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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
46b8a41869e043437d9a6e4dcba044ed46c537cf | Ruby | MartijnBakker/bureau | /spec/bureau_drawer_management.rb | UTF-8 | 2,085 | 2.546875 | 3 | [
"MIT"
] | permissive | describe "A Bureau Managing It's Drawers" do
before do
class UIViewController < UIResponder
include Bureau::Controller
end
@x = UIViewController.new
@y = UIViewController.new
@structure = [
{
drawers:
[
{target: nil, action: :something},
{controller:... | true |
ab9836fd472b8ece9a3aa9f17dbcb4035a48422a | Ruby | ECOtterstrom/Ruby_Basics | /8_return/ex_84.rb | UTF-8 | 318 | 4.65625 | 5 | [] | no_license | # 8_return exercise 4
def meal
puts 'Dinner'
return 'Breakfast'
end
puts meal
# The above code will print the following:
# Dinner (returns as nil)
# Breakfast (returns as breakfast)
# The items will be on separate lines due to the two puts, the return
# will exit the method. | true |
b852de4123d6816c47260a3ab285781a9696f4b9 | Ruby | samiulsyed/terminalapp | /models/tradie_model.rb | UTF-8 | 676 | 3.09375 | 3 | [] | no_license | require_relative "./tradie_record"
class Tradie < TradieRecord
class RecordNotFound < StandardError; end
attr_accessor :businessname, :contact_num, :email, :trade
def initialize (business_name, contact_number, trade, email )
@businessname = business_name
@contact_num = contact_number
... | true |
d1236bec0447288f6bd903c713dcfcd65d8af716 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/roman-numerals/d423312ad1f04e9ea8baf7a386035ab8.rb | UTF-8 | 883 | 3.671875 | 4 | [] | no_license | class Numeric
ROMAN_NUMERALS = {
10 => [ 'I', 'V', 'X' ],
100 => [ 'X', 'L', 'C' ],
1000 => [ 'C', 'D', 'M' ],
10000 => [ 'M' ]
}
def to_roman
roman_numeral = ''
base = 1
while self >= base do
digit = (self / base) % 10
base *= 10
numerals = ROMAN_NUMERALS[ba... | true |
b4b1818bf42d137f10c15cb959621ec87451fae3 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/palindrome-products/9e99974937b6485cab601b914ff47b5f.rb | UTF-8 | 905 | 3.609375 | 4 | [] | no_license | require 'ostruct'
class Palindromes
def initialize(options={})
min_factor = options.fetch(:min_factor, 1)
max_factor = options.fetch(:max_factor)
@factors = [*min_factor..max_factor]
@palindromes = []
end
def generate
@factors.product(@factors).each do |factor_a, factor_b|
product = fa... | true |
eeee28cfefc63ffc6dd09b248bed16f6a80d1f9d | Ruby | muffatruffa/launch_school_ruby_challenges | /medium_2/palindrome_products.rb | UTF-8 | 5,981 | 3.34375 | 3 | [] | no_license | module FactorsInRangePalindrome
Palindrome = Struct.new(:value, :factors)
def set_range(min, max)
@min = min
@max = max
end
def factors(n)
return [] if n < @min
result = []
current = @min
while current * current <= n
if n/current <= @max
result << [current, n/current] if (... | true |
af16c6888c07e9db13ae96a0a1c9363a509ca9d1 | Ruby | sp-nil/pb_qs | /phonebook/lib/contact.rb | UTF-8 | 1,104 | 3.546875 | 4 | [] | no_license | require 'lib/conio'
class Contact
extend ConIO
include ConIO
attr_accessor :phonebook
def initialize(pb)
@phonebook = pb
end
def self.add_new(phonebook)
name = prompt('Enter new name: ')
number = prompt('Enter new number: ')
phonebook.add_entry(name, number)
end
def update
# Read... | true |
07442e16fb634b349efd822b9fbfb8ffce9af065 | Ruby | masimasima/ruby-lecture | /hello.rb | UTF-8 | 43 | 2.515625 | 3 | [] | no_license | puts "Hello Ruby!"
puts "Hello Ruby講義" | true |
91988e4ed6e7254665d7256fc0b2d8e34bb37a67 | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz126_sols/solutions/Donald Ball/fizzbuzz3.rb | UTF-8 | 67 | 3.3125 | 3 | [
"MIT"
] | permissive | puts (1..100).map{|n|n%15>0?n%5>0?n%3>0?n:'fizz':'buzz':'fizzbuzz'} | true |
95708868590e8a40f029f144acc53ed259baae03 | Ruby | dhimasadiyasapro/ruby-learning | /exe01.rb | UTF-8 | 132 | 3.5 | 4 | [] | no_license | puts "Hello World"
puts 3+2
puts 3*2
puts 3**2 # kuadrat
puts Math.sqrt(9) # akar kuadrat
a = 3 ** 2
b = 4 ** 2
puts Math.sqrt(a+b)
| true |
13b603d7324aa3852fcb5a67dd29ba03268e5b4f | Ruby | taylorthurlow/advent-of-code-2018 | /day8/part2-golf.rb | UTF-8 | 404 | 3.1875 | 3 | [] | no_license | #!/usr/bin/env ruby
def process(list)
num_children = list.shift
num_metadata = list.shift
[(0..num_children - 1).to_a.map { process(list) }, list.shift(num_metadata)]
end
def value(node)
node[0].any? ? node[1].map { |m| m != 0 && (m - 1) >= 0 && (m - 1) < node[0].size ? value(node[0][m - 1]) : 0 }.sum : node[... | true |
6914c651adc19b4b8bebd9ba184af776333cfd22 | Ruby | rasmusra/FiRe | /lib/workers/worker_factory.rb | UTF-8 | 1,019 | 2.71875 | 3 | [] | no_license | require_relative '../helpers/resource_locator'
require_relative '../extensions/string'
require 'yaml'
include FiRe
# Factory-class for workers. The createJobs-method reads
# worker-list from config-file and returns list of worker-instances
# Naming conventions for workers in class and configfile are:
#
# classname:... | true |
aee84c63d4806dae387f51e99d7aea2d985ad3bf | Ruby | KalebGz/Flatiron | /code/module-1/active-record-associations-tvland-lab-yale-web-yss-052520/app/models/actor.rb | UTF-8 | 306 | 2.5625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Actor < ActiveRecord::Base
has_many :characters
has_many :shows, through: :characters
def full_name
first_name + " " + last_name
end
def list_roles
roles = []
roles.push(Character.all.where(:actor == self).map{|char| char.name + " - " + char.show.name})
roles[0]
end
end | true |
82a1a726c24109cbeaccba79ac41e4584db9ba8d | Ruby | Pignataro67/parrot-ruby-v-000 | /parrot.rb | UTF-8 | 138 | 2.921875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Create method `parrot` that outputs a given phrase and
# returns the phrase
def parrot (chirp ="Squawk!")
puts chirp
return chirp
end
| true |
2589759d98e1949d953d2cfa47f2d698a5444124 | Ruby | Trevor-Robinson/Enigma | /lib/encrypt.rb | UTF-8 | 311 | 2.78125 | 3 | [] | no_license | require './lib/enigma'
enigma = Enigma.new
file = File.open("./lib/#{ARGV[0]}")
enigma.encrypt(file.readline)
new_file = File.open("./lib/#{ARGV[1]}", "w")
new_file.write(enigma.output_hash[:encryption])
puts "Created '#{ARGV[1]}' with the key #{enigma.output_hash[:key]} and date #{enigma.output_hash[:date]}"
| true |
35a27c8712da63b38bc0451ab879be8c251f699b | Ruby | avvo/validates_not_shouting | /lib/validates_not_shouting/not_shouting_validator.rb | UTF-8 | 516 | 2.859375 | 3 | [
"MIT"
] | permissive | # this is not namespaced so that we can do
# validates :body, not_shouting: true
class NotShoutingValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return true if value.blank?
if shouting?(value)
record.errors[attribute] << options.fetch(:message, "cannot be mostly ca... | true |
55e8d3d4dfd3ef08734bf0ecbdd6fe230389097a | Ruby | bsdpunk/rib | /rib | UTF-8 | 280 | 2.53125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'Resolv'
require "ipaddress"
res = Resolv::DNS.new(:nameserver => [ARGV[1]],
:search => [''],
:ndots => 1)
if IPAddress.valid? ARGV[0]
puts res.getname(ARGV[0])
else
puts res.getaddress(ARGV[0])
end
| true |
6b931938890dcb470930044c2a974f3f3c84bb35 | Ruby | jonatas/fast | /lib/fast/experiment.rb | UTF-8 | 14,545 | 2.9375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'fast'
# Allow to replace code managing multiple replacements and combining replacements.
# Useful for large codebase refactor and multiple replacements in the same file.
module Fast
class << self
# Fast.experiment is a shortcut to define new experiments and allow them to
... | true |
1d8b3eb580d914e8477a88fba873f45e8a72ab63 | Ruby | GraemeHBrown/wk4_day4_hogwarts_lab | /console.rb | UTF-8 | 432 | 2.578125 | 3 | [] | no_license | require_relative('./models/student.rb')
require('pry-byebug')
# @id = options['id'].to_i if options['id']
# @first_name = options['first_name']
# @second_name = options['second_name']
# @house = options['house']
# @age = options['age'].to_i
harry = Student.new({'first_name' => 'Harry', 'second_name' => 'Potter',
'... | true |
e302da5aa5a0592fcf6d1ba5632f8779738f7f04 | Ruby | djdeath/uni_projects | /projet_optimisation/annealing.rb | UTF-8 | 5,034 | 3.015625 | 3 | [] | no_license | require 'graph'
require 'timecounter'
require 'display'
module Annealing
def draw_annealing(display)
# Compte le temps écoulé
time = TimeCounter.new
time.start
# Température
t0 = display.prefs['annealing_... | true |
8b374fd267dd721ef3f56da1e024c78fb7d3acc8 | Ruby | ayellapragada/root | /lib/root/actions/dominance.rb | UTF-8 | 958 | 2.859375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Root
module Actions
# Handles all Dominance related logic
class Dominance
attr_reader :faction
def initialize(faction)
@faction = faction
end
def check
raise Errors::WinConditionReached.new(faction, :dominance) if dominance?
... | true |
ae16b92c20b7c39eadefb932517aeca5ad66f79a | Ruby | jihwan512/bbgr | /chatbot.rb | UTF-8 | 4,259 | 2.703125 | 3 | [] | no_license | require 'sinatra'
get '/keyboard' do
msg =
{
type: "buttons",
buttons: ["소개", "멋쟁이 사자처럼", "깃허브","멋사 AT KOREATECH"]
}
#render json: @msg, status: :ok
msg.to_json
end
post '/message' do
response = params[:content]
if respo... | true |
5c2c2e2fd303f0f7010308e539f131ed66037bd0 | Ruby | JuanFPelaez/CursoRoR5 | /Apuntes Ruby Dicampus/Ejercicios resueltos/Ejercicio 7.rb | UTF-8 | 601 | 4.03125 | 4 | [] | no_license | =begin
Hacer un método que recibe una sentencia y devuelve
true si es un palindromo (ignoramos espacios y
mayusculas/minusculas). El método reverse de
cadenas puede ser util.
=end
def palindromo?(sentence)
# eliminamos todos los espacios introducidos en 'sentence'
downcase_stripped_sentence = sentence.d... | true |
38e7e30be10d7d8c2e6d0a88c759b58f2977da72 | Ruby | MufuckaHero/rack-lesson | /application.rb | UTF-8 | 372 | 2.5625 | 3 | [] | no_license | require "slim"
module Lesson1
class EndpointContacts
def call(env)
[200, {'Content-Type' => 'text/plain'}, [env.inspect]]
end
end
class EndpointWelcome
def call(env)
_request = Rack::Request.new(env)
_body = Slim::Template.new('index.slim', {}).render(_request)
[200, {'Conte... | true |
b12597e1d572845761ccdb64d7035aa6bd264ef3 | Ruby | chen7897499/Codewars | /zip_it.rb | UTF-8 | 501 | 3.578125 | 4 | [] | no_license | #这题不能使用原来的zip方法, 被去掉了
class Array
def zip(arr, &block)
# Good Luck!
result = []
bigarray = []
lala = self
if lala.length > arr.length
lala = lala[0,arr.length]
elsif arr.length > lala.length
arr = arr[0,lala.length]
end
bigarray << lala
bigarray << arr
base = biga... | true |
afba793c6f47e9e1e41a5b151db9eb474051130f | Ruby | bethsebian/sorting_suite | /insertion_sort_archive3.rb | UTF-8 | 1,550 | 3.671875 | 4 | [] | no_license | class InsertionSort
attr_reader :unsorted, :sorted, :array_length
def initialize(unsorted,sorted=[])
@unsorted = unsorted
@sorted = sorted
@array_length = unsorted.length
end
def move_to_sorted_array_and_remove_from_old_array(new_position)
sorted.insert(new_position,unsorted[0])
unsorted.s... | true |
57964c1f13a7324af9e80f6aae8dbfcfcd914a4a | Ruby | jnunemaker/cassanity | /lib/cassanity/operator.rb | UTF-8 | 674 | 3.125 | 3 | [
"MIT"
] | permissive | module Cassanity
def self.Operator(*args)
Operator.new(*args)
end
class Operator
# Internal
attr_reader :symbol
# Internal
attr_reader :value
# Public: Returns an operator instance
def initialize(symbol, value)
@symbol = symbol
@value = value
end
def eql?(other)... | true |
772d0c634b302fbb886544d172413b884b821441 | Ruby | planningalerts-scrapers/parramatta | /scraper.rb | UTF-8 | 1,710 | 2.703125 | 3 | [] | no_license | require 'scraperwiki'
require 'mechanize'
class Hash
def has_blank?
self.values.any?{|v| v.nil? || v.length == 0}
end
end
base_url = "http://eplanning.parracity.nsw.gov.au/Pages/XC.Track/SearchApplication.aspx"
# meaning of t parameter
# %23427 - Development Applications
# %23437 - Constuction Certificates
#... | true |
f063d63320a4f7a7f7a9f91137fe461604d11600 | Ruby | JaehunYoon/Study | /Programming Language/Ruby/Example/04 method/rand/srand.rb | UTF-8 | 122 | 2.671875 | 3 | [] | no_license | srand 1234
puts rand(100)
puts rand(100)
puts rand(100)
puts " "
srand 1234
puts rand(100)
puts rand(100)
puts rand(100) | true |
e40f79f59120c44f98f769c781ab73495b39e3f2 | Ruby | Dew0Tgx/asciidoctor.js | /packages/core/lib/asciidoctor/js/opal_ext/string.rb | UTF-8 | 499 | 3.015625 | 3 | [
"MIT"
] | permissive | class String
# Safely truncate the string to the specified number of bytes.
def limit_bytesize size
return self.to_s unless size < bytes.length
result = byteslice 0, size
result.to_s
end unless method_defined? :limit_bytesize
alias :limit :limit_bytesize unless method_defined? :limit
alias :_orig... | true |
1c0f034f7d7c1b284aafeb8b200bce1f4591b245 | Ruby | justin-lilly/piglatin | /spec/pig_latin_spec.rb | UTF-8 | 330 | 2.65625 | 3 | [
"MIT"
] | permissive | require './lib/pig_latin.rb'
describe PigLatin do
before do
@string = "This is a test for the program"
end
it "first letter of word is a vowel" do
expect(PigLatin.translate("String")[0]).to eq ("i")
end
it "returns ay at the end of word" do
expect(PigLatin.translate("String")[0]).to eq ("i")
... | true |
ae3f73f7b49fdafd4d4cd71519d67af3a67d93dc | Ruby | elliotthilaire/drip-photography | /lights-out-and-shoot/drip_and_shoot_sequence.rb | UTF-8 | 411 | 3.453125 | 3 | [
"MIT"
] | permissive | require "rubyserial"
class DripAndShootSequence
def initialize(serial_string:)
@serial_port = Serial.new serial_string, 9600
end
def run
@serial_port.write("shoot\n")
while true
data = @serial_port.read(1)
print data
# A quick and dirty hack to brack the loop.
# This is the... | true |
10cc93da0a6ab47c1958c0731d929b3f42cd2430 | Ruby | lucidsoftware/cumulus | /lib/s3/models/WebsiteConfig.rb | UTF-8 | 2,798 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | module Cumulus
module S3
class WebsiteConfig
attr_reader :error
attr_reader :index
attr_reader :redirect
# Public: Constructor
#
# json - a hash representing the JSON configuration, expects to be handed
# the 'website' node of S3 configuration.
def initializ... | true |
69e20c9c30eda5874cbaa3cb453ceabda61f8b36 | Ruby | aydyn-gur/intro-to-ruby | /more_stuff/exercise_2.rb | UTF-8 | 224 | 3.421875 | 3 | [] | no_license | def execute(&block)
block
end
execute { puts "Hello from inside the execute method!" }
# This program will not print anything to the screen because there
# is no call method on the block. It will return a Proc object. | true |
e83850fa2018df217b1fc8f4ba6f357160badf2b | Ruby | gropax/golyglot | /app/helpers/cmn/lexical_entries_helper.rb | UTF-8 | 274 | 2.546875 | 3 | [] | no_license | module Cmn::LexicalEntriesHelper
def cmn_lemma(lexical_entry)
[
lexical_entry.simplified,
brackets(lexical_entry.traditional),
lexical_entry.pinyin
].compact.join(" ")
end
def brackets(text)
text.blank? ? nil : "【#{text}】"
end
end
| true |
cb86d7500cec4c1b53a895f91dc8ed687545a364 | Ruby | nuthatch-s/RB101 | /3-practice_problems/array_add_many_elements.rb | UTF-8 | 183 | 2.796875 | 3 | [] | no_license | flintstones = %w(Fred Barney Wilma Betty Pebbles BamBam)
flintstones.append("Dino", "Hoppy")
# or flintstones.push("Dino", "Hoppy")
# or flintstones.concat(%w(Dino Hoppy))
p flintstones
| true |
01a95ac1bd23aa59e812a72f5708cee04b6e2e1c | Ruby | jeanmerlet/ruby_games | /dungeon/src/gui/viewport.rb | UTF-8 | 1,432 | 2.796875 | 3 | [] | no_license | class Viewport
attr_reader :width, :height, :x_off, :y_off
def initialize(map, entities, player)
@map, @entities, @player = map, entities, player
@width = (Config::SCREEN_WIDTH - Config::SIDE_PANEL_WIDTH)/2
@height = Config::SCREEN_HEIGHT - Config::VERT_PANEL_HEIGHT
@x_off, @y_off = @width/2, @heig... | true |
64e44b4c0254b22f6fc8b039dd6380979ee7269d | Ruby | SocialCentivPublic/cheftacular | /lib/cheftacular/stateless_actions/clean_cookbooks.rb | UTF-8 | 4,020 | 2.71875 | 3 | [
"MIT"
] | permissive |
class Cheftacular
class StatelessActionDocumentation
def clean_cookbooks
@config['documentation']['stateless_action'][__method__] ||= {}
@config['documentation']['stateless_action'][__method__]['long_description'] = [
"`cft clean_cookbooks [force] [remove_cookbooks]` allows you to updat... | true |
0f9d5b7d234c3dd8310753d4b32bcf5c8a6a9dce | Ruby | abalewis/cyrillic | /lib/cyrillic.rb | UTF-8 | 1,795 | 3.25 | 3 | [
"MIT"
] | permissive | require "cyrillic/version"
module Cyrillic
# Note. The letters І, Ѣ, Ѳ and Ѵ were eliminated in the orthographic reform of 1918.
# For other obsolete letters appearing in Russian texts, consult the Church Slavic table.
CHARACTER_TABLE = {
"А" => "A",
"Б" => "B",
"В" => "V",
"Г" => "G",
"Д"... | true |
ca5054fd22376ac68335d92f3314f450ac12e4a7 | Ruby | SeaRbSg/rosalind | /sotoseattle/problems/rear.rb | UTF-8 | 1,178 | 3.46875 | 3 | [
"MIT"
] | permissive | class Rosalind
def self.rear inputo
inputo.split(/\n+/).map {|s| s.split(' ').map(&:to_i)}
.each_slice(2).map { |x, y| [switcheroo(x, y), switcheroo(y, x)].min }
.join(" ")
end
def self.switcheroo wip, goal, n = 0
return n if wip == goal
[basic_swap(wip, goal, n),
basic_swa... | true |
3d014cfbe86dcb621d3d1bd82e039f7be79f06f6 | Ruby | binarytemple/enron_slurper | /app/helpers/email.rb | UTF-8 | 1,474 | 2.609375 | 3 | [
"MIT"
] | permissive | # Make it easy to convert RFC822 to JSON
module Mail
class Message
# DELIMITER = "\x1f"
DELIMITER = ','
attr_accessor :person, :mailbox
# keyed by
# customer-id | mailbox | message-id
def message_id
id = header.fields.detect do |x|
x.name == 'Message-ID'
end.to_s
i... | true |
88b783ca263d09f49cc518a41e37eb12f68aa682 | Ruby | ericawinne/active-record-toy-tale-practice | /app/models/toy.rb | UTF-8 | 396 | 2.6875 | 3 | [] | no_license | class Toy < ActiveRecord::Base
has_many :purchases
has_many :kids, through: :purchases
def self.most_expensive
self.find_by(price: Toy.maximum(:price)) #like doing Toy.all.maximum
end
def self.most_popular
most_popular = self.all.map{ |t| t.purchases.count}.max
self.all.find{ |t| t.purchases.cou... | true |
b0dab2fd2455c4b80f14751aa0ae9209b3e498c1 | Ruby | yudai142/fleamarket_sample_61a | /app/models/category.rb | UTF-8 | 239 | 2.65625 | 3 | [] | no_license | class Category < ApplicationRecord
has_many :items
has_ancestry
def self.c_category(parent)
ch = []
parent.each do |parent|
parent.children.each do |child|
ch << child
end
end
return ch
end
end | true |
4d350bb504d52bd1d15b0b13c794cd2ba7a39dba | Ruby | JordanYu4/algorithms_practice | /ruby/spec/array_diff_spec.rb | UTF-8 | 1,072 | 2.859375 | 3 | [] | no_license | require 'rspec'
require 'array_diff'
describe 'array_diff' do
before { @arr1 = [1] }
before { @arr2 = [2] }
it 'returns a new array' do
array_diff([1, 2, 4, 5], [1, 4]).should_not be([2, 5])
array_diff(@arr1, @arr2).should_not be(@arr1)
array_diff(@arr1, @arr2).should_not be(@arr2... | true |
c354c8cd20080cf35b07bd36548d9e870cc24754 | Ruby | tlunter/Prerender | /lib/prerender/searcher.rb | UTF-8 | 1,063 | 2.71875 | 3 | [] | no_license | require 'excon'
require 'nokogiri'
def search_document(conn, contents, previous_links)
document = Nokogiri::HTML(contents)
document.xpath('//a/@href').each do |a|
puts "Found: #{a}"
next_uri = URI.parse(a)
if next_uri.host == nil && next_uri.scheme == nil
unless previous_links.include? next_uri
... | true |
7672f5980006f18cb6155810d7f5dc4fb2cbcdb5 | Ruby | alexamy/thinknetica-blackjack | /models/card/deck.rb | UTF-8 | 364 | 3.15625 | 3 | [] | no_license | # Cards holder
class Deck
attr_reader_writer :cards
delegate :pop, :push, :map, :length, to: :cards
alias get pop
alias add push
def initialize(cards = [])
@cards = cards.shuffle
end
def points
sum = cards.sum(&:points)
aces = cards.select { |card| card.value == :ace }
sum += 10 if ac... | true |
f842520e048fe9a197f5f1dd3139a0d2868f3226 | Ruby | mashan/Benchmarks | /NoSQL/benchmark.rb | UTF-8 | 8,207 | 2.703125 | 3 | [] | no_license | require 'pp'
require 'benchmark'
require 'optparse'
require './lib/kvs_benchmarker'
DB_NAME = 'test'
TABLE_NAME = 'hs_test'
HS_RO_PORT = '9998'
HS_RW_PORT = '9999'
MEMCACHE_PORT = '11211'
STDOUT.sync = true
options = {}
OptionParser.new do |o|
o.banner = "Usage ruby #{File.basename($0)} [OPTIO... | true |
c0a4ce0faedf1642b67acbb323c3090339122d2e | Ruby | arlemi/OpenRecord-CI | /array.rb | UTF-8 | 560 | 2.6875 | 3 | [] | no_license | class Array
#
# Selectionne les elements dont le champ id satisfait le critere
# specifie par le bloc.
#
def selectionner_avec( id )
DBC.check_type( id, Symbol,
"** L'argument a selectionner_avec doit etre un symbole" )
nil
end
def method_missing( id, *args )
if id.t... | true |
b3426cf76570c5cce344c68aa15046a59f01e059 | Ruby | motapuma/al-tweets | /app/helpers/tweets_helper.rb | UTF-8 | 555 | 2.75 | 3 | [] | no_license | module TweetsHelper
def correct_txt_and_class_fav(current_user,tweet)
faved = current_user.faved?(tweet)
txt = faved ? "UnFav" : "Fav"
button_class = faved ? "btn btn-danger btn-lg" : "btn btn-warning btn-lg"
return txt, button_class , faved
end
def correct_txt_and_class_retweet(current_user,... | true |
102b9a431440228229d4f31b29330ee048c873e8 | Ruby | asjedh/slacker_news_sql | /server.rb | UTF-8 | 1,384 | 3.03125 | 3 | [] | no_license | require 'sinatra'
require 'csv'
require 'pry'
require 'pg'
require 'net/http'
require 'addressable/uri'
### METHODS
def db_conn
begin
connection = PG.connect(dbname: 'slacker_news')
yield(connection)
ensure
connection.close
end
end
def save_article_to_db(article_info_array)
db_conn do |conn|
... | true |
85d84e1abf1bf861e69a88fc24d0175bd41c848d | Ruby | hging/trex | /vendor/screen/lib/screen/colourize.rb | UTF-8 | 723 | 3.359375 | 3 | [] | no_license | class Colourize
FG_NORMAL = -1
BG_NORMAL = -1
COLORS = [
0,1,2,3,4,5,6,7,9
]
def self.generate str, fcol=FG_NORMAL, bcol=BG_NORMAL, bold: false
bcol = 9 if bcol == -1
bcol = bcol + 40 if bcol <= 9
fcol = 9 if fcol == -1
fcol = fcol + 30 if fcol <= 9
bcol = 1 if bold... | true |
e92bfda6376647bf1bed0a0441f89dbc3c01d314 | Ruby | laurawhalin/book_search | /app/models/search.rb | UTF-8 | 662 | 2.671875 | 3 | [] | no_license | class Search < ApplicationRecord
validates :author, presence: true, unless: :title
validates :title, presence: true, unless: :author
validates :title, uniqueness: { scope: :author, message: "Title/author pairing already exists" }
before_validation :format_title
before_validation :format_author
before_sav... | true |
da40e0fd311c8d88e467360229e4d85f083ac452 | Ruby | shelkarvijay/ruby_basics | /class.rb | UTF-8 | 564 | 4.09375 | 4 | [] | no_license | class Class
def initialize(m,n)
@width ,@height = m, n
end
def width #this methos is known as accessor method
@width
end
def height #this methos is known as accessor method
@height
end
def setter1=(value)
@width = value
end
def self.setter2=(value) #class method definition
@height = value
end... | true |
ec29af8290372fb6bbf2dbf8d5ce09150d490319 | Ruby | DouglasAllen/code-Metaprogramming_Ruby | /raw-code/PART_II_Metaprogramming_in_Rails/gems/activesupport-4.0.2/lib/active_support/core_ext/string/zones.rb | UTF-8 | 748 | 2.875 | 3 | [
"MIT"
] | permissive | #---
# Excerpted from "Metaprogramming Ruby",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http:/... | true |
4fe8be6d66ebf8224227a21918b353e3ed775e03 | Ruby | Carlospp/mariaauxiliadora | /app/models/treatment.rb | UTF-8 | 496 | 2.65625 | 3 | [] | no_license | class Treatment < ActiveRecord::Base
validates :nombre , presence: { message: " es requerido"} , confirmation: true
validates :costo , presence: { message: " es requerido"} , confirmation: true
validates :costo, numericality: { only_integer: true ,message: "no es un numero"}
def self.to_csv(options = {})
... | true |
89facdd65e2fd6c39e7714b55bc82c6c5c6a5729 | Ruby | nico-hn/PseudoHikiParser | /test/test_htmlplugin.rb | UTF-8 | 1,772 | 2.765625 | 3 | [
"BSD-2-Clause"
] | permissive | #/usr/bin/env ruby
require 'minitest/autorun'
require 'lib/pseudohiki/htmlplugin'
class TC_HtmlPlugin < MiniTest::Unit::TestCase
include PseudoHiki
def test_visit_pluginnode
formatter = HtmlFormat.get_plain
tree = InlineParser.new("{{co2}} represents the carbon dioxide.").parse.tree
assert_equal("CO<... | true |
9c8e211a6c39cd5dbe3e503122da53488bab8dd7 | Ruby | phistando/Redmart-Sinatra | /app.rb | UTF-8 | 5,256 | 2.765625 | 3 | [] | no_license | class RedmarkSinatraApp < Sinatra::Base
get '/' do
erb ''
end
# RESTFUL RESOURCES, CREATE READ UPDATE DELETE
################################ Users ###################################
get '/users' do
@users = User.all
erb :'users/index'
end
get '/users/:id' do
if params[:id] == 'new'
... | true |
388c2445f20b1b87dc4de91634768b9da95fffaa | Ruby | DevGGuedes/Ruby-POO | /Times.rb | UTF-8 | 77 | 3.125 | 3 | [] | no_license |
5.times {
puts "Rodando"
}
puts ""
10.times { |i|
puts "Rodando #{i}"
} | true |
f2c77174de6bc40700fd6f3706bc7d4d2f099b38 | Ruby | DimaSamodurov/browser_crawler | /spec/lib/hooks_operator_spec.rb | UTF-8 | 3,304 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe BrowserCrawler::HooksOperator do
before :each do
lambda do
return nil unless Object.constants.include?(:ClassSubject)
Object.send(:remove_const, :ClassSubject)
end.call
end
describe '.with_hooks_for' do
it 'executes hooks with type :all for a passed block'... | true |
8467c1e21dad67dfc02faf0ff0a2028b4c6658dc | Ruby | yurifrl/curly | /spec/scanner_spec.rb | UTF-8 | 2,546 | 2.84375 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
describe Curly::Scanner, ".scan" do
it "returns the tokens in the source" do
scan("foo {{bar}} baz").should == [
[:text, "foo "],
[:component, "bar"],
[:text, " baz"]
]
end
it "scans components with identifiers" do
scan("{{foo.bar}}").should == [
[:compo... | true |
c19b8eb694014ba241c8b65125f614cc8ba12c01 | Ruby | Linktheoriginal/Euler | /triangle_numbers.rb | UTF-8 | 957 | 3.78125 | 4 | [] | no_license | #I originally was running x up to k/2 (started k at 1 for dividing itself), but I stole
#the sqrt idea from here:http://www.mathblog.dk/triangle-number-with-more-than-500-divisors/
#The second solution is basically usingthe prime divisor code from problem 3 plus combinatorics
#of the prime factors to figure it out.... | true |
16f068eab7b537fa461eac614559596f2dca117e | Ruby | alpaca-tc/tweet_cleaner | /twitter.rb | UTF-8 | 713 | 2.546875 | 3 | [] | no_license | require 'twitter'
require 'yaml'
require 'parallel'
current_dir = File.expand_path(File.dirname(__FILE__))
CONFIG = YAML.load_file("#{current_dir}/config.yml").freeze
client = Twitter::REST::Client.new do |config|
config.consumer_key = CONFIG['CONSUMER_KEY']
config.consumer_secret = CONFIG['CONSUMER_SE... | true |
03b28dac9b796807559dcf5e3975c8d8a07255c6 | Ruby | lorijustlori/C25-REPL-Game | /replgame.rb | UTF-8 | 15,879 | 3.546875 | 4 | [] | no_license | puts "Good morning, Wynfamily! Looks like we have a full house today and everyone is ready to learn!"
puts "Oh, wait. Why is everyone leaving?"
puts "Choose the corresponding number to follow an escapee group of Wyncoders...."
puts "Choose 1 to follow Andrew, Andreina, Gabe and Angel, Choose 2 to follow Stephen, A... | true |
9eeae35ce6ba87f471e28100df56c475bf16925f | Ruby | erikbenton/AppAcademyFullStackOnline | /SQL/Object Relational Model/AA Questions/reply.rb | UTF-8 | 1,768 | 3.140625 | 3 | [] | no_license | require_relative 'questions_database.rb'
require_relative 'model_base'
require_relative 'user.rb'
require_relative 'question.rb'
class Reply < ModelBase
attr_accessor :id, :question_id, :parent_id, :author_id, :body
def self.find_by_question_id(question_id)
replies = QuestionsDBConnection.execute(<<-SQL, ques... | true |
9c191c02e777b2b7a594ba4aa80f56f10fe38735 | Ruby | aleksarakic/scraperio | /lib/helper.rb | UTF-8 | 646 | 3.546875 | 4 | [] | no_license | require_relative 'translate/translation.rb'
module Helper
def temp_hash
{
-50..0 => ['Freezing', 'Time for winter clothes', 'Fire would be nice'],
1..15 => ['Meek', "Let's go south", "I will stay home"],
16..25 => ['Feels nice', 'Where are we?', 'Possible rain'],
26.. => ['Boils inside', 'Fan noise', 'H... | true |
b8feb80b45e4054c8a8f0c31a8b5a7a18b4c333c | Ruby | qqdipps/hotel | /lib/room.rb | UTF-8 | 1,133 | 2.953125 | 3 | [] | no_license | require_relative "reservation"
module Hotel
class Room
attr_reader :id, :cost_per_night, :unavailable_list
def initialize(id:, cost_per_night:, unavailable_list: nil)
@id = id
@cost_per_night = cost_per_night
@unavailable_list ||= []
end
def available_for_date_range?(date_range:)
... | true |
2798d96d3ca3fe167a28a44c6704c3b47d3d4a67 | Ruby | jetpackpony/travelbot | /lib/chat.rb | UTF-8 | 4,354 | 2.671875 | 3 | [] | no_license | require "json"
require "dotenv"
Dotenv.load
require "./lib/skyscanner_api/skyscanner_api"
module TravelBot
class Chat
WAIT_MESSAGE = { type: :none, label: "Hold on I'll fetch you flight info" }
FATAL_MESSAGE = { type: :none, label: "Oops, there was a problem with searching for your flight. A well trained gro... | true |
dff2783723efc72d2edfe9b3da137ece636cf231 | Ruby | jrwest990/blog-app-jaydub | /calculator6.20.rb | UTF-8 | 477 | 3.953125 | 4 | [] | no_license | # @author john
# input should be 2 values and an expression
# output should be a number
def calculate(x, y, expression)
if (x == null || y = null)
puts "invalid input"
elsif (expression == '+')
return x + y
elsif (expression == "*")
return x * y
elsif (expression == "-")
... | true |
7b6eb49fae41d0001b6822e2a6f5bec064d635fb | Ruby | lcowell/railsjam_ruby_examples | /part2_variables/01_assignments.rb | UTF-8 | 123 | 2.734375 | 3 | [] | no_license | #don't need to statically declare the type
#
# a = "hello"
# puts a.class
#
# a = 123
# puts a.class
#
# b = a
# puts b
| true |
36990db6af0035caa4977725a5c519a1e0f7b0fe | Ruby | Valcroca/DevPointCourse | /Exercises_form_Classes/pagination_example/lib/tasks/scrape.rake | UTF-8 | 792 | 2.75 | 3 | [] | no_license | require 'mechanize'
namespace :scrape do
desc "Scape dem rappers off dat webpage foshizzle"
task rappers: :environment do
agent = Mechanize.new
page = agent.get('http://www.buzzle.com/articles/rappers-list.html')
page.search('#article-body .leftnote').each do |rapper|
name = rapper.text.strip
... | true |
dbd91ce0e737572e6a5dfb954df24ac0092435a5 | Ruby | aromatt/pushfour | /lib/board.rb | UTF-8 | 20,266 | 3.078125 | 3 | [] | no_license | module PushFour
BLUE_CHAR = 'b'
RED_CHAR = 'r'
ROCK_CHAR = '#'
EMPTY_CHAR = '+'
class Board
attr_accessor :rows, :columns, :win_len, :cache
attr_reader :board_string # arbitrarily setting this would break cache
@@timing = Hash.new { |h,k| h[k] = 0 }
@@calls = Hash.new { |h,k| h[k] = 0 ... | true |
3d8bad6094a8b20d5ff719fd51d80183c5c6326e | Ruby | jjyg/rbircd | /crypto.rb | UTF-8 | 3,732 | 3.453125 | 3 | [] | no_license | # pure ruby implementation of Diffie-Hellman and RC4
module Bignum_ops
# b**e % m
def mod_exp(b, e, m)
raise if e < 0
ret = 1
while e > 0
ret = (ret * b) % m if (e&1) == 1
e >>= 1
b = (b * b) % m
end
ret
end
SMALL_PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] unless defined? SMALL_PRIMES
... | true |
6ac8e05a0ff64cdba3baa7f4662eb887f9fa09c7 | Ruby | vinhnglx/artistspy | /app/services/searchable_service.rb | UTF-8 | 919 | 2.609375 | 3 | [] | no_license | class SearchableService
include HTTParty
base_uri ENV['api_uri'] || 'api.spotify.com'
DEFAULT_ENDPOINT = ENV['artist_endpoint']
DEFAULT_LIMIT = ENV['api_limit']
# Public: Create constructor
#
# Parameters
#
# searches - A hash contains query and limit
#
# Example
#
# SearchableServi... | true |
6a65f34206b8a67433da7e7696fb3756aae46601 | Ruby | EvilScott/bard_bot | /lib/bard_bot/dictionary.rb | UTF-8 | 846 | 3.1875 | 3 | [
"MIT"
] | permissive | module BardBot
class Dictionary
def initialize(config)
@prefix = config.prefix.to_i
@max_length = config.max_length
@file_path = File.join(config.character_dir, "#{config.character}.txt")
@dictionary = Hash.new { |h, k| h[k] = [] }
load_corpus!
end
def load_corpus!
cor... | true |
775a86cf6b2903587f7b58033ea08f7e706da4a6 | Ruby | Denizdius/Ruby_calisma | /ruby/rb_somethings/ornek_3.rb | UTF-8 | 232 | 3.515625 | 4 | [] | no_license |
puts"Merhaba,kameranı çok beğendim adınız nedir ? "
isim=gets
puts "Ben biraz takıntulyım soyadınız nedir ?"
soyad=gets
puts ("OOOO hemşerim naber ya " + isim.chomp +" " soyad.chomp + "bende" + soyad.chomp + "undanım")
| true |
25f379b4085a5567114f651fecfb68d13032e519 | Ruby | trendwithin/effective-couscous | /app/workflows/create_new_symbols.rb | UTF-8 | 716 | 2.6875 | 3 | [] | no_license | class CreateNewSymbols
attr_reader :params, :errors
def initialize params
@params = params
@errors = []
end
def valid_data_format?
true if params.match(/^[[:alpha:][:blank:]]+$/)
end
def params_to_array
params.split(/\W+/)
end
def split_on_return
params.split(/\r?\n/)
end
de... | true |
eae8e75fdac5f94b2c01258a7562e8531d89571e | Ruby | igorsimdyanov/gb | /part3/lesson6/sort.rb | UTF-8 | 198 | 3.0625 | 3 | [] | no_license | p [6, 2, 8, 3, 9, 11, 1].sort
arr = %w[second third fst]
p arr.sort { |a, b| a.size <=> b.size }
p arr.sort_by(&:size)
# лунь
# нуль
# 'лунь'.split('').sort == 'нуль'.split('').sort | true |
03620de8dbb070b18a94670a1fa879ed570e282e | Ruby | eluke66/checkers | /ruby/Driver.rb | UTF-8 | 1,027 | 3.515625 | 4 | [] | no_license | require "benchmark"
require "Game"
require "ConsolePlayer"
class RandomOptionPlayer
def initialize(name)
@name = name
end
def select_move(moves, board)
return moves.sample
end
def to_s
return @name
end
end
def profile(numRuns)
totalTime = 0
player1 = RandomOptionPlayer.new("player 1")
pl... | true |
0f4d84850b55f9967146e041585f4e7da3a2ad04 | Ruby | Bitmap0079/CycleSpotter | /app/models/post.rb | UTF-8 | 594 | 2.71875 | 3 | [] | no_license | class Post < ApplicationRecord
validates :name, presence: true
validates :name, length: { maximum: 50 }
# validates :validate_name_not_include_comma
belongs_to :user
scope :recent, -> { order(created_at: :desc)}
private
#コンマを含めないようにするバリデーション
def validate_name_not_include_comma
er... | true |
3b54faaf0efc7f1c00d2347bdf06b3d5dedd76da | Ruby | brewchetta/alphabetize-in-esperanto-nyc-web-100818 | /lib/alphabetize.rb | UTF-8 | 338 | 3.296875 | 3 | [] | no_license |
ESPERANTO = ["a","b","c","ĉ","d","e","f","g","ĝ","h","ĥ","i","j","ĵ","k","l","m","n","o","p","r","s","ŝ","t",
"u","ŭ","v","z"]
def alphabetize(phrases)
phrases.sort_by!{ |a| ESPERANTO.index(a.split("").first) }
puts phrases
phrases
end
# I got it to work just fine for me so I went ahead and submitted without... | true |
c9fa5817a1249aa691a18ac80864e2f5bf277732 | Ruby | lowellmower/tic_tac_toe | /lib/models/human_player.rb | UTF-8 | 404 | 2.984375 | 3 | [] | no_license | require_relative 'player'
class HumanPlayer < Player
attr_accessor :name, :piece
def initialize(args = {})
args = defaults.merge(args)
end
def make_move(move, board)
if valid_move?(move) && move_available?(move, board)
place_piece(move, board) and return true
end
board.reject_piece
en... | true |
72272ba5a09dfab56e307dd9ac766c0101687637 | Ruby | geoquant/oroshi | /scripts/bin/mobi2epub | UTF-8 | 914 | 3 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'shellwords'
# Converts a .mobi file to a .epub one
class Mobi2Epub
def initialize(*args)
@mobi = File.expand_path(args[0])
@ext = File.extname(@mobi)
@basename = File.basename(@mobi, @ext)
@epub = File.expand_path("#{@basename}.epub")
@cover = File.expand_path("#{@bas... | true |
8fde7488858d5376115e075f8212d338557c6bcd | Ruby | smalruby/smalruby-installer-for-windows | /Ruby216_32/lib/ruby/gems/2.1.0/gems/smalruby-0.1.11-x86-mingw32/samples/hardware_neo_pixel2.rb | UTF-8 | 881 | 2.71875 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
DESCRIPTION = <<EOS
マイコン内蔵RGB LEDを制御します
EOS
# マイコン内蔵RGB LEDデジタルの5番ピンに、
# スイッチをデジタルの3・4番ピンに接続してください。
require 'smalruby'
init_hardware
stage1 = Stage.new(color: 'white')
stage1.on(:start) do
color_codes = Color::NAME_TO_CODE.keys
index = 0
loop do
fill(color: 'white')
color = c... | true |
0fdd1831ea92803ece275423dd06358fcf4b34d5 | Ruby | PianoFF/ruby-enumerables-hash-practice-nyc-pigeon-organizer-lab-london-web-102819 | /nyc_pigeon_organizer.rb | UTF-8 | 358 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def nyc_pigeon_organizer(data)
nyc_pigeon = Hash.new
names = data[:gender].values
names.map{|i| i.map {|name|
nyc_pigeon[name]= {:color => [], :gender => [], :lives => []
}
}
}
nyc_pigeon
data.select{|key, value|
value.select{|key_2, value_2|
value_2.map{|name|
nyc_pigeon[name][key]<<key_2... | true |
cf9366346260729471b6d6588418de6f69e4eeb3 | Ruby | t9md/vim-transform | /misc/ruby_handler/lib/transformer/go.rb | UTF-8 | 1,304 | 2.8125 | 3 | [] | no_license | module Transformer
module Go
class Import
def self.run(input)
r = []
repos = {
gh: "github.com",
cg: "code.google.com",
gl: "golang.org",
}
input.each_line do |l|
l.strip.split.map do |e|
repos.each do |k, v|
... | true |
0fa50b8e9de495016c7a917c3ef5f24e45494696 | Ruby | Dwire/keys-of-hash-prework | /lib/keys_of_hash.rb | UTF-8 | 151 | 3.046875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Hash
def keys_of(*arguments)
key_arr = []
self.each {|key, value| key_arr << key if arguments.include?(value)}
key_arr
end
end
| true |
f6ac5cbb08fb1eb6b3b78f19ce5e2781ec76b7f9 | Ruby | thomasfedb/warp | /lib/warp/controller_matchers/assign_matcher.rb | UTF-8 | 4,745 | 2.671875 | 3 | [
"MIT"
] | permissive | require "warp/matcher"
module Warp
module ControllerMatchers
class AssignMatcherBuilder
attr_reader :assign_key, :controller
def initialize(assign_key, controller)
@assign_key = assign_key
@controller = controller
end
def with(value)
AssignWithMatcher.new(@contro... | true |
b9f403b307df4a642a6aaa75a5a9ea980b317b08 | Ruby | bottles9/sharetribe-clone | /spec/services/payment_math_spec.rb | UTF-8 | 751 | 2.703125 | 3 | [
"CC-BY-2.5",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | describe PaymentMath do
describe "#service_fee" do
it "calculates service fee from price and commission percentage" do
PaymentMath.service_fee(10000, 12).should == 1200
end
it "ceils the service fee" do
PaymentMath.service_fee(500, 12).should == 100
PaymentMath.service_fee(2900, 10).sho... | true |
d6a1e298633818eef5bda8fbd95912e266ff9123 | Ruby | TenBesta/exported_scripts | /Classes Setup.rb | UTF-8 | 4,707 | 2.53125 | 3 | [] | no_license | # encoding: utf8
# [127] 62258286: Classes Setup
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# The instance of this... | true |
f27afe3529f73b2acd05203e2cc3b4168242e227 | Ruby | shaun-yb/leetcode | /114_flatten_binart_tree_to_linked_list.rb | UTF-8 | 843 | 3.796875 | 4 | [] | no_license | # https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @return {Void} Do not return any... | true |
fafbc56c896088b7950572016e215bb190006a2f | Ruby | aliwoodman/ruby-test | /calc9.rb | UTF-8 | 315 | 3.640625 | 4 | [] | no_license | puts "Generate leap years list"
puts "Start year?"
start_year = gets.to_i
puts "End year?"
end_year = gets.to_i
while start_year <= end_year
if start_year % 400 == 0
puts start_year
elsif start_year % 100 != 0 and start_year % 4 == 0
puts start_year
else
end
start_year = start_year + 1
end
puts "End"
| true |
d7efd0a304366f3773cfd7829604a3086fe09e13 | Ruby | fiosman/App-Academy | /ruby_curriculum/19_simon/lib/simon.rb | UTF-8 | 1,139 | 3.5625 | 4 | [] | no_license | class Simon
COLORS = %w(red blue green yellow)
attr_accessor :sequence_length, :game_over, :seq
def initialize
@sequence_length = 1
@game_over = false
@seq = []
end
def play
until game_over
self.take_turn
system('clear')
end
self.game_over_message
self.reset_game... | true |
e83709fae560abdf0c5254c888376ab00f622fa6 | Ruby | eturino/etudev_rails_app | /spec/support/mini/shared/eql.rb | UTF-8 | 763 | 2.71875 | 3 | [] | no_license |
shared_examples_for "(eql? == hash) no" do
it "eql? false" do
expect(subject.eql?(other)).to be_false
end
it "== false" do
expect(subject == other).to be_false
end
it "hash not the same" do
expect(subject.hash).not_to eq other.hash
end
it "if uniq is called in an array with the 2, both remain... | true |
91ae0d56b6048f82f1f354ea2b454c07f78359dd | Ruby | CrystalPea/student-directory | /source_code_reader.rb | UTF-8 | 104 | 2.828125 | 3 | [] | no_license | def read_code(filename = $0)
code_string = (File.read filename).to_s
puts code_string
end
read_code | true |
f98429f0e243dc94d1006f43bc3ba7ade6075ec8 | Ruby | addislw/appA-Intro | /advanced_problems.rb | UTF-8 | 13,784 | 4.40625 | 4 | [] | no_license | # Write a method map_by_name that takes in an array of hashes and returns a new array containing the names of each hash
def map_by_name(hash_array)
hash_array.map { |hash| hash["name"] }
end
pets = [
{"type"=>"dog", "name"=>"Rolo"},
{"type"=>"cat", "name"=>"Sunny"},
{"type"=>"rat", "name"=>"Saki"},
{"type"=... | true |
e4408dc1099bf2893ea3fff926c149fb2f599a19 | Ruby | muaad/WhatsWeb | /app/models/ticket.rb | UTF-8 | 1,643 | 2.65625 | 3 | [] | no_license | class Ticket < ActiveRecord::Base
belongs_to :customer
belongs_to :account
scope :not_closed, -> { where("status = ? or status = ? or status = ? or status = ?", "1", "2", "3", "4") }
STATUS_NEW = '1'
STATUS_OPEN = '2'
STATUS_PENDING = '3'
STATUS_SOLVED = '4'
STATUS_CLOSED = '5'
STATUS_WAITING_ON_CUSTOMER = '... | true |
9caa12fcc1019e3001f9bff31e052bee85b71352 | Ruby | chian88/course_120 | /rps8.rb | UTF-8 | 6,585 | 3.65625 | 4 | [] | no_license | require 'pry'
class Score
attr_accessor :value
def initialize(value)
@value = value
end
def full?
@value >= 5
end
def reset
self.value = 0
end
end
class Rock
attr_accessor :value
def initialize
@value = "rock"
end
def win_over(other_type)
(other_type.instance_of? Scissors... | true |
ade93be05133099dda1435fdc201177d4fc0f775 | Ruby | ntl/raygun-client | /materials/event_store_client_http_session.rb | UTF-8 | 2,432 | 2.546875 | 3 | [
"MIT"
] | permissive | module EventStore
module Client
module HTTP
class Session
setting :host
setting :port
dependency :logger, Telemetry::Logger
def self.build
logger.trace "Building HTTP session"
new.tap do |instance|
Telemetry::Logger.configure instance
... | true |
1c15403132593a4cb3ca0768cd4e186f73dd528e | Ruby | carloshdelreal/coding_challenges | /leet/4_median_of_two_sorted.rb | UTF-8 | 1,324 | 3.59375 | 4 | [] | no_license | # frozen_string_literal: true
# @param {Integer[]} nums1
# @param {Integer[]} nums2
# @return {Float}
def find_median_sorted_arrays(nums1, nums2)
total_length = nums1.length + nums2.length
median_index = total_length / 2
previous = nil
if total_length.odd?
loop do
if !nums1[0].nil? && (nums2[0].nil?... | true |
3dae6ef3f8e7a8c271e62ab3f2d4f70808d535e8 | Ruby | trumans/ruby | /date_difference.rb | UTF-8 | 3,762 | 3.59375 | 4 | [] | no_license | # Date Difference
require 'test/unit/assertions'
extend Test::Unit::Assertions
def date_difference(start_year, start_month, start_day, end_year, end_month, end_day)
def days_in(year, month)
case month
when 1,3,5,7,8,10,12
31
when 2
# leap year if evenly divisible by 4 and not century, or by 400
((yea... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.