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
0ece8c46c2f9ba68023f518840343914161b5d7f
Ruby
feigningfigure/WDI_NYC_Apr14_String
/w01/d05/Jane_Shin/animal_shelter/classes/client.rb
UTF-8
527
3.8125
4
[]
no_license
class Client attr_accessor :name, :age, :pets def initialize(client_name, client_age) @name = client_name @age = client_age @pets = Hash.new #make hash, change errthing else end def pet_count @pets.length end def display_pets @pets.each {|pet, pet_attr| puts pet} end def give_away_pet(pet_name) ...
true
dc787ec0cc51cfa4824ac6fc57fe42a80399faa2
Ruby
TyMazey/enigma
/lib/key_generator.rb
UTF-8
217
3.234375
3
[]
no_license
class KeyGenerator def initialize @numbers = (0..9) end def randomizer rand(@numbers).to_s end def self.create(length) key = new length.times.collect {|num| key.randomizer}.join end end
true
2f1315204f46b446d2530fdbb53630fb7b54906a
Ruby
AdrianTuckwell/cinema
/models/ticket.rb
UTF-8
1,435
3.296875
3
[]
no_license
require_relative("../db/sql_runner") class Ticket attr_reader :id, :customer_id, :film_id def initialize( options ) @id = options['id'].to_i @customer_id = options['customer_id'].to_i @film_id = options['film_id'].to_i end # ----- Save Ticket ---------------------- def save() sql = "INSERT...
true
e684012ece3195d67855baacb5adf707c21d414c
Ruby
elliottwilliams/XcodeMove
/lib/xcmv.rb
UTF-8
2,237
2.71875
3
[]
no_license
# frozen_string_literal: true require 'xcodeproj' require_relative 'xcmv/file' require_relative 'xcmv/header_visibility' require_relative 'xcmv/group_membership' require_relative 'xcmv/project_cache' require_relative 'xcmv/version' # Moves files on disk and between Xcode projects. module XcodeMove class InputError ...
true
a9e6c4cc5a8027c3d83f78aee721e223782122bb
Ruby
blh0021/screen_driver
/lib/driver/mouse.rb
UTF-8
992
2.875
3
[]
no_license
module ScreenDriver class Mouse def mouse_move(x, y) mouse = Robot.new mouse.mouseMove(x, y) end def left_click(x, y) mouse = Robot.new mouse.mouseMove(x,y) mouse.mousePress(InputEvent::BUTTON1_MASK); mouse.mouseRelease(InputEvent::BUTTON1_MASK); #Java 7+ Only ...
true
3fb79fa9d38d672ad6ed06564780a69c5afae36c
Ruby
ivhq/thisdata-ruby
/test/this_data/event_test.rb
UTF-8
1,219
2.515625
3
[ "MIT" ]
permissive
require_relative "../test_helper.rb" class ThisData::EventTest < ThisData::UnitTest test "can get all events" do response = { total: 10, results: [ {id: "1", overall_score: 0.5, user: {id: 112233}}, {id: "2", overall_score: 0.1, user: {id: 445566}} ] } expected_path = U...
true
a60521e67d4ced1b37f81e57068af248ab9e3ea8
Ruby
marcusfgardiner/ruby-refresher
/lib/questions.rb
UTF-8
14,388
4.4375
4
[]
no_license
# keep only the elements that start with an a def select_elements_starting_with_a(array) array.select {|i| i[0] == "a"} end # keep only the elements that start with a vowel def select_elements_starting_with_vowel(array) array.select {|i| i[0] == "a" || i[0] =="e" || i[0] == "i" || i[0] == "o" || i[0] == "u"} ...
true
2cf71e73d42ddc842e6ccd6ccc8c888ffe3f463d
Ruby
Sproodigy/goods_cards
/training_ruby/books_on_ruby.rb
UTF-8
4,396
3.453125
3
[]
no_license
require 'active_support/all' require 'csv' # def name # while true # names = [] # print 'Name:' # response = gets # case response # when /^[a-zA-Z]/ # names << response # puts response # when /^[0-9]/, /^$/ # puts 'Jerk' # when /[q]/ # puts names # return tru...
true
6816d701b0e0b8c34e4d422c02cbcdd40258113d
Ruby
FernandaFranco/book-intro-programming
/loops_iterators/exercise_2.rb
UTF-8
124
3.171875
3
[]
no_license
question = "DO YOU LOVE ME? REALLY?? DO YOU???" answer = 0 while answer != "STOP" puts question answer = gets.chomp end
true
1b21e5fdf8787dc4d403847dddefbd8ae9dd3b4a
Ruby
Mikeermz/test_latam
/Finland.rb
UTF-8
239
2.75
3
[]
no_license
require_relative 'Sale.rb' class Finland < Sale def initialize(producto, precio, fecha, latitud, longitud, ciudad, tipo_pago, nombre) super(producto,precio,fecha,latitud,longitud,ciudad,tipo_pago,nombre) @pais = "Finland" end end
true
9d328067dae1c9b50c363416aeba751d8b8602a5
Ruby
firecracker/cloud_search
/spec/cloud_search/document_spec.rb
UTF-8
10,018
2.65625
3
[ "MIT" ]
permissive
# encoding: utf-8 require "spec_helper" describe CloudSearch::Document do it "has a 'id' attribute" do expect(described_class.new(:id => 123).id).to eq("123") end it "has a 'type' attribute" do expect(described_class.new(:type => "add").type).to eq("add") end it "has a 'version' attribute" do ...
true
b7c158cb3b73d9078c125c18ef97ca674609bd3f
Ruby
bilalnaeem/template-engine
/db/seeds.rb
UTF-8
631
2.625
3
[]
no_license
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
true
f02e472d7a43faa9615df45fe994d2b43547683f
Ruby
comfyguy/lessons
/tests/a.rb
UTF-8
122
3.328125
3
[]
no_license
class Animal attr_accessor :name def initialize self.name = 'Murzik' end end pet = Animal.new puts pet.name
true
91ab421de83f8dc90e81301d7e010b177161ba29
Ruby
googleapis/google-cloud-ruby
/google-cloud-pubsub/samples/pubsub_publish_custom_attributes.rb
UTF-8
1,314
2.546875
3
[ "Apache-2.0" ]
permissive
# Copyright 2023 Google, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, ...
true
777c186465d740ace8295b5d29a1d112ac13fb0f
Ruby
codesicario/Exercises-Launch-School
/sum_or_product_of_int.rb
UTF-8
547
4.25
4
[]
no_license
def product_or_sum puts "Please enter an integer greater than 0:" integer = gets.chomp.to_i puts "Enter 's' to compute the sum, 'p' to compute the product." user_input = gets.chomp if user_input == 's' sum = (1..integer).inject(:+) puts "The sum of the integers between 1 and #{integer} is: #{sum}" ...
true
a717af42fe85a1f37f0af4e344b75a9613f98be8
Ruby
camillavk/Rock-Paper-Scissors
/spec/game_spec.rb
UTF-8
487
2.546875
3
[]
no_license
require_relative '../app/game' describe Game do let (:game) {Game.new} let (:player) {double :player} let (:opponent) {double :opponent} let (:rock) {double :rock} it "should have five choices" do expect(game.choices).to be_kind_of(Array) end it "can add a player" do game.add_player(player) expect(gam...
true
43fc9f1fbea7522377fb4b25c5c22d21ab7211a4
Ruby
InnoZ/RubyCars
/app/models/runner.rb
UTF-8
758
2.890625
3
[]
no_license
class Runner include RubyCarsLog def initialize(scraper) @scraper = scraper end def run log_start scrape ensure log_finish end private attr_reader :scraper def scrape scraper.run rescue => e rescue_message(e) end def rescue_message(e) RubyCarsLog.logger.error([ ...
true
df192c5d2b9fc0552f462376d73a3da4dd5cb475
Ruby
djberg96/berger_spec
/test/core/Float/instance/test_floor.rb
UTF-8
1,529
3.328125
3
[ "LicenseRef-scancode-warranty-disclaimer", "Artistic-2.0" ]
permissive
###################################################################### # test_floor.rb # # Test case for the Float#floor instance method. ###################################################################### require 'test/helper' require 'test/unit' class Test_Float_Floor_InstanceMethod < Test::Unit::TestCase def s...
true
20a5e9555c53f8c7c63b54328aad8532a705a783
Ruby
johnlarkin1/ror-intro
/lesson2_assignment2/module2_lesson2_formative.rb
UTF-8
715
3.921875
4
[]
no_license
### This is the old sample code that I'll be working with # Grab 23 random elements between 0 and 10000 arr = (1..10000).to_a.sample(23) p arr # This selects only elements that when divided by 3 have a 0 remainder. p arr.select { |element| element % 3 == 0} # Write a single chain of command to find all numbers that...
true
1aaee53c4b77aab12fc2be18ddf621ee2487d71b
Ruby
BranLiang/assignment_rspec_viking
/spec/viking_spec.rb
UTF-8
4,667
3.15625
3
[]
no_license
# Your code here require 'viking.rb' require 'pry-byebug' describe Viking do let(:viking){ Viking.new } let(:oleg){ Viking.new("Oleg") } let(:bran){ Viking.new("Bran") } before do allow($stdout).to receive(:puts) end describe '#initialize' do it 'set up with a name' do new_viking = Viking.n...
true
b51a5cf1e78495633b6dd8ad92ae9aeed55e1a5e
Ruby
StevenACZ/ruby-basics-2-StevenACZ
/06caesar/caesar.rb
UTF-8
1,065
4.125
4
[]
no_license
# Ask the user for the key and plaintext # Create the ciphertext. You will need to iterate over each character of plaintext. # On each character check if is an alphabetic letter. If you have a list of the alphabetic letters # you cancheck if the character is included in that list. If not, it goes directly to the ciphe...
true
aae634da89bba53eb2087ec094b12b7511af5f37
Ruby
Luis846/Ruby-Practice
/student.rb
UTF-8
342
3.6875
4
[]
no_license
class Student attr_accessor :first_name, :last_name, :primary_phone_number def introduction(target) puts "Hi, #{target}, I'm #{first_name}" end def favorite_number 7 end end Luis = Student.new Luis.first_name = "Luis" Luis.last_name = "Rivera" puts "Luis's favorite number is #{L...
true
54690e4a196bf626baa7225e1c9cc41d527fe3a4
Ruby
ruby-rdf/spira
/spec/rdf_types_spec.rb
UTF-8
5,121
2.625
3
[ "Unlicense", "LicenseRef-scancode-public-domain" ]
permissive
require "spec_helper" # These classes are to test finding based on RDF::RDFS.type class Cars < RDF::Vocabulary('http://example.org/cars/') property :car property :van property :car1 property :van property :station_wagon property :unrelated_type end describe 'models with a defined rdf type' do subject {...
true
65de148c04f4395379c2f1745d14ff6aecbec6d0
Ruby
adrianpike/paranoia
/paranoia.rb
UTF-8
2,062
2.890625
3
[]
no_license
require 'formatador' require 'openssl' require 'ostruct' class ParseError < StandardError; end class Cert < OpenStruct def self.initialize_from_string(string) name = nil; sig = nil string.each_line do |line| if line.match(/"alis"<.+>=(?:0x[0-9A-F]+\W+)?"(.*)"$/) then name = $1 end ...
true
8a900c7dd66ddac0076d1a73491ab6b82fa3c7ce
Ruby
demileee/roll-of-the-die
/permutations.rb
UTF-8
132
3.296875
3
[]
no_license
dice = [1, 2, 3, 4, 5, 6] dice2 = [1, 2, 3, 4, 5, 6] dice.each do |die| dice2.each do |die2| puts "#{die} #{die2}" end end
true
16e38c14ff9b2c182aaef4c9f6790f33d6742173
Ruby
eclipse2ant/e_keisan
/lib/unit.rb
UTF-8
1,388
3.171875
3
[]
no_license
#!/usr/local/jruby/bin/jruby # encoding: utf-8 ############################################################################# ### 単位の編集(@@u2fの編集)は、unit_file.rb で行ってください ############## ############################################################################# require 'apath' require 'unit_file' class Unit incl...
true
2745ca3ece7c4dcd846d1028d90e3ae4fa2aafd6
Ruby
tdd/tweep
/lib/tweep/account.rb
UTF-8
1,491
2.640625
3
[ "MIT-0", "MIT" ]
permissive
#! /usr/bin/env ruby # encoding: utf-8 # # (c) 2011 Christophe Porteneuve require 'tweep/config' require 'rubygems' require 'twitter' module Tweep class Account @@registry = {} def self.each(&block) @@registry.values.each(&block) end def self.find(nick) @@registry[nick] end ...
true
519e017a62e9d2abd07b847363d08f2b5a3e8b2f
Ruby
Harxy/battleships
/lib/board.rb
UTF-8
137
2.921875
3
[]
no_license
class Board attr_accessor :board def initialize @board = [] end def boat_location boat, x, y board << boat end end
true
1de744e076a76cc3ab8150d903ba69b51a6ef5cf
Ruby
samiylo/job
/lib/job_posting/scraper.rb
UTF-8
3,632
3.046875
3
[]
no_license
class JobObjects class Job @@all = [] attr_accessor :name, :company, :location, :url def initialize(name, company, location = nil, url) @name = name @company = company @location = location @url = url @@all << self ...
true
58451b4fc082dcb6452b43b029b8eebdb82b20dc
Ruby
afiore/extraloop
/lib/extraloop/extractor_base.rb
UTF-8
1,396
2.984375
3
[]
no_license
module ExtraLoop # Pseudo Abstract class from which all extractors inherit. # This should not be called directly # class ExtractorBase module Exceptions class WrongArgumentError < StandardError; end class ExtractorParseError < StandardError; end end attr_reader :field_name # # ...
true
34eaf401e22ab81e9861f6bced815be49849fb2a
Ruby
hkumar1993/coding_assessments
/2017_12_16/spec/between_two_sets_spec.rb
UTF-8
792
3.125
3
[]
no_license
require 'between_two_sets' describe 'lcm' do it 'returns the lowest common multiple' do expect(lcm([2,4])).to eq(4) expect(lcm([5,6])).to eq(30) expect(lcm([3,6,9])).to eq(18) end end describe 'gcf' do it 'returns the greatest common factor' do expect(gcf([2,4])).to eq(2) ...
true
551fd72512cbba2356298979df9b833b35dcc744
Ruby
zfvit/learning_ruby
/OO/methods.rb
UTF-8
1,178
3.890625
4
[]
no_license
class Methods $global = 1234 @instanceName = "Instance field!!!" @@class_field = "Like a static field" attr_accessor :instanceName def initialize(arg) @instanceName = arg @instanceName.capitalize! #changeInstanceName!("changed") $global = 5678 ...
true
23d2f4c1e9c53597efaba989f2fd41d277a3d857
Ruby
unhcr/axis
/app/models/population.rb
UTF-8
1,065
2.59375
3
[]
no_license
class Population < ActiveRecord::Base attr_accessible :ppg_code, :value, :year, :element_id, :element_type, :ppg_id def self.models_optimized(ids = {}, limit = nil, where = nil, offset = nil) conditions = '' conditions = "element_id IN ('#{ids.values.flatten.join("','")}')" if ids sql = "select array...
true
4bafdb37e00282c0e8fb13aeefd6f02a617386c9
Ruby
jasonlong/geo_pattern
/lib/geo_pattern/structure_generators/octagons_generator.rb
UTF-8
1,126
2.671875
3
[ "MIT" ]
permissive
# frozen_string_literal: true module GeoPattern module StructureGenerators class OctagonsGenerator < BaseGenerator private attr_reader :square_size, :tile def after_initialize @square_size = map(hex_val(0, 1), 0, 15, 10, 60) @tile = build_octogon_shape(square_size) se...
true
36282079abb348ebe593868c649d63e2d090688c
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/hamming/6cb42db4546e4fdfa7d36aa7c9c79e9f.rb
UTF-8
485
3.640625
4
[]
no_license
class Hamming def self.compute(strand1, strand2) distance = 0 strandA = strand_to_array(strand1) strandB = strand_to_array(strand2) size = use_shorter_strand(strandA, strandB) strandA.take(size).each_with_index { |char, index| distance += 1 if char != strandB[index] } distance ...
true
554063a368810cbc45ce5264dbf16f8eca223ea8
Ruby
LilyMarcela/Ruby-excercises
/testruby.rb
UTF-8
238
4
4
[]
no_license
def fizz_buzz (num) if num % 3==0 && num % 5 == 0 puts "fizz_buzz" elsif num % 3 == 0 puts "fizz" elsif num % 5 == 0 puts "buzz" else puts "#{num}" end end fizz_buzz(3) fizz_buzz(5) fizz_buzz(15) fizz_buzz(20)
true
a7231861ed5f05b640f4b63832e86aa1cbaab255
Ruby
Nanosim-LIG/boast
/lib/BOAST/Language/HighLevelOperators.rb
UTF-8
4,861
2.703125
3
[ "BSD-2-Clause" ]
permissive
module BOAST class HighLevelOperator < Operator include Intrinsics include Arithmetic include Inspectable end class Sqrt < HighLevelOperator extend Functor attr_reader :operand attr_reader :return_type def initialize(a) @operand = a @return_type = a.to_var unless ...
true
939651b8261a1a52e9ef249a4c35573e700f9ed9
Ruby
fstovarr/UNaTHESIS_IS2
/app/controllers/file_controller.rb
UTF-8
2,266
2.5625
3
[]
no_license
require 'digest/md5' require 'fileutils' require 'json' # FileController class FileController < ApplicationController skip_before_action :verify_authenticity_token def initialize super User.user_type_ids.slice 'student' end def load_post file_name = Time.now.strftime('%Y%m%d_%H%M%S') + '.pdf' th...
true
138a490bbba1a1358f42b9220d6e1ec2d7937cae
Ruby
nielspetersen/smar_T
/lib/algorithm/tour_generation.rb
UTF-8
2,970
2.9375
3
[]
no_license
require 'algorithm/variants/savingsplusplus' require 'algorithm/variants/mthreetp' module Algorithm class TourGeneration def self.generate_tours(company, order_type_filter = {}) # clear all tours with status equal to generated Tour.where(status: StatusEnum::GENERATED).destroy_all orders, dri...
true
7d67bafe86d25c839b1dfd0b3698644fb6af92c0
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/robot-name/21476d679fe44df0b94680825506504b.rb
UTF-8
387
3.296875
3
[]
no_license
class Robot attr_accessor :name def initialize self.name = Robot.create_new_name end def reset self.name = Robot.create_new_name end private def self.create_new_name letter = possible_letters.sample(2).join digits = "%03d" % rand(1000) return letter + digits end def self.poss...
true
157987d17e4cff1ff1453a707ba265f3ad9cc702
Ruby
dylanconnolly/messenger_api
/app/models/conversation.rb
UTF-8
1,280
2.71875
3
[]
no_license
class Conversation < ApplicationRecord has_many :user_conversations has_many :users, through: :user_conversations has_many :messages validates_length_of :users, maximum: 2 def self.find_or_create_conversation(sender, recipient) response = find_conversation(sender.id, recipient...
true
766179fb9948ec1a930de61f6e349c57bec94a47
Ruby
syundo0730/deresta-cnn
/src/downloader/note_image_downloader.rb
UTF-8
1,893
2.90625
3
[]
no_license
require 'cgi' require 'json' page_source = open("../../data/scraped_data/index.html", &:read) class NoteImageDownloader def getImageData(page_source) list_data = page_source.scan(%r!<tr class=\"type-(.+?)\">.*?<td>(.+?)</td><td.*?>(.*?)</td><td.*?><a href=\"(.+?)".*?>.*?</a></td><td.*?><a href=\"(.+?)\".*?>.*?...
true
435192232a55164e408ec3131f63c45c36762b32
Ruby
elersong/light-blogger
/app/controllers/articles_controller.rb
UTF-8
3,294
2.921875
3
[]
no_license
class ArticlesController < ApplicationController include ArticlesHelper before_filter :require_login, only: [:new, :create, :edit, :update, :destroy] def index # We're going to need the @articles var to hold an array of all articles because the index # page is simply a listing of all the instances of t...
true
c5b0b120cdf57bdf351e836b94c444dc37fb263a
Ruby
cwhwang1986/Algorithm
/Easy/ugly_number.rb
UTF-8
732
4.40625
4
[]
no_license
=begin Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is typically treated as an ugly number. 6 = 2 * 3 8 = 2 * 2 * 2 ...
true
2826dacf3edfdf93b978bef20e592f81f4d7cef9
Ruby
ben-biddington/rsettings
/lib/rsettings/core/setting.rb
UTF-8
315
3.296875
3
[ "MIT" ]
permissive
class Setting def truthy?; @truthy; end def initialize(text="") @text = text @truthy = (text||"").downcase.match /(yes|no|on|off)/ end def missing?; @text.nil?; end def to_s; @text.to_s; end def true? match = (@text||"").downcase.match(/(yes|on)/) false == match.nil? end end
true
7ce1cce7524d0eb2dfc23ce2df057dafa4e9533b
Ruby
cielavenir/paiza_solutions
/learning/speedrun190424/d4.rb
UTF-8
109
2.75
3
[]
no_license
#!/usr/bin/ruby gets;puts$<.map{|e| {'forward'=>'Sunny','reverse'=>'Rainy','sideways'=>'Cloudy'}[e.chomp] }
true
c3a93d81e04c2dcaf1b754cb538dc7f606a188b1
Ruby
jaywilburn/tickets
/lib/json_web_token.rb
UTF-8
461
2.59375
3
[]
no_license
require 'json_web_token_decoded' class JsonWebToken def self.encode(payload) JWT.encode(payload, Rails.application.secrets.secret_key_base) end def self.decode(token) payload = JWT.decode(token, Rails.application.secrets.secret_key_base, nil)[0] JsonWebTokenDecoded.new(payload) rescue nil # It ...
true
f50f8dd075a83bff5c7f6bcd1e2e6eaced9f4c6e
Ruby
mwynholds/challenges
/euler/Level2/problem64.rb
UTF-8
1,409
3.1875
3
[]
no_license
require '../helper' require '../continued_fraction' require 'bigdecimal' class Problem64 def initialize end def first(n) a = Math.sqrt(n).floor b = 1 c = a [ a, b, c ] end def rest(n, b, c) x = b y = c z = n - c**2 b1 = z / x a1 = 0 c1 = y loop do a1 += 1 ...
true
9e45b49fa476e974dbf4f0b3004eb2c00a829ef8
Ruby
alf-tool/alf-core
/lib/alf/adapter.rb
UTF-8
3,355
3.015625
3
[ "MIT" ]
permissive
module Alf class Adapter class << self include Support::Registry # Register an adapter class under a specific name. # # Registered class must implement a recognizes? method that takes an array of # arguments; it must returns true if an adapter instance can be built using those ...
true
658610f1e093762036d3705109f61c19f8b48885
Ruby
AndresgilMVP/Practica-de-archivos
/exercise4.rb
UTF-8
584
2.953125
3
[]
no_license
# #Copia el contendio de file_to_copy.txt en un nuevo archivo que se llame notes.txt # (Es probable que este archivo aun no exista en tu directorio). # No se debe alterar el contenido original de file_to_copy.txt # y ten mucho cuidado de cerrar correctamente ambos archivos. archivo_original = "file_to_copy.txt" archi...
true
94fe6d0d5d2c94ea1b7ead3c0d196994317797cd
Ruby
kreyes12/ruby-objects-has-many-lab-london-web-071618
/lib/artist.rb
UTF-8
424
3.375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Artist attr_accessor :name, :songs @@all = [] def initialize(name=nil) @songs = [] @name = name end def self.all @@all end def add_song(new_song) new_song.artist = self @songs << new_song end def add_song_by_name(name) song = Song.new(name) song.art...
true
2c05a908207fc58864c6749e0b8175be77f7e8e2
Ruby
hrigu/rails_3_1_sandbox
/spec/lib/mastermind/master/evaluator_spec.rb
UTF-8
2,520
2.921875
3
[]
no_license
require "spec_helper" require File.expand_path(Rails.root) + '/lib/mastermind/master/computer_master' describe "Evaluator can evaluate guesses" do context "The code has four different colors" do before(:all) do @code = :r, :b, :g, :y @evaluator = Evaluator.new end context "and the guess is ...
true
efcaf24c3372d69f21889bca68e39ee361adfee8
Ruby
danbriechle/Enigma
/lib/key.rb
UTF-8
254
2.96875
3
[]
no_license
require 'SecureRandom' require 'pry' class Key attr_reader :first_shift def initialize @first_shift = number_generator end def number_generator number = SecureRandom.random_number(99999).to_s.ljust(5, "0").to_i number end end
true
f54d507f6a296332ff85711a131ad656ecc93f03
Ruby
seejee/sqlite-pure-ruby
/lib/pure-sqlite/database_record.rb
UTF-8
965
3.140625
3
[]
no_license
module PureSQLite class DatabaseRecord attr_reader :entries def initialize(stream) @header_index = Structures::VariableLengthInteger.new(stream) @entries = read_entries(stream) end def header_index_length @header_index.length end def total_header_bytes @heade...
true
670e886103663c2d5a1e0880b28ca9464a19162f
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/hamming/5939903581e04a07ac6dffe6374e7a9c.rb
UTF-8
109
3.25
3
[]
no_license
class Hamming def self.compute(a, b) a.split("").zip(b.split "").count { |x| x[0] != x[1] } end end
true
746cf0cbdfafa4f564a4b2d305d20877ed67b032
Ruby
filip373/design-patterns
/09_decorator/documents_app.rb
UTF-8
696
2.953125
3
[]
no_license
require_relative "./plaintext_document" require_relative "./encrypted_document" require_relative "./compressed_document" require_relative "./notified_document" puts("Writing a plaintext document...") plaintext_doc = PlaintextDocument.new("my_book.txt") plaintext_doc.write("First chapter") puts("Compressing the docume...
true
32a0be829b3620391dce24602e41a29f9d7b817f
Ruby
remiodufuye/programming-univbasics-nds-nested-arrays-iteration-lab-dc-web-102819
/lib/iteration.rb
UTF-8
1,482
3.78125
4
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
def join_ingredients(src) # Given an Array of 2-element Arrays ( [ [food1, food2], [food3, # food4]....[foodN, foodM]]): # # Build a new Array that contains strings where each pair of foods is # inserted into this template: # # "I love (inner array element 0) and (inner array element 1) on my pizza"" ...
true
31e9128c92166efa92ac7b837e779661403db562
Ruby
peterneely/e2e-sample
/features/step_definitions/#XSELL04_Quantity_steps.rb
UTF-8
2,738
2.609375
3
[]
no_license
Given(/^an online customer added a product to their shopping bag$/) do pending end Then(/^they should be able to increment the quantity by (\d+) with each click$/) do |arg| pending end And(/^the quantity in the shopping bag summary should increment with each click$/) do pending end And(/^the price in the produ...
true
3f58797eaee1e10c3bf1b45aa8058582dc7b4bff
Ruby
great084/draque_like
/character.rb
UTF-8
454
3.796875
4
[]
no_license
class Character attr_reader :name, :offense, :defense attr_accessor :hp def initialize(name:, hp:, offense:, defense:) @name = name @hp = hp @offense = offense @defense = defense end def attack(opponent) puts "#{@name}の攻撃!!" damage = @offense - opponent.defense / 2 puts "#{oppone...
true
8cdfe54d7c18c5b063f36805051f8f9b97f395bf
Ruby
mgoldfi1/oo-banking-v-000
/lib/transfer.rb
UTF-8
760
3.3125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require 'pry' class Transfer attr_reader :sender, :receiver attr_accessor :status, :amount def initialize(sender,receiver,amount) @sender = sender @receiver = receiver @amount = amount @status = "pending" end def valid? sender.valid? && receiver.valid? end def execute_transaction if self.valid? == false |...
true
f7f3745866d54ecb768f7e2009d9cdde1ed1948c
Ruby
Rhoxio/RPG
/Game/Testing/class_testing.rb
UTF-8
103
2.921875
3
[]
no_license
class Person class << Person def species "Homo Sapien" end end end p Person.species
true
e1d1f83cbf3aa8b083c9ef169aa0a39ae7d501f1
Ruby
Mew-Traveler/Time_Traveler
/lib/Time_Traveler/rentInfo.rb
UTF-8
1,232
2.625
3
[ "MIT" ]
permissive
require_relative 'airbnb_api' module Airbnb class RentInfo attr_reader :location attr_reader :infos def initialize(rooms,info) @infos = rooms.map { |item| rooms = room(item) } # searchVal(info) end def infos @infos end def self.find(location:) @sea...
true
feda04eb6bb896bbd6e68f897e2a7a5bb8656b36
Ruby
Hilbert-lang/dydx
/lib/dydx/function.rb
UTF-8
624
2.890625
3
[ "MIT" ]
permissive
module Dydx class Function attr_accessor :algebra, :vars def initialize(*vars) @vars = vars end def <=(algebra) @algebra = algebra self end def evalue(nums) subst_hash = Hash[*[@vars, nums].transpose.flatten] begin @algebra.subst(subst_hash).to_f r...
true
cf49ce2a8f44f37ef81a8094bdcf99b8c0833006
Ruby
jwilkins/coderay
/etc/check-diffs.rb
UTF-8
484
2.5625
3
[ "MIT" ]
permissive
DIFF_PART = / ^ ([\d,]+c[\d,]+) \n # change ( (?: < .* \n )+ ) # old ---\n ( (?: > .* \n )+ ) # new /x class String def undiff! gsub!(/^./, '') end end for diff in Dir['*.debug.diff'] puts diff diff = File.read diff diff.scan(/#{DIFF_PART}|(.+)/o) do |change, old, new, error| raise error if error ...
true
11d98d602d3f14c7fc3b84ef3c0a134733691829
Ruby
KerryAlsace/ruby-challenges
/case.rb
UTF-8
229
3.078125
3
[]
no_license
weather='cold' case weather when 'sunny' puts "Wear sunblock!" when 'rainy' puts "Bring an umbrella!" when 'cold' puts "Wear a jacket!" when 'snowy' puts "Wear snow shoes!" else puts "Take a gamble, wear whatever you want!" end
true
e128ab2074311c70dfa58c2161ac4e3f9437aba5
Ruby
amkhrjee/mb-geometry
/lib/mb/geometry.rb
UTF-8
9,720
3.53125
4
[ "BSD-2-Clause" ]
permissive
require 'matrix' require 'mb-math' require 'mb-util' require_relative 'geometry/version' module MB # Inefficient algorithms for some basic geometric operations. module Geometry class << self # Finds the line intersection, if any, between two lines given coordinates # in the form used by rubyvor (...
true
d62d0bac934e54894365d7250b08faed3a3cc0d5
Ruby
am-kantox/see_as_vee
/lib/see_as_vee/producers/hashes.rb
UTF-8
3,180
2.75
3
[ "MIT" ]
permissive
module SeeAsVee module Producers class Hashes INTERNAL_PARAMS = %i|ungroup delimiter|.freeze NORMALIZER = ->(symbol, hash) { hash.map { |k, v| [k.public_send(symbol ? :to_sym : :to_s), v] }.to_h }.freeze HUMANIZER = lambda do |hash| hash.map do |k, v| [k.respond_to?(:humanize) ...
true
07ba9b19755c6d834410daf74d6ae882fc7d2bbc
Ruby
nkoehring/towerdefence
/classes/game.rb
UTF-8
6,183
3.125
3
[ "ISC" ]
permissive
module TowerDefence class Game include EventHandler::HasEventHandler include TowerDefence def initialize() Configuration.setup make_screen make_clock make_event_hooks # basics Grid.setup @screen.size @grid_highlighter = Grid::GridHighlighter.new @the_path ...
true
af5e96a234ec0dca1c067fddb45a609d23401326
Ruby
J-Y/RubyQuiz
/ruby_quiz/quiz109_sols/solutions/Mark Harris/number_spiral.rb
UTF-8
1,128
3.71875
4
[ "MIT" ]
permissive
class NumberSpiral include Enumerable def initialize(dimension) @n = dimension @even = dimension % 2 @maxSize = (@n**2 - 1).to_s.length end def each @line=0 (0..@n-1).map { yield nextLine } @line=0 end private def nextLine result = spiral(@n, @line) @line+=1 resul...
true
b7a8195875dda42e18bc68e6430874b832fde8ea
Ruby
laithshadeed/hacker-rank
/zombie-cluster/s.rb
UTF-8
1,128
3.296875
3
[]
no_license
#!/usr/bin/env ruby def search_dfs_recursive(z, visited, i) for j in 0..z.length-1 unless visited[j] visited[i] = true search_dfs_recursive(z, visited, j) if z[i][j] == 1 end end end def search_dfs_iterative(z, visited, i) stack = [i] while !stack.empty? j = stack.pop unless visite...
true
b2fea5098d2dd7c57cbb13193a9e842deea49dfb
Ruby
larskanis/pkcs11
/lib/pkcs11/session.rb
UTF-8
30,330
2.953125
3
[ "MIT" ]
permissive
require 'pkcs11/helper' module PKCS11 # Cryptoki requires that an application open one or more sessions with a token to gain # access to the token's objects and functions. A session provides a logical connection # between the application and the token. A session can be a read/write (R/W) session or a # read-on...
true
725162cce40ce02d7123f227ab88248cb7cd3d61
Ruby
eilw/Makers-wkend-challenges
/wk1-airport-challenge/lib/weather.rb
UTF-8
111
2.59375
3
[]
no_license
class Weather STORM_PERCENTAGE = 15 def stormy? true if rand(1..100) <= STORM_PERCENTAGE end end
true
94d05a985907aebd1ae72af162689e734ec6c822
Ruby
YuukiMAEDA/AtCoder
/Ruby/ABC/A/9x9.rb
UTF-8
54
2.75
3
[]
no_license
a,b=gets.split.map(&:to_i) puts a<10 && b<10 ? a*b:-1
true
84156836796193d524343ca00da10b2cac08bb1e
Ruby
azhou31/Ruby-Fundamentals-OOP
/exercise.rb
UTF-8
625
4.28125
4
[]
no_license
a = ["Matz","Guido","Dojo","Choi","John"] b = [5,6,9,3,1,2,4,7,8,10] puts a[0] puts a[1] puts b.class puts b.shuffle.join("-") puts a.to_s puts a.shuffle puts a.fetch(2) #returns "Dojo" puts b.delete(4) #deletes 4 puts b.delete_at(4) #deletes 1 puts a.reverse # ["John,"Choi","Dojo","Guido","Matz"] puts a.lengt...
true
898b5548d2f5daa07c47a1b19d8237c9704a5a4e
Ruby
gambaroff/ruby_sandbox
/code_challenges/top_three_words.rb
UTF-8
837
3.75
4
[ "Apache-2.0" ]
permissive
text = "Count Lev Nikolayevich Tolstoy, also known as Leo Tolstoy, was a Russian writer who primarily wrote novels and short stories. Tolstoy was a master of realistic fiction and is widely considered one of the world's greatest novelists." #My solution. def top_3_words(text) words_to_string = text.downcase.scan(...
true
4839f93ceebc9948a987357bf15d3e0847799a07
Ruby
snikch/vending-machine
/lib/vend/resource_collection.rb
UTF-8
2,000
2.640625
3
[ "MIT" ]
permissive
module Vend class ResourceCollection attr_accessor :parameters, :store include Vend::Finders include Enumerable def initialize(store, klass, records = nil) @store = store @klass = klass @records = records end ## # Check for a collection method # defined on the reso...
true
2fa487be82b192a48ec7bffe8020d63e1ff7fdb7
Ruby
akoltun/tree_struct
/lib/tree_struct/array.rb
UTF-8
260
2.640625
3
[ "MIT" ]
permissive
require 'typed_array' class TreeStruct class Array < TypedArray def create self << (item = create_item) item end def to_hash self.map(&:to_hash) end private def create_item item_class.new end end end
true
ccdb3765538aa67b173f62b6faed5f3e9cd164c1
Ruby
noam-io/host
/lib/noam_server/ear.rb
UTF-8
1,701
2.59375
3
[ "BSD-3-Clause" ]
permissive
#Copyright (c) 2014, IDEO require 'em/pure_ruby' require 'noam/messages' module NoamServer module EarHandler attr_accessor :callback_delegate def unbind callback_delegate.terminate end end class Ear attr_accessor :host, :port, :incoming_connection def initialize(host, port, incomin...
true
97afb03bbeff5281b6b60e9b8489e4450a778df2
Ruby
FergusLemon/battle
/lib/game.rb
UTF-8
883
3.578125
4
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
class Game attr_reader :attacker, :defender @@games = [] def initialize(player_1 = Player.new, player_2 = Player.new) @players = [player_1, player_2] @attacker = @players.first @defender = @players.last @winner = nil @@games << self end def self.games @@games.dup end def players...
true
f84b3a857df347acd7912278b38a535940a3ebcc
Ruby
NQuinn27/AdventOfCode
/Day5/day5_p2.rb
UTF-8
458
3.5625
4
[]
no_license
def has_repeats(s) for i in 0..s.length-2 pair = s[i,2] remaining = s[i+2..-1] if remaining.include? pair then return true; end end return false end def has_repeats_with_gap(s) for i in 0..s.length-2 if s[i] == s[i+2] return true end end return false end count = 0 File.r...
true
8a0704eaf8b61d2a3cec772427b63f7a76c1c98f
Ruby
beck03076/happy_shop
/app/values/money_formatter.rb
UTF-8
573
3.40625
3
[]
no_license
# value object for formatting money class MoneyFormatter # new object # # @param money [Money] def initialize(money) @money = money.to_money end # formats to a string # # @return [String] def format "#{amount} #{currency}" end # to get the currency object of money # # @return [Money:...
true
c6e30d991e08057295ce3135d6573a4a1c0ad4cc
Ruby
SquiggerJJohnson/cursebot
/curse.rb
UTF-8
630
2.703125
3
[]
no_license
require 'cinch' require 'obscenity' curse_words = Psych.load_file(Obscenity::Config.new.blacklist) bot = Cinch::Bot.new do configure do |c| c.server = "irc.rizon.net" c.channels = ["#8chan"] c.nick = "CurseBot" c.user = "CurseBot" c.realname = "CurseBot" end on :message, /.+/ do |m| ...
true
7f7e74bff8a89e3f760a2b7140521cdd443d71ab
Ruby
ilyadzyuba/mendeleev
/mendeleev.rb
UTF-8
502
3.578125
4
[]
no_license
require 'json' file = File.read('elements.json') data_hash = JSON.parse(file) puts "У нас всего элементов: #{data_hash.keys.size}" puts data_hash.keys puts "О каком элементе хотите узнать?" element = gets.chomp if data_hash.has_key?(element) puts "Первооткрывателем этого элемента считается: #{data_hash[element]}" ...
true
3d04f25089c9fa755ca425218607718e46e7b170
Ruby
mettledrum/gPhone
/g_phone.rb
UTF-8
2,063
2.625
3
[]
no_license
require 'sinatra' require 'rubygems' require 'twilio-ruby' require 'httparty' require 'active_support' require 'active_support/core_ext' get '/' do @@body = params[:Body] redirect to('/g_weather') end get '/g_weather' do # google geocoordinates API weather_search = @@body.gsub(" ", "+") google_api_response ...
true
3d90b35e2d0d3e5171acadbc31b2584cd549428f
Ruby
epistrephein/italiansubs
/lib/italiansubs.rb
UTF-8
4,980
2.546875
3
[ "MIT" ]
permissive
require 'faraday' require 'faraday_middleware' require 'json' module ItalianSubs VERSION = '0.1.1'.freeze API_KEY = '6f53c6a55288ff82591c881eda98cd8f'.freeze API_BASEURL = 'https://api.italiansubs.net/api/rest'.freeze USER_AGENT = 'italiansubs-rubygem'.freeze class RequestError < StandardError; end class ...
true
1ccb5ca69d0c4acfb80cfbbaee6e2d6c04e3050c
Ruby
jjarre10/homework4
/spec/movies_controller_spec.rb
UTF-8
3,750
2.765625
3
[]
no_license
require 'spec_helper' describe MoviesController, :type => :controller do describe 'edit page for appropriate Movie' do it 'When I go to the edit page for the Movie, it should be loaded' do movie = mock('Movie') Movie.should_receive(:find).with('1').and_return(mock) get :edit, {:id => '1'} ...
true
aa8b7953a13082f44806fc5c17919d3ed82ab855
Ruby
arvicco/win_gui
/spec/win_gui/convenience_spec.rb
UTF-8
2,231
2.59375
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
require "spec_helper.rb" describe WinGui, 'Convenience methods' do before(:each) { @win = launch_test_app.main_window } after(:each) { close_test_app } describe '#dialog' do it 'returns top-level dialog window with given title if no block attached' do with_dialog(:save) do dialog_window = dial...
true
f9fd37200ac0ae0bf4be4726b7533fd13a865df1
Ruby
mobius-network/mobius-client-ruby
/lib/mobius/client/blockchain/key_pair_factory.rb
UTF-8
1,453
3
3
[ "MIT" ]
permissive
# Transforms given value into Stellar::Keypair object. module Mobius::Client::Blockchain::KeyPairFactory class << self # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity # Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut. # @param subject [String||Stell...
true
ee328b22847428f0269196bcac2c1c83ca50ba5f
Ruby
briecoyle/sinatra-cool-store-2
/app/models/cart.rb
UTF-8
155
2.578125
3
[]
no_license
class Cart < ActiveRecord::Base belongs_to :user has_many :items def total self.items.inject(0) { |total, item| total += item.price } end end
true
32c9538108c55ed90b451ba489bd53bc9a8782ca
Ruby
leehopper/black_thursday
/spec/invoice_repository_spec.rb
UTF-8
3,854
2.53125
3
[]
no_license
require_relative 'spec_helper' require_relative '../lib/invoice_repository' RSpec.describe InvoiceRepository do before :each do @repo = InvoiceRepository.new('./spec/fixtures/mock_invoices.csv') end it 'exists' do expect(@repo).to be_an_instance_of(InvoiceRepository) end it 'can create invoice inst...
true
924084ce9d98ae9f5b91fb96e86fd906d3ab7027
Ruby
FrancescaRodricks/fractions
/fraction_spec.rb
UTF-8
1,250
3.3125
3
[]
no_license
# Author : Francesca Rodricks # Date Created: 24/09/2017 # Date Modified: 26/09/2017 # Problem Statement: Adding fractions/rational numbers # Fraction Class Spec require 'rspec' require_relative "#{__dir__}/fraction" RSpec.describe Fraction, type: :class do # 1/2 3/4 5/6 7/8 # add fraction to an integer # add ...
true
18d9a73d11aeca6b9fd49c2743e53c915209a00f
Ruby
SathishAchilles/ParkingLot
/lib/parking_lot.rb
UTF-8
1,013
3.171875
3
[]
no_license
require_relative 'parking_slot' #Implements the parking lot class ParkingLot def initialize @slots = [] end def slots @slots end def slots=(no_of_slots) begin no_of_slots = no_of_slots.to_i raise ArgumentError unless no_of_slots.is_a?(Integer) (ParkingLayout::ENTRY_POINT...no_o...
true
2677ab865d59332296c71e1163a20af7fb252085
Ruby
psychedel/qwester
/lib/random_string.rb
UTF-8
544
3.140625
3
[ "MIT" ]
permissive
class RandomString < String def initialize(length = 40) super(new_random_string(length)) end private def new_random_string(length = 40) string = "" string += random_string until string.length >= length return string[0, length] end def random_string string_pairs = Digest::SHA1.hexdiges...
true
35a7cb412cac00d9e9c1ed1c9091702e00459884
Ruby
badal/jacman-selectors
/lib/jacman/selectors/table.rb
UTF-8
1,544
2.6875
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
#!/usr/bin/env ruby # encoding: utf-8 # File: table.rb # Created: 11/12/2015 # # (c) Michel Demazure <michel@demazure.com> module JacintheManagement module Selectors # specific class for Qt widget class Table # @param [Array<String>] list answer from MySQL # @return [Table] new instance de...
true
cc3fb78b8482619b0054a8bf13fcb83a9f8f663b
Ruby
JasonTavarez/ruby-puppy-nyc-web-091619
/lib/dog.rb
UTF-8
590
3.734375
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require 'pry' class Dog # attr_reader :name attr_accessor :name @@all = [] def initialize(name) @name = name save end def self.all @@all end def self.clear_all #clear array @@all of all Dog instances @@all.clear end def self.prin...
true
06a445103df7de9ec7dba1128de3b6c48a7dbac5
Ruby
franlocus/knight_travails.rb
/main.rb
UTF-8
463
4
4
[]
no_license
# frozen_string_literal: true require_relative 'knight' require_relative 'board' board = Board.new puts board.knight_moves([0,0],[3,3]) puts board.knight_moves([0,0],[1,2]) puts board.knight_moves([0,0],[7,7]) # You made it in 2 moves! Here's your path: # [0, 0] # [1, 2] # [3, 3] # You made it in 1 moves! H...
true
9a3641466c5551cffb1269728753e695dbb7ef75
Ruby
Hykios42/THP_Scrapping_d09
/lib/crypto_currencies.rb
UTF-8
442
2.984375
3
[]
no_license
require 'rubygems' require 'nokogiri' require 'open-uri' def crypto_scrapper page = Nokogiri::HTML(open("https://coinmarketcap.com/all/views/all/")) currencies = [] page.xpath('//span//a').each do |crypto| currencies << crypto.text end values = [] page.xpath('//a[@class="price"]...
true
a780286162f4c609cdc73f8901582852723856e6
Ruby
krlawrence/SVG
/generators/slope.rb
UTF-8
88
2.8125
3
[ "Apache-2.0" ]
permissive
45.step(89,1) do |a| puts "Angle=#{a} , Slope=#{Math.tan( a*Math::PI / 180 )}" end
true
3c7d9b15dc95280e58e628a4a06f9d5d59996e34
Ruby
usuyama/sam_simulator
/read.rb
UTF-8
961
3.125
3
[]
no_license
# -*- coding: utf-8 -*- class Read attr_accessor :seq, :base_qualities, :cigar, :pos, :chr def initialize(seq, quality, cigar, pos, chr) @seq = seq @base_qualities = quality @cigar = cigar @pos = pos @chr = chr end def inspect "#{@pos}, cigar: #{@cigar}\n#{@seq}\n#{@base_qualities}" ...
true
4b575334d0bf723d273aa020047ce8ab7de5e8a4
Ruby
Deimos620/octopus
/app/models/blog_author.rb
UTF-8
759
2.609375
3
[]
no_license
class BlogAuthor < ActiveRecord::Base extend FriendlyId friendly_id :slug, use: :slugged has_many :blog_posts belongs_to :user before_save { self.first_name = first_name.capitalize if self.first_name? } before_save { self.last_name = last_name.capitalize if self.last_name?} validates :slug, unique...
true