blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 4 137 | path stringlengths 2 355 | src_encoding stringclasses 31
values | length_bytes int64 11 3.9M | score float64 2.52 5.47 | int_score int64 3 5 | detected_licenses listlengths 0 49 | license_type stringclasses 2
values | text stringlengths 11 3.93M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
cfc907a3a0660af4351197ee25a26c6753dfd699 | Ruby | fizzik/orion | /app/models/product.rb | UTF-8 | 1,275 | 2.5625 | 3 | [] | no_license | class Product < ActiveRecord::Base
attr_accessible :description, :image_url, :price, :title
validates :title, :description, :image_url, presence: true
validates :title, uniqueness: true
validates :title, length: {maximum: 100}
validates :description, uniqueness: true
validates :image_url, allow_blank: true, format: ... | true |
e0b75393e3d5fe328fdbe05d6f523681370da703 | Ruby | dementova/store | /app/lib/discount_factory/color.rb | UTF-8 | 421 | 2.765625 | 3 | [] | no_license | module DiscountFactory
class Color
attr_reader :discount
def initialize products
@products = products
end
def define
exist? ? Discount::CONFIG['discount_amount']['color'] : 0
end
private
def exist?
amount_products >= Discount::CONFIG['amount_products']['by_color']
end
def amount_produc... | true |
97d9416fc0b3276e38b7a1108e30a216269be3c6 | Ruby | zed-0xff/zpng | /lib/zpng/adam7_decoder.rb | UTF-8 | 2,556 | 3.09375 | 3 | [
"MIT"
] | permissive | module ZPNG
class Adam7Decoder
attr_accessor :bpp
attr_reader :scanlines_count
# http://en.wikipedia.org/wiki/Adam7_algorithm#Passes
def initialize width, height, bpp
@bpp = bpp
raise "Invalid BPP #{@bpp.inspect}" if @bpp.to_i == 0
@widths = [
[(width/8.0).ceil] * (heigh... | true |
d1b9bc3797af581409355636414d980e1bfcd91c | Ruby | steve-hawkins/uplifting_quote | /spec/uplifting_quote_spec.rb | UTF-8 | 1,008 | 2.84375 | 3 | [
"MIT"
] | permissive | require "spec_helper"
RSpec.describe UpliftingQuote do
it "has a version number" do
expect(UpliftingQuote::VERSION).not_to be nil
end
describe ".add" do
it "should add two numbers" do
expect(UpliftingQuote.add(0, 0)).to eq(0)
expect(UpliftingQuote.add(1, 3)).to eq(4)
expect(UpliftingQu... | true |
1b08ce50f0115ad2d51a7fcbd85dbbc69f8f87c6 | Ruby | xWilsonle/RubyCounting | /count.rb | UTF-8 | 958 | 3.96875 | 4 | [] | no_license |
#Gets the name for the user
def getName
puts "What is your name?"
$inputName = gets
end
#Gets the number for the user
def getNumber
puts("What is your number?")
begin
$inputNumber = Integer(gets.chomp)
rescue
puts("Please enter a valid number")
retry
end
end
#gets the increment
def getIncrement
puts("Wh... | true |
9025e1774624782dd4f0773f194fc263d062421f | Ruby | yoricksijsling/voter | /app/models/poll.rb | UTF-8 | 745 | 2.71875 | 3 | [] | no_license | class Poll
include MongoMapper::Document
key :title
key :description
many :options
many :participants
def get_participant(code)
self.participants.select{ |p| p.code == code }.first
end
def options_csv # yeah yeah not really csv i know
self.options.map{|o| o.title }.join ','
end
d... | true |
d21c41fd055d55aa52c61441dc796b5728e4b800 | Ruby | yuemori/active_any | /lib/active_any/relation/order_clause.rb | UTF-8 | 1,175 | 2.875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module ActiveAny
class Relation
class OrderClause
def self.empty
new
end
OrderValue = Struct.new(:key, :sort_type)
attr_reader :order_values
def initialize(values = [], reverse = false)
@reverse = reverse
@order_values = conve... | true |
21465b37f99167e3482fc60ae5f93eab696b4254 | Ruby | jhellerstein/crocus | /test/tc_elements.rb | UTF-8 | 1,533 | 2.71875 | 3 | [] | no_license | require './test_common.rb'
require '../lib/crocus/minibloom'
class TestElements < Test::Unit::TestCase
def test_pull_element
e = Crocus::PullElement.new(:p, 0, (1..1000000000))
i = e.to_enum do |out, inp|
out.yield inp if inp.class <= Numeric and inp%2 == 0
end
assert_equal([2,4,6], i.take(3))
... | true |
664b3568b9bb6fd7e6b7d12f15cc788ee176f8f6 | Ruby | williamtome/ruby-course | /estruturas_de_controle/iteracao/foreach.rb | UTF-8 | 199 | 3.609375 | 4 | [] | no_license | lista = [1,2,3,4,5]
lista.each do |item|
puts "Número: #{item}"
end
palavra = "Onomatopéia"
puts "total de letras: #{palavra.size}"
palavra.each_char do |letra|
puts "Letra: #{letra}"
end | true |
676320d373a0a4874767a26a41ae1eeb2faacdb5 | Ruby | pixapi/headcount | /test/headcount_analyst_test.rb | UTF-8 | 5,119 | 2.609375 | 3 | [] | no_license | require_relative 'test_helper'
require './lib/headcount_analyst'
require './lib/district_repository'
class HeadcountAnalystTest < Minitest::Test
def test_it_has_a_class
dr = DistrictRepository.new
ha = HeadcountAnalyst.new(dr)
assert_instance_of HeadcountAnalyst, ha
end
def test_it_gets_participatio... | true |
c30ddbe7b4fa088f42b51f55904bdb1b61d4a608 | Ruby | mlyubarskyy/leetcode | /206_reverse_linked_list.rb | UTF-8 | 520 | 3.625 | 4 | [] | no_license | # Definition for singly-linked list.
# class ListNode
# attr_accessor :val, :next
# def initialize(val)
# @val = val
# @next = nil
# end
# end
# @param {ListNode} head
# @return {ListNode}
def reverse_list(head)
return head if !head || !head.next
node = reverse_list(head.next)
head.ne... | true |
155034648e2684621e22a77516f4e8af02fddb14 | Ruby | ualbertalib/serials-admin | /data_scripts/spec/bad_issn_spec.rb | UTF-8 | 553 | 2.515625 | 3 | [] | no_license | require_relative("spec_helper")
RSpec.configure do |c|
c.include TestData
end
describe BadIssn do
let(:bad_issn){ BadIssn.new(StringIO.new(bad_issn_data)) }
# BadIssn takes reads the badissn data, takes in a titleID and returns whether the issn is bad or not.
context "when provided with a titleID" do
it ... | true |
e9b3c28af1653c2bb3b517a37010a3882219cffb | Ruby | TertiumQuid/Cthulhu-Quest | /app/models/armament.rb | UTF-8 | 1,084 | 2.5625 | 3 | [] | no_license | class Armament < ActiveRecord::Base
ORIGIN = ['purchase','gift','reward']
belongs_to :weapon
belongs_to :investigator
scope :weapons, includes(:weapon)
before_validation :set_weapon_name, :on => :create
after_create :arm_investigator
attr_accessor :origin
validates :investigator_id, ... | true |
d39ce3aa749afe4bfecc9d22351596e821e6e0fc | Ruby | cthomaspdx/fat-linode | /libraries/linode_api.rb | UTF-8 | 1,722 | 2.84375 | 3 | [] | no_license | module FatLinode
class LinodeApi
attr_accessor :api_key, :node_name, :public_ip
def initialize(args)
@api_key = args[:api_key]
@node_name = args[:node_name]
@public_ip = args[:public_ip]
end
def private_ips
all_ips.collect {|ip| ip.ipaddress if private?(ip)}.compact
end
... | true |
da077dbb4d7bae19eea387d79884bd58f6668ce2 | Ruby | andrewetobin/home-consultant | /app/services/appointment_collector.rb | UTF-8 | 1,559 | 2.671875 | 3 | [] | no_license | class AppointmentCollector
def initialize(appointment_info, auth_token, email)
@appointment_info = appointment_info
@auth_token = auth_token
@email = email
response
end
def build_body
{
HTTP_AUTH_TOKEN: @auth_token,
email: @email,
address: @appointment_info[:consultation][:... | true |
4e1365b9aae51e6d7fe0a0eb764786d82ecc6fc4 | Ruby | bradgreen3/apicurious | /app/models/github_starred_repo.rb | UTF-8 | 519 | 3.015625 | 3 | [] | no_license | class GithubStarredRepo
attr_reader :full_name, :updated_at, :language
def initialize(raw_repo={})
@full_name = raw_repo[:full_name]
@updated_at = clean_date(raw_repo[:updated_at])
@language = raw_repo[:language]
end
def self.for_user(token)
starred_repos = GithubService.new(token).starred_rep... | true |
522daa4689eb1f6deb9aa92074cd295ad98a5af7 | Ruby | bestmike007/log4rails | /lib/log4r/MDC.rb | UTF-8 | 1,462 | 2.515625 | 3 | [
"BSD-2-Clause"
] | permissive | # :include: rdoc/MDC
#
# == Other Info
#
# Version:: $Id$
# Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
require 'monitor'
module Log4r
MDCNAME = "log4rMDC"
MDCNAMEMAXDEPTH = "log4rMDCMAXDEPTH"
$globalMDCLock = Monitor.new
# See log4r/MDC.rb
class MDC < Monitor
private_class_method ... | true |
bd6a0c70cb6f69b566c0866a633f8a8395723e84 | Ruby | cvolpe12/ruby-objects-belong-to-lab-nyc-web-career-010719 | /lib/post.rb | UTF-8 | 152 | 2.765625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Post
attr_accessor :title, :author
@@posts = []
def initialize
@@posts << self
end
def all
@@posts
end
end
| true |
5e710ac33900fc42a32e7cf1e71a66f2a28f7f57 | Ruby | rainforestapp/get_env | /spec/get_env_spec.rb | UTF-8 | 1,601 | 2.640625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
RSpec.describe GetEnv do
before(:all) do
ENV['SOME_STRING'] = 'foo'
ENV['SOME_INT'] = '1'
ENV['SOME_FLOAT'] = '1.23'
ENV['SOME_TRUE'] = 'true'
ENV['SOME_FALSE'] = 'false'
end
it "has a version number" do
expect(GetEnv::VERSION).not_to be nil
end
describ... | true |
f2b0232e522d9f76e5d9ce647847861d94b3e3dd | Ruby | RubyCamp/rc2021sp_g6 | /Generic Mario/scenes/ending/director.rb | UTF-8 | 857 | 2.5625 | 3 | [] | no_license | module Ending
class Director
def initialize
#文字のフォント、サイズ
@font = Font.new(70, "丸 ゴシック")
@font2 = Font.new(40, "MS ゴシック")
@image = Image.load('images/墓.png')
end
def reload
end
def play
#画像の描画
... | true |
0e790dfb83b25dc31a7a8b9b7e6e5cb4c6fb9df3 | Ruby | markpackham/codeclan_week04_big_project | /models/customer_lesson.rb | UTF-8 | 2,686 | 2.90625 | 3 | [] | no_license | require_relative("../db/sql_runner")
class Customer_Lesson
attr_accessor(:customer_id, :lesson_id)
attr_reader(:id)
def initialize(options)
@id = options["id"].to_i if options["id"]
@customer_id = options["customer_id"].to_i
@lesson_id = options["lesson_id"].to_i
end
def save()
sql = "INSER... | true |
57747aa4a3e6dd038da183d2e3e4d9dd35e9fbc3 | Ruby | gonyolac/ls_ruby_course | /ruby_more_topics/weekly_challenges/protein_translation.rb | UTF-8 | 1,791 | 3.71875 | 4 | [] | no_license | class Translation
# no need for initialize?; no indication of instance object; class method
#track states of a Translation? (no need!)
@codon_codes = {
"Methionine": ['AUG'],
"Phenylalanine": ['UUU', 'UUC'],
"Leucine": ['UUA', 'UUG'],
"Serine": ['UCU', 'UCC', 'UCA', 'UCG'],
"Tyrosine": ['UAU',... | true |
6c9c0a42ec121a9d3485821563741ef3ec047b49 | Ruby | amenning/Design_Patterns_GOF_In_Ruby | /Structural_Patterns/class_structural/proxy/example.rb | UTF-8 | 377 | 2.5625 | 3 | [] | no_license | require_relative 'real_image.rb'
require_relative 'proxy_image.rb'
puts 'Open pretend document with real image'
immediate_image = RealImage.new('Real')
puts 'Scroll down page so image is on page'
immediate_image.display
puts "\n" + 'Open pretend document with proxy image'
proxy_image = ProxyImage.new('Proxy')
puts 'S... | true |
34a7027ef37086fcc91809b56b1de73ab64058a1 | Ruby | snreid/uc-tracker | /app/models/usda/api.rb | UTF-8 | 827 | 2.53125 | 3 | [] | no_license | module USDA
require 'uri'
require 'net/http'
require 'json'
class API
attr_accessor :base_uri
API_KEY = { api_key: Rails.application.secrets.usda_api_key }
def initialize(base_uri = "http://api.nal.usda.gov/ndb/")
@base_uri = base_uri
end
def response(endpoint, params = {})
u... | true |
6e1202486c3f61b2eaca7998688659d7c4b3415a | Ruby | peterylai/project_euler | /p026.rb | UTF-8 | 357 | 3.734375 | 4 | [] | no_license | require 'prime'
def recurring_cycle_length(num)
return 0 if num % 2 == 0 || num % 5 == 0
repetend_length = 1
while (((10**repetend_length) - 1) % num) != 0
repetend_length += 1
end
repetend_length
end
max = 0
Prime.each(1000) do |prime|
max = recurring_cycle_length(max) > recurring_cycle_leng... | true |
eeab91ccfc6e0b5c866e4a811f26938a0429dd57 | Ruby | omustafa1994/starwars-api | /spec/fixerio_spec.rb | UTF-8 | 984 | 2.640625 | 3 | [] | no_license | require 'spec_helper'
describe 'starwars api' do
before(:all) do
@starwars_people = ParseJson.new(HTTParty::get("https://swapi.co/api/people/1").body).json_data
@starwars_planet = ParseJson.new(HTTParty::get("https://swapi.co/api/planets/1").body).json_data
end
it 'should be a hash' do
expect(@s... | true |
00613edf6e5a1890ed5e1debf22dcbdecfb6d525 | Ruby | binzume/ruby-irc-bot | /irc.rb | UTF-8 | 4,134 | 2.703125 | 3 | [] | no_license | require 'time'
require 'net/irc'
require 'kconv'
require 'digest/md5'
def irc_connect servers, bot
servers.map{|server|
s = IrcServer.new(server)
client = s.connect
client.add_bot(bot) if bot
t = Thread.new do
client.start
puts "IRC client finished."
end
s
}
end
class IrcServ... | true |
d3f0b8cbe7cc1565bf51f6a51c644831ffffae9c | Ruby | jk1dd/homework | /pseudocode_extended.rb | UTF-8 | 1,947 | 3.8125 | 4 | [] | no_license | =begin
I have a text document and want to know
“What are the three most common words in the text?”
1. You know the problem is solved when you are able to inspect the list
of the 3 most frequent workds
2. To interface, you want to input the text document, and have those three
words (at least) spit out
3. The first triv... | true |
9e16ec24c65aaad9693d74600a4d502c5f8897c6 | Ruby | AlisonZXQ/leetcode | /Algorithms/001. Two Sum/Solution.rb | UTF-8 | 369 | 3.25 | 3 | [] | no_license | # @param {Integer[]} nums
# @param {Integer} target
# @return {Integer[]}
def two_sum(nums, target)
map={}
index=0
nums.each{|num| map[(target-num)]=index;index+=1}
puts map
for i in 0..nums.size
print i,nums[i],map[nums[i]]
if map[nums[i]] && i!=map[nums[i]]
return [i,ma... | true |
d979d2bc6697887eff6562a5ae74328773877250 | Ruby | dmyers3/launch_school_101 | /lesson_3/easy1.rb | UTF-8 | 1,079 | 3.875 | 4 | [] | no_license | # Question 3
advice = "Few things in life are as important as house training your pet dinosaur"
advice.gsub!('important', 'urgent')
puts advice
# Question 5
puts (10..100).include?(42)
# Question 6
famous_words = "seven years ago..."
famous_words.insert(0, 'Four score and ')
puts famous_words
famous_words = "seven y... | true |
b30bf9727b2a56edb73bb37c0f97db9fdf48b45e | Ruby | mithunder916/hartl_sample_app | /ruby/string_shuffle.rb | UTF-8 | 203 | 3.21875 | 3 | [] | no_license | def string_shuffle(s)
s.split('').shuffle.join
end
p string_shuffle('foobar')
p string_shuffle('myxomatosis')
class String
def shuffle
self.split('').shuffle.join
end
end
p "goobar".shuffle
| true |
68a2fe9895ee02cd20dc2b3b88612a5c2a99b6c2 | Ruby | mxhold/vimperor | /spec/lib/type_coersion_spec.rb | UTF-8 | 3,813 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require_relative '../../lib/type_coersion'
describe ArrayExtensions::DeepToH do
describe '#deep_to_h' do
it 'converts deeply nested array into hash' do
module TestModule
using ArrayExtensions::DeepToH
def self.actual_hash
[[:a, [[:b, [[:c, :d]]]]]].deep_to_h
... | true |
f972f88dc2bf00080969135f1d2554f5f1efb1ae | Ruby | ChienliMa/schools | /lib/schools/schools.rb | UTF-8 | 2,442 | 2.921875 | 3 | [] | no_license | require "nokogiri"
require 'open-uri'
require "socket"
class Schools
attr_accessor :type
attr_accessor :max_page_num
Type = { elementary:"mainxx", middle:"maincz", high:"main" }
def initialize( school_type )
@type = school_type
# get max page num
url ="http://xuexiao.eol.cn/iframe/#{Type[scho... | true |
a8684f7219199b4618e40625436fb140ee8344e4 | Ruby | HyeokJungKim/OO-mini-project-nyc-web-031218 | /app/models/Recipe.rb | UTF-8 | 752 | 3.171875 | 3 | [] | no_license | class Recipe
@@all = []
attr_accessor :users, :ingredients, :name
def initialize(name)
@name = name
@@all << self
@ingredients = []
end
def self.most_popular
arr = RecipeCard.all.map do |rc|
rc.recipe
end
hash = Hash.new(0)
arr.each do |recipe|
hash[recipe] +=1
en... | true |
5018cfd890d3b484de9032b3f7744a7449fcd9a0 | Ruby | danjglick/launch-academy-challenges | /perimeter-method/code.rb | UTF-8 | 70 | 2.59375 | 3 | [] | no_license | def perimeter(width, height = width)
(width * 2) + (height * 2)
end
| true |
e5a608d039fcbd1f905d845995299cd7b30caf34 | Ruby | bbchui/practice_problems | /ruby_problems/tech_coding2.rb | UTF-8 | 1,155 | 4.28125 | 4 | [] | no_license | # We also want to allow parentheses in our input. Given an expression string using the "+", "-", "(", and ")" operators like "5+(16-2)", write a function to parse the string and evaluate the result.
# Sample input:
# expression1 = "5+16-((9-6)-(4-2))"
# expression2 = "22+(2-4)"
# Sample output:
# evaluate... | true |
bf78f7870007494f5d9bae1f6079ee32ffc2e365 | Ruby | sirscriptalot/mugatu | /lib/mugatu/attribute_type.rb | UTF-8 | 499 | 2.609375 | 3 | [
"MIT"
] | permissive | module Mugatu
module AttributeType
def set_cast_with(sym)
@cast_with = sym
end
def get_cast_with
@cast_with
end
def cast(value)
if value.respond_to?(get_cast_with)
value.send(get_cast_with)
else
raise_cast_error(value)
end
end
def raise_cast... | true |
45a3e18d9a911fafc412a533a5a5c731a22cc381 | Ruby | Karis-T/RB139 | /exercises_more_topics/medium_1.rb | UTF-8 | 2,579 | 3.90625 | 4 | [] | no_license | #1
class Device
def initialize
@recordings = []
end
def listen
record(yield) if block_given?
end
def record(recording)
@recordings << recording
end
def play
puts @recordings.last
end
end
listener = Device.new
listener.listen { "Hello World!" }
listener.listen
listener.play # Outputs ... | true |
2496aebf1f016cd7426e2ef5174173d2482da88b | Ruby | rien/minitest-utils | /test/minitest/utils/let_test.rb | UTF-8 | 883 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class LetTest < Minitest::Test
i_suck_and_my_tests_are_order_dependent!
$count = 0
let(:count) { $count += 1 }
test 'defines memoized reader (first test)' do
assert_equal 0, $count
5.times { assert_equal 1, count }
end
test 'defines memoized reader (second test)' do
ass... | true |
00c80251bad6aaa72cd1cd903435eb121d173e0b | Ruby | hnmn/termux-rootfs | /termux-rootfs/data/data/com.termux/files/usr/lib/ruby/gems/2.4.0/gems/celluloid-io-0.16.2/lib/celluloid/io/stream.rb | UTF-8 | 9,715 | 2.953125 | 3 | [
"MIT",
"Ruby"
] | permissive | # Partially adapted from Ruby's OpenSSL::Buffering
# Originally from the 'OpenSSL for Ruby 2' project
# Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
# All rights reserved.
#
# This program is licenced under the same licence as Ruby.
module Celluloid
module IO
# Base class of all streams in Celluloid::I... | true |
d58313d185774aebaf27d386460523f87f0a6b41 | Ruby | e-barr/notBuggySkipe_back-end | /app/models/contact.rb | UTF-8 | 929 | 2.578125 | 3 | [] | no_license | class Contact < ApplicationRecord
belongs_to :user_1, class_name: :User, foreign_key: :user_1_id
belongs_to :user_2, class_name: :User, foreign_key: :user_2_id
validates :user_1_id, presence: true
validates :user_2_id, presence: true
def self.make_new_contact(user_1_id, user_2_id)
if user_1_id == user_2_... | true |
4ad21d016aea18e0f722c9c7f33f06f2dab7220a | Ruby | travis4all/node-backplane | /features/support/defaults.rb | UTF-8 | 702 | 2.65625 | 3 | [
"MIT"
] | permissive | class Defaults
def initialize(config)
@config = config
@valid_info = @config['valid_info']
@count = 1
end
def get_count()
return @count
end
def inc_count()
@count += 1
end
def get_valid_bus()
@config['base_url'] + '/' + @config['backplane']['version'] + '/bus/' + @valid_info['b... | true |
6695ae8e208b278f99dcde8c886c0a4fd9bb4a26 | Ruby | ClearFit/marketo-api-ruby | /lib/marketo_api/lead.rb | UTF-8 | 6,691 | 2.75 | 3 | [
"MIT"
] | permissive | require 'forwardable'
# An object representing a Marketo Lead record.
class MarketoAPI::Lead
extend Forwardable
include Enumerable
NAMED_KEYS = { #:nodoc:
id: :IDNUM,
cookie: :COOKIE,
email: :EMAIL,
lead_owner_email: :LEA... | true |
508921af042a0222319fa2a86295881f2ff46146 | Ruby | wgltony/ReactRealTimeNewsScrapingandRecommendationSystem-GraphiteSystemMonitor | /tap-news/elasticsearch_server/logstash-5.4.0/logstash-core/lib/logstash/timestamp.rb | UTF-8 | 478 | 2.546875 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | # encoding: utf-8
require "logstash/namespace"
module LogStash
class TimestampParserError < StandardError; end
class Timestamp
include Comparable
# TODO (colin) implement in Java
def <=>(other)
self.time <=> other.time
end
# TODO (colin) implement in Java
def +(other)
self.t... | true |
ddfc91760bdb022e2bdcf3bd20561863e20137ea | Ruby | marcelgalang/my-select-001-prework-web | /lib/my_select.rb | UTF-8 | 174 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def my_select(collection)
i = 0
result = []
while i < collection.length
if (yield(collection[i]))
result << collection[i]
end
i+=1
end
result
end | true |
c15fc898db44fef608c6a9ad9dc4bdfe076d8981 | Ruby | arnewauters/RubyRabbits | /rabbit.rb | UTF-8 | 682 | 3.4375 | 3 | [] | no_license | require_relative 'animal'
require 'win32console'
require 'colored'
class Rabbit < Animal
def initialize()
@breedingAge = 1 + rand(1)
@maximumAge = 8 + rand(4)
@breedingProbability = 0.7
@maxLitterSize = 6
super
end
def checkFood
end
def breed(maximum)
if (maximum == 0 || @age < @breedingAge)... | true |
0d3f188b76eee88d0c1892bcce0d51127d4fba7b | Ruby | cgservices/officer | /lib/officer/lock_store.rb | UTF-8 | 5,674 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Officer
class LockQueue < Array
def to_host_a
map {|conn| conn.to_host_s}
end
end
class Lock
attr_reader :name
attr_reader :size
attr_reader :queue
attr_reader :lock_ids
def initialize name, size = 1
@name = name
@size = size.to_i
@lock_ids = (0..@size... | true |
d7636f51dcdbf83014d8ab016b8a59f6c61230a4 | Ruby | Hiten-waroo/LS_CORE | /R101_lesson_3/practice_problems_medium_2_q3.rb | UTF-8 | 1,626 | 4.09375 | 4 | [] | no_license | def tricky_method(a_string_param, an_array_param)
a_string_param += "rutabaga" #this is not mutable
an_array_param << "rutabaga" #this is mutable
end
my_string = "pumpkins"
my_array = ["pumpkins"]
tricky_method(my_string, my_array)
puts "My string looks like this now: #{my_string}" #this remains "pumpkins" as m... | true |
1f15e6375d351e09f8c2d44998a5fdf9b166effa | Ruby | axiomiety/exercism-io | /ruby/robot_name.rb | UTF-8 | 540 | 3.3125 | 3 | [] | no_license | require 'set'
class Robot
attr_reader :name
@@names = Set.new
@@alpha_uppercase = ('A'..'Z').to_a
@@digits = (0..9).map{|i| i.to_s}
def self.generate_unique_name
# [A-Z]*2 + [0-9]*3
uid = ''
loop do
2.times { uid << @@alpha_uppercase.sample }
3.times { uid << @@digits.sample }
... | true |
4f4e90a4ea336aca7a1a38477db8a34d40218535 | Ruby | lhoff0/public_library | /pblibrary.rb | UTF-8 | 1,962 | 4.15625 | 4 | [] | no_license | # pblibrary.rb
# define class Library
# Report all books it contains
class Library
def initialize (library_title)
@library_title = library_title
@shelves=[]
end
def add_shelf(shelf)
@shelves << shelf
end
def delete_shelf(shelf)
@shelves.delete(shelf)
end
def books
puts @library_title + ' librar... | true |
cbd5a32f60eafa323d44c08af54b4820097e34db | Ruby | macjapm/projecteuler | /p11.rb | UTF-8 | 1,070 | 3.28125 | 3 | [] | no_license | #Author : Mackenzie Park-McInnes
#Title : P11
#Purpose : Solve 'projecteuler.net' archived problem 11
def v(x, y, arr)
prd = 1
if y > 16 == false
for rep in 1..4
prd *= (arr[x + (y*19)]).to_i
y += 1
end
end
return prd
end
def h(x, y, arr)
prd = 1
if x > 16 == false
for rep in 1..4
prd *= (arr[x +... | true |
1b4800d9f4cdb12f039fe64413dc94121705c9bc | Ruby | stok0102/word_count | /lib/word_count.rb | UTF-8 | 228 | 3.421875 | 3 | [
"MIT"
] | permissive | require('pry')
class String
def word_count (user_input)
result = 0
input_array = user_input.split(" ")
input_array.each do |match|
if self == match
result += 1
end
end
result
end
end
| true |
4dbaf27d8e5afaae53b40ec97c081e7c38c201ca | Ruby | katharinap/my_recipes | /test/models/recipe_test.rb | UTF-8 | 3,137 | 2.53125 | 3 | [] | no_license | # == Schema Information
#
# Table name: recipes
#
# id :integer not null, primary key
# name :string
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# picture :string
# active_time :integer
# total_time :integer
# prep_time ... | true |
5765648b2d2d2fae9cea5832e5895de462dfc28d | Ruby | jungchae/ruby-pwa | /bin/weights.rb | UTF-8 | 1,983 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
# Author:: Mike Williams
#
# Dumps event weights to screen
#
require 'optparse'
require 'pwa/dataset'
require 'utils'
require 'plot/utils'
require 'plot/iteration'
#
# parse command line
#
#options = {:type => :acc}
options = {}
cmdline = OptionParser.new
cmdline.banner = 'Usage: plot.rb [...option... | true |
4ccdcb39fd99eafe08520fe3e43c486eefa9a510 | Ruby | tapfit/tapfit | /lib/crawler_validation/process_class.rb | UTF-8 | 5,643 | 2.515625 | 3 | [] | no_license | require_relative 'process_base'
require './lib/workout_key'
class ProcessClass < ProcessBase
def initialize(opts={})
if !opts.nil?
@valid_keys = opts.keys
@valid_keys = @valid_keys.collect{|i| i.to_s}
@place_id = opts[:place_id]
@name = opts[:name]
@tags = opts[:tags]
@sour... | true |
772a7739f3f10400fe69acfeba317dc320dab3c3 | Ruby | AlexBaranosky/GongOMatic | /src/audio_player.rb | UTF-8 | 434 | 2.984375 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../src/speaker'
require 'win32/sound'
include Win32
class AudioPlayer
GONG_WAV = File.dirname(__FILE__) + '/../resources/blong2.wav'
def play(routine_parts)
routine_parts.each do |p|
Speaker.new.speak(p.message) if p.has_message?
wait_then_ring_gong(p.duration)
... | true |
f8c80f4488a543841867e15f8bf5890893adf118 | Ruby | Claiborne/media-qa | /codefoo_2013/if_statement.rb | UTF-8 | 465 | 4.21875 | 4 | [] | no_license | number = 1
# contrived example
if number == 1
puts 'number is 1'
elsif number == 2
puts 'number is 2'
else
puts 'number is nethier 1 nor 2'
end
# this does the same thing as above
puts 'number is 1' if number == 1
puts 'number is 2' if number == 2
puts 'number is nethier 1 nor 2' if number != 1 && number != 2
... | true |
30fd41722eb734a064659ec2a1380c4adc34917e | Ruby | kepishelf/ruby | /coursera_test.rb | UTF-8 | 18,223 | 3.40625 | 3 | [] | no_license | # ruby playground / sandbox = d:\sandbox\ruby\coursera_test.rb
# see notes from coursera : d:\sandbox\ruby\ruby-reference.txt
a = 6
# ----------------------------------------------------------
# IF ELSE, CASE, UNTIL
# ----------------------------------------------------------
puts 'more stuff after this'
if a==3
p... | true |
7c3660f38389a83156f6c3755e8b3c1ce48e2286 | Ruby | Sayanc93/HashtagBattle | /app/services/twitter_streaming_service.rb | UTF-8 | 912 | 2.625 | 3 | [] | no_license | class TwitterStreamingService
attr_reader :client, :user
def initialize user = nil
@user = user
@client = TweetStream::Client.new(oauth_token_secret: user.secret,
oauth_token: user.token)
end
# Tracks tweets in a stream, stream exits when user's connected attribu... | true |
a458a7d95b90625c9651ce6b0d926a385dbabf7e | Ruby | Kacper3331/fight_club | /app/models/result.rb | UTF-8 | 1,813 | 2.90625 | 3 | [] | no_license | class Result < ActiveRecord::Base
def self.create_result(first_fighter_id, second_fighter_id)
first_fighter_skill = select_skill(first_fighter_id)
second_fighter_skill = select_skill(second_fighter_id)
first_fighter_exp_points = fighter_info(first_fighter_id).exp_points.to_i
second_fighter_exp_points ... | true |
3263723ae224100964b6cdf833b07ec46174d754 | Ruby | Lecogoni/THP-W2-D2 | /exo_03.rb | UTF-8 | 125 | 3.59375 | 4 | [] | no_license | # 2.3. Un programme qui calcule des âges
puts "Ton âge ?"
input = gets.chomp.to_i
puts "Tu avais #{input - 4} ans en 2017" | true |
508d2d4f50044dd989c525ff69a5f54bb1782d05 | Ruby | mercedesb/fun_friendly_cs_ruby | /app/models/inheritance/geranium.rb | UTF-8 | 402 | 2.625 | 3 | [] | no_license | # frozen_string_literal: true
class Inheritance::Geranium < Inheritance::Plant
def initialize
@name = 'Geranium'
@sun = true
@wet = false
@light_needs = '4 - 6 hours of direct sunlight per day.'
@soil_needs = 'Plant in a pot with soil-less potting mixture and good drainage.'
@water_needs = 'W... | true |
a2911ef2516111c3b10d77745f0028643390feb3 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/21283d4391e3498f86c6749baba92311.rb | UTF-8 | 298 | 3.046875 | 3 | [] | no_license | class Raindrops
def self.convert(number)
return_string = String.new
return_string += "Pling" if number % 3 == 0
return_string += "Plang" if number % 5 == 0
return_string += "Plong" if number % 7 == 0
return_string = number.to_s if return_string.empty?
return_string
end
end
| true |
5b12e6005d8490f11fafd07717e64cbe8894ba4f | Ruby | vconcepcion/level_up_exercises | /supportive/supportive.rb | UTF-8 | 3,889 | 2.921875 | 3 | [
"MIT"
] | permissive | # In case you missed them, here are the extensions: http://guides.rubyonrails.org/active_support_core_extensions.html
require 'active_support/all'
class BlagPost
attr_accessor :author, :comments, :categories, :body, :publish_date
Author = Struct.new(:name, :url)
DISALLOWED_CATEGORIES = [:selfposts, :gossip, :b... | true |
e54893b5b2c786a289df92e92d303610bdf3393b | Ruby | eabrash/Scrabble | /lib/Scrabble_scoring.rb | UTF-8 | 1,952 | 3.609375 | 4 | [] | no_license | require_relative "../Scrabble_module"
class Scrabble::Scoring
LETTER_VALUES = {"A"=> 1, "E"=> 1, "I"=> 1, "O"=> 1, "U"=> 1, "L"=> 1, "N"=> 1, "R"=> 1, "S"=> 1, "T"=> 1,
"D"=> 2, "G"=> 2,
"B"=> 3, "C"=> 3, "M"=> 3, "P"=> 3,
"F"=> 4, "H"=> 4, "V"=> 4, "W"=> 4, "Y"=> 4,
"K"=> 5,
"J"=> 8, "X"=> 8,
"Q"=> 10,... | true |
4f137fb43a36401b23e4adc79d52ed90fff06cea | Ruby | um-eng-web/grupo3 | /bookie.rb | UTF-8 | 119 | 2.796875 | 3 | [] | no_license | require_relative 'person.rb'
class Bookie < Person
def initialize(nome,pass, mail)
super(nome,pass,mail)
end
end | true |
58e5ed2032d250881e622a151280dcb800ee318c | Ruby | andrechalom/outarms | /outarms-core.rb | UTF-8 | 4,930 | 3.1875 | 3 | [] | no_license | # Class inspired by Chingu::BasicGameObject https://github.com/ippa/chingu/blob/master/lib/chingu/basic_game_object.rb
# These classes however don't require a graphic interface
class GameObject
# Para entender essa linha: http://openmymind.net/2010/6/25/Learning-Ruby-class-self/
class << self; attr_accessor :instance... | true |
a32d3b79e0bae01ec130de2e581d2eff72eb83bf | Ruby | horangijk/dumbo-web-100818 | /10-intro-testing/app/animal.rb | UTF-8 | 182 | 2.609375 | 3 | [] | no_license | class Animal
def zoos_escaped_from
escapes = Escape.all.select do |escape|
escape.animal == self
end
escapes.map do |escape|
escape.zoo
end
end
end | true |
7a44067a3306968337f569ca4355d024f2afadb8 | Ruby | rymanalo/convert_to_phone_number | /convert_to_phone_number.rb | UTF-8 | 393 | 3.578125 | 4 | [] | no_license | def convert_to_phone_number(num)
str = ""
num2 = num.to_s.reverse.split("")
str << num2.shift
str << num2.shift
str << num2.shift
str << num2.shift
str << "-" + num2.shift
str << num2.shift
str << num2.shift + " "
str << ")" + num2.shift
str << num2.shift
str << num2.shift + "( "
str << num2.... | true |
f6bf7d96922cfb31a7e2619b0f8929158dd9033e | Ruby | oseivale/roll-of-the-die | /roll_die_ten_times.rb | UTF-8 | 198 | 2.71875 | 3 | [] | no_license | # PRINTING THE RESULTS OF RANDOMLY ROLLED DIE
counter = 0
until counter == 10
puts "The result of your roll is #{Random.rand(1..7)}" # --> This generates a number between 0 and 6
counter += 1
end
| true |
6b858568e45c49d836042e8bc864ab157913481c | Ruby | rofreg/reservations | /app/models/cart_item.rb | UTF-8 | 623 | 3.109375 | 3 | [] | no_license | class CartItem
attr_reader :equipment_model, :quantity
def initialize(equipment_model)
@equipment_model = equipment_model
@quantity = 1
end
def increment_quantity
@quantity += 1
end
def decrement_quantity
if @quantity > 0
@quantity -= 1
end
end
def details
detai... | true |
59309e48a0abdf9ada7514b09186d1dd988efea5 | Ruby | hussainpithawala/parking-lot-problem-ruby | /lib/command/create.rb | UTF-8 | 483 | 2.75 | 3 | [] | no_license | require_relative 'base_command'
module Command
class Create < BaseCommand
attr_reader :capacity, :msg
def initialize(context)
super(context)
context_is_not_nil?
if context.capacity < 1
raise "capacity cannot be less than 1"
end
super(context)
@capacity = context... | true |
f259d7b45f74ed39b946639450d408ebbfab05d9 | Ruby | chses9440611/Ruby_the_hard_way_ex | /ex2.rb | UTF-8 | 97 | 2.71875 | 3 | [] | no_license | #The comment character in Ruby is '#''
puts "I could have code like this."
puts "This will run."
| true |
82da31f1d6c6065db818aa0fac44682cbcf4fdde | Ruby | awanderson8/Poco-A-Poco | /Alphabetize-Words.rb | UTF-8 | 241 | 3.734375 | 4 | [] | no_license | puts "Type out 1 word per line. When you are finished, press \'enter\'."
words = []
input = gets.chomp
while input != ""
input = gets.chomp
words.push input
end
puts "Here are your words in alphabetical order."
puts words.sort
| true |
4e056609e664f730699adc541c763adb9cf8ead5 | Ruby | get4137/ruby_ruby | /while.rb | UTF-8 | 1,022 | 3.5625 | 4 | [] | no_license | # frozen_string_literal: true
# answer = 'Y'
# while answer == 'Y'
# puts 'Хотите продолжить? (Y/N) '
# answer = gets.strip.capitalize
# end
# hh = {}
# while true
# print 'enter name (Enter to stop): '
# name = gets.strip.capitalize
# if name == ''
# break
# end
# print 'enter phone number: '
# n... | true |
1709f972f4eb1513d6240de32387cae1baac69b9 | Ruby | roniRamon/aA-homeworks | /W2D5/lru_cache.rb | UTF-8 | 503 | 3.5 | 4 | [] | no_license | class LRUCache
attr_reader :arr, :size
def initialize(size)
@arr = Array.new()
@size = size
end
def add(element)
#befor add element see if exist
#if yes delete it an move to end
if @arr.include?(element)
@arr.delete_at(@arr.index(element))
end
#check if arr size == 4
ke... | true |
c0a2d9d85053bc0c896f6cea0197d1aa5a81a4f6 | Ruby | garuma/sorbetor | /test/sorbetor/string_container_test.rb | UTF-8 | 2,099 | 3.109375 | 3 | [
"Apache-2.0"
] | permissive | # typed: true
require "test_helper"
class Sorbetor::StringContainerTest < Minitest::Test
def test_string_comes_back_the_same
text = "Hello World!"
assert_equal Sorbetor::Text::StringContainer.from_s(text).to_s, text
end
def test_can_concat_two_strings
text1 = "Hello "
text2 = "World!"
contai... | true |
a7d9d020857b2b2910c0e8b4ed0a0e56f5be36e4 | Ruby | timreganporter/JMS-302 | /exercises/quiz-midterm-prep/grade_calculator.rb | UTF-8 | 1,110 | 4.4375 | 4 | [] | no_license | # This could have even more comments. However, this code is quite readable without
# even the existing comments. It's overcommented for my tasts, but
# you should get in the habit of commenting your code. It'll help you and your reader.
# Prompt the user for a grade, get the grade and return it
def get_grade
puts "E... | true |
417608a1f557938d7c58fbb843486dc1e626afbb | Ruby | madnificent/has_barcode | /lib/has_barcode.rb | UTF-8 | 680 | 2.796875 | 3 | [
"MIT"
] | permissive | module HasBarcode
def self.included(mod)
mod.extend(ClassMethods)
end
module ClassMethods
def has_barcode
require 'barby'
require 'barby/outputter/rmagick_outputter'
extend HasBarcode::SingletonMethods
include HasBarcode::InstanceMethods
end
end
module SingletonMet... | true |
43dd5db4e06c07ea7603a54ecfe85f7d58c69649 | Ruby | nttl22/ruby | /app/controllers/user_controller.rb | UTF-8 | 927 | 2.5625 | 3 | [] | no_license | class UserController < ApplicationController
def new
end
def login
end
def login_handle
user = User.find_by email: params[:user][:email].downcase
if user && user.authenticate(params[:user][:password])
session[:email] = user.email
flash[:success] = "Đăng nhập t... | true |
8baf771c7faf3b765be4cfaa15204b89c2da68a6 | Ruby | RianaFerreira/routeplanner | /main.rb | UTF-8 | 3,109 | 3.34375 | 3 | [] | no_license | require 'sinatra'
# require 'pry'
# require 'sinatra/reloader'
# stations per line
subway = {
"N Line" => ["Times Square","34th","28th on the N","Union Square","8th on the N"],
"L Line" => ["8th","6th","Union Square","3rd","1st"],
"6 Line" => ["Grand Central","33rd","28th","23rd","Union Square","Astor Plac... | true |
e7d8e2aef32819cfc37e09d1136b4d844929d22f | Ruby | krasho/blog | /app/services/post_service.rb | UTF-8 | 219 | 2.5625 | 3 | [] | no_license | class PostService
attr_reader :service
def new
@service = Post.new
end
def all
@service = Post.order("publish_date DESC").all
end
def find (id)
@service = Post.find id
end
end
| true |
9166b31cc8e70b400145180a8555f10201eba2af | Ruby | camcarter131/aA-Homeworks | /W2D4/octopus.rb | UTF-8 | 1,590 | 4 | 4 | [] | no_license |
fishes = ['fish', 'fiiish', 'fiiiiish', 'fiiiish', 'fffish', 'ffiiiiisshh', 'fsh', 'fiiiissshhhhhh']
def sluggish(arr)
sorted = false
while !sorted
sorted = true
(0...arr.length-1).each do |i|
if arr[i].length > arr[i+1].length
arr[i], arr[i+1] = arr[i+1], arr[i]
... | true |
b3b0b7f6b840d13fe2cd9b7ebb5d0c3101e82e17 | Ruby | darkmyst/project-euler | /002/project-002.rb | UTF-8 | 153 | 3.171875 | 3 | [] | no_license | total = 0
last = 1
current = 1
while current <= 4000000
total += current if current % 2 == 0
last, current = current, current + last
end
puts total
| true |
414b9d07871a395e52b2d4664c44290c1fcaebc7 | Ruby | rahmaniansyah/elxgo-ruby-intermediet | /week-4/homework/models/order.rb | UTF-8 | 279 | 2.765625 | 3 | [] | no_license | require '../db/mysql_connector.rb'
class Order
attr_accessor :reference_no , :customer_name , :date, :items
def initialize(param)
@reference_no = param[:reference_no ]
@customer_name = param[:customer_name ]
@date = param[:date]
end
end | true |
5d561d82c4fed6e02c6bc544416c1dbc2421221e | Ruby | brantwellman/Turing-task-manager | /test/models/task_manager_test.rb | UTF-8 | 3,019 | 2.875 | 3 | [] | no_license | require_relative '../test_helper'
class TaskManagerTest < Minitest::Test
# def create_tasks(num)
# num.times do |n|
# TaskManager.create({:title => "a title#{n+1}", :description => "a description#{n+1}"})
# end
# end
def test_task_can_be_created
TaskManager.create({ title: "Do it!",
... | true |
a480cc175e6805ad530e61c694b4b80cb17bf105 | Ruby | AndreaGarofoli/CosmicParser | /cosmp.rb | UTF-8 | 838 | 2.75 | 3 | [] | no_license | # Parsa un file .vcf e genera un file di testo con: cromosoma, posizione e
# il rapporto del n° di riscontri di mutazioni di questo tipo su tutte
# le mutazioni studiate
class VCFp
attr_reader :m
attr_writer :m
def rimc(i)
c=0
m=open(i).readlines.map{ |i| i.chomp.to_s}
m.size.time... | true |
55695a8095ddc1ddb111ffa617ec16e2a64c0984 | Ruby | sqwiggle/switchboard | /lib/switchboard/router.rb | UTF-8 | 774 | 2.78125 | 3 | [
"MIT"
] | permissive | module Switchboard
class Router
include Singleton
attr_accessor :default_adapter
def self.default_adapter=(val)
self.instance.default_adapter = val
end
def self.routes
self.instance.routes
end
def self.route(key, &block)
routes << Route.new(key, block)
end
def... | true |
94acc8ee8dd5cc874b34948881f5762ba4440768 | Ruby | azarei/ruby_training | /pantry.rb | UTF-8 | 405 | 3.34375 | 3 | [] | no_license | class Ingredient
#Sets up my ingredients
attr_reader :name, :type
def initialize(name, type)
@name = name
@type = type
end
end
class IngredientList < Array
def ingredients
self
end
def add(ingredient)
self << ingredient
end
end
class Pantry < Ingredient... | true |
d3382f5de928166c4861d9fdbed68c4482f1aa3d | Ruby | jakewendt/my | /scripts/archive/rubyprograms/bird.rb | UTF-8 | 233 | 3.578125 | 4 | [] | no_license | class Bird
def preen
puts "I am cleaning my feathers."
end
def fly
puts "I am flying."
end
end
class Penguin<Bird
def fly
puts "Sorry. I'd rather swim."
end
end
p = Penguin.new
p.preen
p.fly | true |
e39963988587bbca62de6137286a936aa979069a | Ruby | mble/parker | /spec/unit/parker/issue_spec.rb | UTF-8 | 1,049 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Parker::Issue do
subject { described_class.new }
let(:issue) { double(html_url: 'http://www.example.com', number: '3124', title: 'It broke', created_at: Time.now - 432_000) }
describe '#open_for_days' do
it 'returns the number of days the issue is open for' do
expect(subje... | true |
074ca2a7d315a739dadd863bfec1aa24a937d06f | Ruby | biscar/patterns | /lib/expressions/and_exp.rb | UTF-8 | 694 | 2.953125 | 3 | [
"MIT"
] | permissive | module Expressions
class AndExp < Expressions::BooleanExp
def post_initialize(args = {})
@boolean_exp1 = args[:boolean_exp1]
@boolean_exp2 = args[:boolean_exp2]
end
def evaluate(context)
boolean_exp1.evaluate(context) && boolean_exp2.evaluate(context)
end
def replace(name, bool... | true |
fb4d5e52941868b4017422fb9273a48bf10b5a84 | Ruby | jw20191n/ruby-objects-has-many-through-readme-nyc-clarke-web-082619 | /lib/waiter.rb | UTF-8 | 688 | 3.09375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Waiter
attr_accessor :name, :yrs_exp
@@all = []
def initialize(name, yrs_exp)
@name = name
@yrs_exp = yrs_exp
@@all << self
end
def new_meal(customer, total, tip)
Meal.new(self, customer, total, tip)
end
def meals
Meal.all.select {|meal| meal... | true |
b3a927da814bc71e92e67f34a92e8732412808f7 | Ruby | aibek1392/dumbo-web-051319 | /06-inheritance/lib/mammal.rb | UTF-8 | 233 | 3.171875 | 3 | [] | no_license | class Mammal < Animal
def initialize(name)
super(name)
@warm_blooded = true
end
def sleep
"I'm not an emoji..."
end
def give_live_birth(baby_name)
"I have given birth to a beautiful #{baby_name}"
end
end
| true |
240b7001319205b9c5ab2ed77b3ca3377c8ac5c7 | Ruby | tyranja/rubyist | /self.rb | UTF-8 | 292 | 3.125 | 3 | [] | no_license | class C
def x
puts "This is method x"
puts self
end
def y
puts "This is method y"
puts self
self.x
end
def self.test
puts self
end
#def C.no_dot
#puts "As long as self is C, you can call this method with no dot."
#end
#no_dot
end
# C.no_dot
| true |
5a3202777e6471f14839373afd141440b28ac2ce | Ruby | mskeen/adventofcode | /2015/day23/turing_lock.rb | UTF-8 | 1,604 | 3.40625 | 3 | [] | no_license | class Computer
attr_accessor :registers
PARSER = /((?<instruction>hlf|tpl|inc|jie|jio|jmp) (?<register>a|b)*(, )*(?<offset>[+\-\d]+)*)/
INSTRUCTIONS = {
"hlf" => { cmd: -> (c, reg, off) { c.registers[reg] /= 2; c.jump(1) } },
"tpl" => { cmd: -> (c, reg, off) { c.registers[reg] *= 3; c.jump(1) } },
"... | true |
be9a098c34d3c94152fb7d53c3ca723b58bd5a7d | Ruby | wipegup/backend_prework | /day_1/lrthw/ex11.rb | UTF-8 | 514 | 4.375 | 4 | [] | no_license | print "How old are you? "
age = gets.chomp
print "How tall are you? "
height = gets.chomp
print "How much do you weigh? "
weight = gets.chomp
puts "So, you're #{age} old, #{height} tall and #{weight} heavy."
### chomp removes the carriage return "\n" from the end of a strings
### `gets` prompts the user for input., a... | true |
04390762ababa199eb17ac5124895bbba499fcfb | Ruby | mimizotti/date_night | /test/binary_search_tree_test.rb | UTF-8 | 2,862 | 3.390625 | 3 | [] | no_license | gem 'minitest', '~> 5.2'
require 'minitest/autorun'
require 'minitest/pride'
require_relative '../lib/binary_search_tree'
require_relative '../lib/node'
require 'pry'
class BinarySearchTreeTest < Minitest::Test
def test_tree_adds_new_node_and_returns_depth
tree = BinarySearchTree.new
assert_equal(0, tree.ins... | true |
6b3654c393a8774d13cb174487d528eb88222b49 | Ruby | Beekasha/triangle-classification-onl01-seng-ft-012120 | /lib/triangle.rb | UTF-8 | 832 | 3.5 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Triangle
attr_accessor :length_1, :length_2, :length_3
def initialize(length_1, length_2, length_3)
@length_1 = length_1
@length_2 = length_2
@length_3 = length_3
@sides = [length_1, length_2, length_3]
end
def kind
validate_triangle
if (length_1 == length_2) && (length_2 == l... | true |
7e50fc10d75118ddadc4eccf8338f97a2515ac77 | Ruby | xurde/quizzr | /app/models/quizz.rb | UTF-8 | 2,342 | 2.953125 | 3 | [] | no_license | class Quizz < ActiveRecord::Base
belongs_to :user
belongs_to :winner, :class_name => 'User'
has_many :answers
has_many :clues
validates_presence_of :user_id, :question, :correct_answer
validates_associated :user
after_create :post_to_user_twitter
def is_open?
self.closed_at.nil?
end
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.