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
ef0224617294e21a8e06b2a4080aa870397e5e8f
Ruby
ippachi/test-driven-development
/money/pair.rb
UTF-8
417
3.34375
3
[]
no_license
module Money class Pair # @param from [String] # @param to [String] def initialize(from, to) @from = from @to = to end # @param other [Pair] def eql?(other) @from == other.from && @to == other.to end # @return [Integer] def hash 0 end protected ...
true
7c9179ec2fc3322a878b96f31b74270a7662207d
Ruby
jjromeo/online-marketplace
/lib/product.rb
UTF-8
520
3.046875
3
[]
no_license
# Contains information for each product class Product ATTRS = [:code, :name, :price] def initialize(attributes = {}) initialize_attrs(attributes) validate_attrs end private def initialize_attrs(attributes) ATTRS.each do |attr| instance_variable_set("@#{attr}", attributes[attr]) self...
true
3f670f1b1a8dd6fb423b801c2c9b8b710be1ecb7
Ruby
Denmanpg/ruby
/homeloop.rb
UTF-8
2,294
3.96875
4
[]
no_license
#Practice Problem 1. puts "Welcome, please enter your full name (first and last)?" name = gets.chomp puts name puts "Your name is " + name.length.to_s + " characters long!" puts "Do you have a nickname? Type your nickname or first name, please?" nickname = gets.chomp # #Practice Problem 2. puts "Alright, "...
true
ff6b1fc614cb0a4997078a68794794b8e6f676fd
Ruby
JQC5610/ruby-oo-relationships-practice-mini-mock-code-challenge
/book.rb
UTF-8
629
3.84375
4
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
# ### `Book` # Build the following methods on the Book class # - `Book.all` # should return all of the books # - `Book#author` # should return the author instance who wrote this book # - `Book#title` # should return the title of the book # - `Book#word_count` # should return the number of words in the book class Book...
true
c1841de50886ec78c813a47d4ee3aa6c0cd9d2a9
Ruby
mcat56/nearest-fuel-station
/app/facades/directions_facade.rb
UTF-8
993
2.578125
3
[]
no_license
class DirectionsFacade def initialize(location) @location = location end def travel_time get_directions['routes'].first['legs'].first['duration']['text'] end def distance get_directions['routes'].first['legs'].first['distance']['text'] end def html_instructions get_directions['routes']...
true
b30460e1e49c34b104e627265649c361ea1731e1
Ruby
Eden-Eltume/101
/101_Exercises/Small_Problems/Easy9/ex7.rb
UTF-8
106
3.4375
3
[]
no_license
def swap_name(str) arr = str.split(' ') "#{arr[-1]}, #{arr[0]}" end p swap_name('Joe Roberts') == 'Roberts, Joe'
true
4bb2fe6f45f352616bf0aea84c2ad06d0f2d116f
Ruby
Brazenbillygoat/programming-univbasics-4-finding-the-maximum-value-in-an-array-lab-wdc01-seng-ft-082420
/lib/finding_the_max_value.rb
UTF-8
88
3
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
def find_max_value(array) sorted_array = array.sort() return sorted_array.last() end
true
eadf5891e101073d0f35f8234bc0e8d27456de53
Ruby
courtneyburas/phase-0-tracks
/ruby/puppy_methods.rb
UTF-8
772
4.15625
4
[]
no_license
class Puppy def initialize p "initializing new puppy instance..." end def fetch(toy) puts "I brought the #{toy}!" toy end def speak(n) n.times {|n| puts "Woof!"} end def roll_over # don't know why this doesn't automatically create a new line print "*rolls over*" end def dog_years(...
true
715bb0ed68b606941ba16ee8040b478d11e1a9ec
Ruby
muriloime/exercism
/ruby/connect/connect.rb
UTF-8
1,601
3.265625
3
[]
no_license
Cell = Struct.new(:row, :col, :kind, :connected_component) class Board attr_reader :board def initialize(board) @board = board.map { |x| x.delete(' ') }.map(&:chars) # puts @board.map{|r| r.join('')} @cells = Array.new(size) { Array.new(@board.first.size) } end def size @board.count end ...
true
638341c9188bfa1a9073426e951038fa9d081db0
Ruby
etdev/algorithms
/0_code_wars/arraysecond.rb
UTF-8
129
2.875
3
[ "MIT" ]
permissive
# http://www.codewars.com/kata/536c6f2349aa8b16520002e0 # --- iteration 1 --- class Array def second self.[](1) end end
true
131be8a8d213241d2936592264860c9a7a0dad3d
Ruby
raravena80/zulia
/log_parser/log_parser.rb
UTF-8
280
2.921875
3
[ "Apache-2.0", "MIT" ]
permissive
#!/usr/bin/env ruby myfile = File.read('./samplelog') lines = myfile.split("\n") events = [] while lines.any? l = lines.shift next if l =~ /Non event/ next unless l =~ /Begin/ l = lines.shift while l !~ /End/ events << l l = lines.shift end end puts events
true
06230992e207ab10704dae1643a405321b8a4025
Ruby
elin-y/Drupalgeddon2
/drupalgeddon2.rb
UTF-8
5,887
2.765625
3
[]
no_license
#!/usr/bin/env ruby # # [CVE-2018-7600] Drupal < 7.58 / < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' ~ https://github.com/dreadlocked/Drupalgeddon2/ # Authors: # - Hans Topo ~ https://github.com/dreadlocked // https://twitter.com/_dreadlocked # - g0tmi1k ~ https://blog.g0tmi1k.com/ // https://twitter.com/g0tmi1k # ...
true
040d0f23c13f1877d43eeaa2d6b405871a364348
Ruby
JuanjoMoya/Ironhack
/Part-time/Module2_Testing_&_MVC/Noviembre2016/05saturday/Sinatra TODO (part 2)/lib/Todo.rb
UTF-8
551
2.90625
3
[]
no_license
require 'pry' class Task attr_reader :content, :id @@current_id = 1 def initialize(content) @content = content @id = @@current_id @@current_id += 1 @completed = false # wait 1 second # sleep 1 @created_at = Time.now @update_at = nil end def complete? @comp...
true
3b5aaaa06e51c61cade15c483821eb9198799d48
Ruby
eddpeterson/RackDemo
/MyFilter.ru
UTF-8
977
2.703125
3
[]
no_license
class MyFilter def initialize(app) @app = app end def call(env) status, headers, @response = @app.call(env) [status, headers, self] end def each(&block) block.call("<p>Hello from <b>my</b> filter on #{Time.new}</p>") @response.each(&block) end end class YourFilter def initialize(app) @app = ...
true
015aa8bd0a9b7aad6bbc45270b811e11079c186f
Ruby
meryemturk/ruby
/exercise_9.rb
UTF-8
1,160
4.375
4
[]
no_license
def calculator_3 puts "give me the fist number?" first_number = gets.chomp.to_i puts "give me the second number?" second_number = gets.chomp.to_i puts "what operation do you want to use? (* / - +)" operation = gets.chomp if operation == "+" answer = first_number + second_number text = "#{first_num...
true
9aa40846ddcc9c0e179f3da01c2d5a943eda37cf
Ruby
matpalm/trending
/lib/specs/trend_spec.rb
UTF-8
1,483
3.109375
3
[]
no_license
require "#{File.dirname(__FILE__)}/../trend.rb" describe 'simple mean and std dev' do before do @trend = Trend.new([2,3]) end it 'should know mean' do @trend.mean.should == 2.5 end it 'should know std dev' do @trend.sd.should be_close(0.7071068, 0.00001) end end describe 'trending without zero...
true
5472109bfdb71770559617aac7a8ec2f9a79592b
Ruby
nevans/d_heap
/spec/d_heap_spec.rb
UTF-8
3,552
3.078125
3
[ "MIT" ]
permissive
# frozen_string_literal: true RSpec.describe DHeap do it "has a version number" do expect(DHeap::VERSION).not_to be nil end shared_examples "it pops all elements in order" do |max, order| before do (0..max).to_a.__send__(order).each do |i| heap << i end end it "pops all elements in order" ...
true
28f76db2ced6e541249ccabf16cf2bc893fca4fa
Ruby
Ejhfast/codex
/examples/linter2.rb
UTF-8
1,172
2.53125
3
[]
no_license
require 'ruby_codex' require 'mongoid' require 'pp' # Boilerplate until we set up a public API Mongoid.load!("../test/mongoid.yaml", :development) class ASTNodes; include Mongoid::Document; end class ASTStats; include Mongoid::Document; end codex = Codex.new(ASTNodes, ASTStats) files = Dir["#{ARGV[0]}/**/*.rb"] unl...
true
21e4e2dee521d578bbe7ce8169207a95184e729f
Ruby
rohan484909/Training
/Ruby Training/Pattern1.rb
UTF-8
71
2.875
3
[]
no_license
for j in (5).downto(1) l=9 for i in 1..j print l l-=2 end puts end
true
32cfe4442952f50b6d62de717bd0f1875dd46783
Ruby
gittygitgit/ruby-sandbox
/strings/string4.rb
UTF-8
2,050
3.578125
4
[]
no_license
#!/bin/ruby s="|dsfsdf|234324|sdfsfd|" s=s<<"2342342|" # concat to end of s s=s.concat "sdfsfsds|" # concat to end of s s.insert(0,"|sdfsfsfd") # insert to beg of s s.insert(s.index("234"),"hello|") # insert at given index s.slice(s.index("2"),6) # re...
true
2715afa00d4180db6159652ef4c9901e0d000414
Ruby
adybas/cli-applications-jukebox-dc-web-120919
/lib/jukebox.rb
UTF-8
1,059
4.28125
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# Add your code here def help puts "I accept the following commands:" puts "- help : displays this help message" puts "- list : displays a list of songs you can play" puts "- play : lets you choose a song to play" puts "- exit : exits this program" end def play(songs_array) puts "Please enter a...
true
b0642a102a671a77eee066f636ccfc32e63a43be
Ruby
mdorash/Yacht
/lib/player.rb
UTF-8
194
3.453125
3
[]
no_license
class Player attr_reader :points, :name def initialize (player_name) @name=player_name @points=0 end def add_points (new_points) @points+=new_points end end
true
c8d2bd9a7ab0bb90335b137f729aab8734787c24
Ruby
mguachun/ruby_phase1_project
/scraper.rb
UTF-8
576
2.90625
3
[]
no_license
require 'nokogiri' require 'open-uri' class Scraper def get_page doc = Nokogiri::HTML(open("https://a24films.com/films")) end def prints_first_title first_title = self.get_page.css("h3") puts first_title end def prints_movie_info movie_info = self.get_page.css("div...
true
725ba961716f2bebbf6c21381372d5bb9da32d38
Ruby
feigningfigure/WDI_NYC_Apr14_String
/w01/d02/Jane_Shin/calculator/calc.rb
UTF-8
1,924
4.15625
4
[]
no_license
def func_do(func) if func == "a" puts "What is the first number?" num1 = gets.chomp.to_i puts "What is the second number?" num2 = gets.chomp.to_i add(num1,num2) puts "#{add(num1,num2)}" elsif func == "s" puts "What is the first number?" num1 = gets.chomp.to_i puts "What is the second number?" nu...
true
320b2a43cbc46fc9a7333bd2f701f8f21dd22b77
Ruby
Abdul-Sayed/intro-to-simple-array-manipulations-dumbo-web-051319
/lib/intro_to_simple_array_manipulations.rb
UTF-8
684
3.5
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def using_push(array, string) array.push(string) end def using_unshift(array, string) array.unshift(string) end def using_pop(array) array.pop end def pop_with_args(array) array.pop(2) end def using_shift(array) array.shift end def shift_with_args(array) array.shift(2) end d...
true
06e291f1ac4feba6726363c3725eee9b2a48e381
Ruby
Oleggio/blog
/app/models/user.rb
UTF-8
430
2.515625
3
[]
no_license
class User < ActiveRecord::Base has_many :posts validates :email, :first_name, :password, presence: true validates :email, uniqueness: true validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "Not valid!" scope :users_with_email, -> {where("email IS NOT NULL AND email ...
true
dcb9a39bc65c6d130bfdcc1c7403e80347e7d788
Ruby
ohler55/agoo
/lib/rack/handler/agoo.rb
UTF-8
5,170
2.6875
3
[ "MIT" ]
permissive
require 'agoo' unless defined?(Agoo) # Grand parent for the Agoo rack handler. module Rack # Parent for the Agoo rack handler. module Handler # The Rack::Handler::Agoo module is a handler for common rack config.rb files. module Agoo # Run the server. Options are the same as for Agoo::Server plus ...
true
91524ba48c563decc05610aa898015403c50ad12
Ruby
jemmyw/centigrade
/test/unit/centigrade_task_test.rb
UTF-8
2,074
2.609375
3
[]
no_license
require File.dirname(__FILE__) + '/../test_helper' require 'test/fixtures/test_task' class CentigradeTaskTest < ActiveSupport::TestCase context 'a task class' do should 'have an array of attributes represented as hashes each having a name' do TestTask.attributes.each do |attribute| assert attribute...
true
2fa5ab8d46f1f94930d9b43680867ded35498a15
Ruby
thotmx/pingpong
/app/models/game_decorator.rb
UTF-8
608
2.921875
3
[]
no_license
class GameDecorator def initialize(game, user) @game = game @user = user end def date game.date_played end def opponent if game.player_id == user.id game.opponent.email else game.player.email end end def score if game.player_id == user.id "#{game.player_s...
true
af011959138b83442e417d2bfeac6905936812fd
Ruby
jgwhite/mmxii-olympic-record-evolution
/scrape.rb
UTF-8
1,238
2.671875
3
[]
no_license
require 'bundler/setup' require 'nokogiri' require 'open-uri' require 'json' country_codes_page = Nokogiri::HTML open 'http://wits.worldbank.org/WITS/wits/WITSHELP/Content/Codes/Country_Codes.htm' country_codes = {} country_codes_page.css('.WT1 tr').each do |row| paras = row.css 'p' name = paras[0].content.strip ...
true
c24deeabf9bf21f8965c831d6d89b03281d6a5d2
Ruby
cjprieb/AdventOfCode2015
/Day5/niceness.rb
UTF-8
1,609
3.75
4
[]
no_license
# A nice string is one with all of the following properties: # It contains at least three vowels (aeiou only), like aei, xazegov, or aeiouaeiouaeiou. # It contains at least one letter that appears twice in a row, like xx, abcdde (dd), or aabbccdd (aa, bb, cc, or dd). # It does not contain the strings ab, cd, pq, ...
true
375993a2d6b6687cde90a90447072eda24bc552c
Ruby
NijaPerry/phase-3-ruby-oo-basics-instance-variables-lab
/lib/dog.rb
UTF-8
533
4.1875
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Dog def name=( dog_name) @this_dogs_name = dog_name end def name @this_dogs_name end end # Here we've defined two instance methods, the name= (or "name equals") method, and the name method. The first method takes in an argument of a dog's name and assigns that value to a variable, this_dogs_name...
true
992299ca58978bbd977de96110195e01838b8e92
Ruby
lucanioi/assembly-interpreter
/spec/support/arithmetic_shared_examples.rb
UTF-8
1,566
2.90625
3
[]
no_license
OPERATORS = { multiplication: :*, division: :/, addition: :+, subtraction: :- }.freeze shared_examples 'arithmetic operation' do |operation| subject(:instruction) { described_class.new(target_register, source_register) } let(:target_register) { :a } let(:source_register) { :b } let(:operator) { OPERAT...
true
533c6b7b42871f72f4414f07ef0afb697474f96c
Ruby
keithrowell/hue
/lib/hue/sensor.rb
UTF-8
3,911
2.546875
3
[ "MIT" ]
permissive
module Hue class Sensor include TranslateKeys include EditableState # HUE_RANGE = 0..65535 # SATURATION_RANGE = 0..255 # BRIGHTNESS_RANGE = 0..255 # COLOR_TEMPERATURE_RANGE = 153..500 # Unique identification number. attr_reader :id # Bridge the light is associated with attr_...
true
7feaade26288cd0ef3f9b0f0cef8192a6cc7f3f3
Ruby
madebyhiro/codem-schedule
/app/models/schedule.rb
UTF-8
1,571
2.578125
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
class Schedule class << self def run! processed = update_jobs + schedule_jobs processed.size end def update_jobs to_be_updated_jobs.each do |job| job.with_lock(true) { update_job(job) } end end def schedule_jobs to_be_scheduled_jobs.each do |job| job...
true
2b09a6239c612ca1479e97221af15872abdd9ebf
Ruby
free-beer/reorm
/lib/reorm/validators/minimum_length_validator.rb
UTF-8
528
2.78125
3
[ "MIT" ]
permissive
#! /usr/bin/env ruby # Copyright (c), 2015 Peter Wood # See the license.txt for details of the licensing of the code in this file. module Reorm class MinimumLengthValidator < Validator def initialize(length, *field) super("is too short (minimum length is #{length} characters).", *field) @length = len...
true
1216e50ea16db9de8b375d216b2621cb026e0c66
Ruby
timetwister4/nanotwitter
/helpers/authentication.rb
UTF-8
1,048
2.625
3
[ "MIT" ]
permissive
require_relative '../models/user.rb' require "byebug" def authenticate! if session[:user_id] && User.where(id: session[:user_id]).exists? #if the user id saved in session does not belong to any user, also direct to general homepage true else session[:original_request] = request.path_info false ...
true
b97625ce06ee7cd1921a43fdf897dde826fdedff
Ruby
gmcgibbon/Ecommerce-Rails-Project
/app/models/customer.rb
UTF-8
804
2.609375
3
[]
no_license
class Customer < ActiveRecord::Base attr_accessible :address, :city, :country, :email, :first_name, :last_name, :postal_code, :province_id belongs_to :province has_many :orders validates :address, :format => {:with => /^[0-9]+ +\w+ +\w+?\S$/, :message => "was not recognized. eg. 123 Blue Street"} val...
true
69ed97d4ec90f940019720f43880856b86bc8e7e
Ruby
bobtodd/bananas
/txtgrndr/macspyder.rb
UTF-8
5,366
3.0625
3
[]
no_license
#!/usr/bin/env ruby # A short script to run textgrounder MacGyver-style # using low memory require 'nokogiri' require 'open-uri' require 'optparse' # Use OptionsParser to read command-line options options = {} optparse = OptionParser.new do |opts| # Banner: displayed at top of help screen opts.banner = "Usage: ...
true
2c29016673b9f822fdfd70c45cbd406c8eb8cdcb
Ruby
DojoCaelumRio/Mini-Interpretador-de-Scheme
/lib/solution/array.rb
UTF-8
149
3.28125
3
[]
no_license
class Array def without_first self - [first] end def apply(method) self.inject{|result,number| result.send(method,number)} end end
true
b2ed2d63b0c3941865b10321e3989c74a69f15a8
Ruby
kdeberk/advent-of-code
/2017/13/13.rb
UTF-8
671
3.359375
3
[]
no_license
#!/usr/bin/env ruby lines = File.read('input').split("\n") layers = lines.map {|line| line.split(':').map(&:to_i)} puts layers .select {|(depth, range)| 0 == depth % (2 * (range - 1))} .map{|(depth, range)| depth * range} .reduce(&:+) # the delays at which we can safely pass through the firewa...
true
4da718d4b3ac0a7cb536e82516e4f77c3cfbeaaa
Ruby
brandnewlink/noteblock
/db/seeds.rb
UTF-8
1,258
2.75
3
[]
no_license
# FAKE DATA! @key = Bitcoin::Key.from_base58("93SXbJxzDKu4GGoh92DBW8yXbtFUZbPXUL6oqGbdosXD4cGBTbV") @note = Note.create( content: "I love you baby for ever", address: @key.addr, email: "scottli_010@hotmail.com", encrypted_private_key: AES.encrypt(@key.priv, ENV["DECRYPTION_KEY"]) ) @note.note_transactions.cr...
true
1f5fddcfd1b68c47a52c1670c3016a9fa3261a05
Ruby
othiym23/ingestion-tools
/lib/ui/selection_model.rb
UTF-8
492
2.59375
3
[]
no_license
require 'observer' class SelectionModel include Observable attr_accessor :list, :selected, :total def list=(values) if @list != values changed @list = values notify_observers(values) end end def selected=(value) if @selected != value changed @selected = value ...
true
2c05461e808892545497382bb20cc5d979731cd8
Ruby
jessicabettsftw/Game-of-Thrones-CLI
/lib/cli.rb
UTF-8
3,000
3.9375
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
####################################### #------------STAGE3 CLI --------------# ####################################### class CLI @player_character_id = nil def player Character.find_by(id: @player_character_id) end def main welcome player_character = nil keep_playing = true while !play...
true
34e40fe97efa48df9011b66a460045f8fcd050b5
Ruby
kolyaventuri/black_thursday
/lib/item.rb
UTF-8
920
3.0625
3
[]
no_license
# frozen_string_literal: true require 'time' # Defines an item in the store class Item attr_reader :id, :name, :description, :unit_price, :created_at, :updated_at, :merchant_id, :item_repository def initialize(data,...
true
428e981ace7a0bd00b2909567c8109731ccfe95a
Ruby
vjuska/practice-web-requests
/weather_app.rb
UTF-8
641
3.53125
4
[]
no_license
require "http" response = HTTP.get("https://api.openweathermap.org/data/2.5/forecast?q=chicago&appid=#{ENV["OPEN_WEATHER_API_KEY"]}") weather_data = JSON.parse(response.body) five_day = [] index = 0 while index < 33 five_day << weather_data["list"][index]["main"]["temp"] index += 8 end p five_day puts "Please ...
true
2f518484e7952631149ea40f57d20b21fa776ee8
Ruby
benchristel/waterslide
/lib/waterslide.rb
UTF-8
1,227
3.171875
3
[ "MIT" ]
permissive
module Waterslide module RightShiftOverride def >> (filter) instantiated(filter).receive_from(self) end private def instantiated(filter) filter.is_a?(Class) ? filter.new : filter end end module Filter def self.included(base) base.class_eval do include Enumerable...
true
e6846e9e3f7f9caa578edda366aab674d69e297a
Ruby
emilie-lb/THP_S1J2_exosRuby-testSession
/exo_16.rb
UTF-8
267
3.390625
3
[]
no_license
puts "Quel âge as-tu?" print "> " user_age = gets.chomp.to_i user_yearbirth = 2020 - user_age i = 0 user_age.times do if i <= user_age puts "Il y a #{i}ans, c'est à dire en #{user_yearbirth + (user_age - i)}, tu avais #{user_age - i} ans." i = i + 1 end end
true
e2021f77d3d44365cb81b2cf20029ca9689795bc
Ruby
ravenwijaya/MyKattis
/Trik.rb
UTF-8
310
3.5
4
[]
no_license
input=gets.chomp().split('') position=0 input.each do |char| if char == "A" && position != 2 position = 1 - position end if char == "B" && position != 0 position = -position + 3 end if char == "C" && position != 1 position = -position + 2 end end puts position+1
true
7c790d499d753b7fced0375228a45d64670704e2
Ruby
akesterson/tailor
/lib/tailor/Library.rb
UTF-8
1,100
3.078125
3
[ "MIT" ]
permissive
require 'Tailor/Tileset' module Tailor class Library def initialize @tilesets = [] end def tileset_names x = [] idx = 0 @tilesets.each do |tileset| x << tileset.tileset_name idx += 1 end x end def each @tilesets.each do |tileset| ...
true
9e5f8b8ac961fa24f73e4c49377b1a7d043008e8
Ruby
Dpalazzari/HTTP
/test/dictionary_test.rb
UTF-8
492
2.734375
3
[]
no_license
require 'minitest/autorun' require 'minitest/pride' require './lib/dictionary.rb' class DictionaryTest < Minitest::Test attr_reader :dictionary def setup @dictionary = Dictionary.new end def test_it_exists assert dictionary end def test_it_can_find_a_word_from_the_dictionary assert_equal "Po...
true
21a401e34bef0a963dc00ef7f138f59d66d8b998
Ruby
dhbtk/rndl-old
/app/models/trip_date.rb
UTF-8
160
2.8125
3
[]
no_license
class TripDate attr_accessor :trip_date, :count, :trips def initialize(*args) @trip_date = args[0] @count = args[1] @trips = args[2] end end
true
6ec210d8091f2a7d369697c4bd6bac4d1943983f
Ruby
dtz900/Launch-school
/small_problems/easy2d.rb
UTF-8
458
4.28125
4
[]
no_license
# Build a program that displays when the user will retire and how many years she has to work # till retirement def retire puts "What is your age?" age = gets.chomp.to_i puts "At what age would you like to retire?" retire_age = gets.chomp.to_i time = Time.new.year retire_year = (retire_age - age) + time ...
true
65cab7152e1f0f25de83b8425feac839d03e0e59
Ruby
maros310/sample_app
/app/helpers/sessions_helper.rb
UTF-8
3,328
2.828125
3
[]
no_license
module SessionsHelper # コントローラ、ビューの両方からアクセスできるcurrent_userを作成する。 def sign_in(user) remember_token = User.new_remember_token cookies.permanent[:remember_token] = remember_token # 20年後に期限切れするクッキーを作成(まあ半永久的でしょってことでpermanent)。 # cookies[:remember_token] = { value: remember_token, expires: 20.years.from_now.utc } <= ...
true
9a00eb7c211dab978599d3f5743fa1ad8989f5f9
Ruby
JustinData/GA-WDI-Work
/w01/d02/Erica/2.rb
UTF-8
2,078
3.84375
4
[]
no_license
# A user should be given a menu of operations # A user should be able to choose from the menu def menu puts 'basic, advanced, or quit' $answer = gets.chomp.downcase end def basic_calc print "(a)dd, (s)ubtract, (m)ultiply, (d)ivide: " $answerx = gets.chomp.downcase end def advanced_calc print '(p)ower, (s)qr...
true
e1b65ce9377217d7eaa88434b34e0a19665d1b1c
Ruby
AshleyRapone/programming_foundations
/lesson4/PracticeProblem8.rb
UTF-8
242
3.78125
4
[]
no_license
# How does take work? Is it destructive? How can we find out? arr = [1, 2, 3, 4, 5] arr.take(2) =begin Take returns the first number of elements, since there is a 2 [1, 2] would be returned It is not destructive, I checked it in irb =end
true
2c6df543e098d771bec1860c8a5164267d25af5c
Ruby
Sethoscope1/Url-Shortener
/app/models/shortened_url.rb
UTF-8
1,584
2.578125
3
[]
no_license
require 'SecureRandom' require 'time' class ShortenedUrl < ActiveRecord::Base attr_accessible :short_url, :long_url, :user_id validate :short_url, :uniqueness => true validate :short_url, :presence => true validate :long_url, :presence => true validate :user_id, :presence => true belongs_to( :user, ...
true
b141ea9194e17fac578a6406073e8b4a64f21d63
Ruby
katycarr/pokemon-scraper-web-010818
/lib/pokemon.rb
UTF-8
699
3.25
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Pokemon attr_accessor :name, :type, :db, :id, :hp attr_reader :all @@all = [] def initialize(id:nil, name:, type:, db:, hp:60) @id = id @name = name @type = type @db = db @hp = hp @@all << self end def self.save(name, type, db) db.execute("INSERT INTO pokemon (name, ty...
true
70fa88cdfbf32cde8e89cb0f2724363c75c0fd58
Ruby
JayTeeSF/church_search
/lib/church_search/twitter_client.rb
UTF-8
1,146
2.53125
3
[ "MIT" ]
permissive
require 'twitter' module ChurchSearch module TwitterClient extend self def default_options { consumer_key: SecureSettings::TwitterClient.consumer_key, consumer_secret: SecureSettings::TwitterClient.consumer_secret, } end def help <<-EOF Create your own #{ENV[...
true
b6e7e5c455040ced394fd4846ecc081361658c23
Ruby
benbristow/agile-timer
/program.rb
UTF-8
1,590
3.34375
3
[ "MIT" ]
permissive
#!/usr/bin/env ruby Dir.glob('lib/**/*.rb') { |f| require_relative f } class Program def initialize env clear_display @participants = get_participants.shuffle @drive_time = get_drive_time @random_voice = env["RANDOM_VOICE"] == "true" ? true : false @timer = AgileTimer.new({ drive_time: @dri...
true
be4a89180030a99f02fe30959e39c07ad9d76586
Ruby
BillyCaudy/W2D1
/chess/game.rb
UTF-8
317
2.71875
3
[]
no_license
require_relative 'board.rb' require_relative 'display.rb' class Game def initialize @baord = Board.new @display = Display.new @players = {} @current_player = :white end def play end def notify_players end def swap_turn! end end
true
00a2f9924fa46480b153c09e5b438987091a83df
Ruby
coffeencoke/fun
/lib/problems/tall_people.rb
UTF-8
697
3.296875
3
[ "MIT" ]
permissive
module TallPeople def self.get_people(*rows) tallest_of_the_shortest = -1/0.0 tallest_by_column = [] rows.each_with_index do |people, row| shortest_from_row = 1/0.0 people.split(" ").each_with_index do |person, column| height = person.to_i shortest_from_row = height if shortes...
true
a6a9db38058a916e2da33ee4febccecfa91ca232
Ruby
JustinLove/ohol-family-trees
/lib/ohol-family-trees/id_index.rb
UTF-8
812
2.53125
3
[]
no_license
module OHOLFamilyTrees class IdIndex attr_reader :filesystem attr_reader :output_path attr_reader :tile_type def initialize(filesystem, output_path, tile_type) @output_path = output_path @filesystem = filesystem @tile_type = tile_type end def write_index(triples, dir) ...
true
f54284479ab7465c56befb9ccb03ef687e64a89b
Ruby
safuya/school-domain-v-000
/lib/school.rb
UTF-8
367
3.5625
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require 'pry' class School attr_reader :name, :roster def initialize(name) @name = name @roster = {} end def add_student(name, grade) @roster[grade] ? @roster[grade] << name : @roster[grade] = [name] end def grade(grade) @roster[grade] end def sort @roster.sort.to_h.map { |grade...
true
29a29e3ae9bee42ead2f70649a911eef8903bb67
Ruby
sofiajonsson/my-select-seattle-web-career-021819
/lib/my_select.rb
UTF-8
96
2.734375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def my_select(collection) # your code here! collection.select do |num| num.even? end end
true
7bb0c6a264818e2534821eea52b62c7f5e339e53
Ruby
ctpelnar1988/Ruby
/recursion/quick_sort.rb
UTF-8
349
3.5
4
[ "Apache-2.0" ]
permissive
require_relative 'flatten.rb' def quick_sort(arr) length = arr.length return arr if length <= 1 left, right = [], [] pivot = arr[0] i = 1 while i < length arr[i] < pivot ? left << arr[i] : right << arr[i] i += 1 end flatten([quick_sort(left), pivot, quick_sort(right)]) end list = [6,4,8,3,7,2,...
true
14aebbd0cd0bb12abaf3d62dfa2a6fd5830aa0f9
Ruby
amitbansal7/sbpp-ruby
/70_duplicate_removing_set.rb
UTF-8
221
3.0625
3
[]
no_license
# frozen_string_literal: true # How do you remove the duplicates from a collection? # Send as_set to the collection. The result will have all duplicates # removed require 'set' puts [1, 2, 3, 4, 5, 1, 2, 3, 1].to_set
true
f82bdd599817140a380d9d19dae393ad765a3699
Ruby
medusa-project/ideals
/test/util/space_utils_test.rb
UTF-8
502
2.84375
3
[]
no_license
require 'test_helper' class SpaceUtilsTest < ActiveSupport::TestCase test "dms_to_decimal() with nil arguments returns zero" do result = SpaceUtils.dms_to_decimal(nil, nil, nil) assert_equal 0.0, result end test "dms_to_decimal() returns a correct value" do result = SpaceUtils.dms_to_decimal(40, 6,...
true
dea458bf422fa949c15c173038060efaf79a573b
Ruby
John-Li/my_programs
/book/old/task4-9.rb
UTF-8
787
3.671875
4
[]
no_license
# Задача 9. # Написать программу нахождения числа дней в месяце, если даны # номер месяца и целая величина, равная 1 для високосного года и 0 в # противном случае. # Jan 31 / Feb-28,29 / March-31 / April-30 / May-31 / June-30 / July-31 / August-31 / Sept-30 / Oct-31 / Nov-30 / Dec-31 hash = {'1' => "30", '3' => "31"...
true
9c99d3b15fd105f785a8d381289674fb4d79f827
Ruby
Macaroni2629/Launch-School
/RB100_back_end_prep/ruby_exercises/return/breakfast_lunch_or_dinner_part5.rb
UTF-8
229
3.796875
4
[]
no_license
def meal 'Dinner' puts 'Dinner' end p meal # 'Dinner' is outputted, and because 'p' method is used, one # can see the raw value returned. Thus, you also see 'nil' returned # because `puts` method always returns `nil.`
true
fc16b9a3c4dc91d4febd05344a3358be07243b21
Ruby
traject/traject
/test/solr_json_writer_test.rb
UTF-8
13,981
2.671875
3
[ "MIT" ]
permissive
require 'test_helper' require 'httpclient' require 'traject/solr_json_writer' require 'thread' require 'json' require 'stringio' require 'logger' # Some basic tests, using a mocked HTTPClient so we can see what it did -- # these tests do not run against a real solr server at present. describe "Traject::SolrJsonWriter...
true
a1fa1ddd6d436a2b5e75622970d66245504d226b
Ruby
pienkowskip/geoprojector
/lib/geo_projector/math/float.rb
UTF-8
137
2.90625
3
[ "MIT" ]
permissive
class Float ZERO_EPSILON = 1e-32 def zero_epsilon? self.abs <= ZERO_EPSILON end alias_method :zero_eps?, :zero_epsilon? end
true
9234be593923c3cbcaf86569c6fdbf40f8ddc95e
Ruby
flexirest/flexirest
/spec/lib/result_iterator_spec.rb
UTF-8
5,033
2.6875
3
[ "MIT" ]
permissive
require 'spec_helper' describe Flexirest::ResultIterator do let(:response) { double(status: 200, response_headers: { some: 'header'}) } it "should be able to have a status set during creation" do result = Flexirest::ResultIterator.new(response) expect(result._status).to eq(200) end it "should be able...
true
e734a84877fe38e616b3deace4161aca40bb75fd
Ruby
pdadhaniya/burrito_tracker
/spec/repositories/persons_spec.rb
UTF-8
2,318
2.578125
3
[]
no_license
require_relative '../spec_helper.rb' describe BurritoTracker::Repositories::PersonsRepo do let(:person1) { BurritoTracker::Person.new(first_name: "Parag") } before(:each) do # BurritoTracker.persons_burritos_restaurants_repo.drop_tables BurritoTracker.restaurants_repo.drop_tables BurritoTracker.burrit...
true
2eae0c745d3c7dc271c6f65586e8317437157902
Ruby
VinyLimaZ/iugu-scripts
/script_numbers/magic_numbers.rb
UTF-8
436
3.65625
4
[]
no_license
#!ruby class MagicNumbers def initialize(number) @number_to_verify = number end def esoteric? @number_to_verify % 3 == 0 && @number_to_verify % 5 == 0 end def cetic? !esoteric? end def prime? !not_prime? end def not_prime? # Prime.instance.prime?(number) [2, 3, 5, 7]...
true
c4006be0cc0610b9e1daa4b0def80857f4d42c00
Ruby
yoelyukalo/ruby-enumerables-cartoon-collections-lab-part-2-hou01-seng-ft-100520
/cartoon_collections.rb
UTF-8
694
3.359375
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
def square_array(array) new_arr = [] count = 0 while count < array.length do new_arr << array[count] * array[count] count += 1 end new_arr end def summon_captain_planet(planeteer_calls) new_arr = [] i = 0 while i < planeteer_calls.length do new_arr << planeteer_calls[i].capitalize + "!" ...
true
aed67fbc52b46b014b1178265831871cdfdd1d92
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/rna-transcription/f730cd812ea44a5f9d753364f33264e7.rb
UTF-8
389
3.25
3
[]
no_license
module Complement DNA_MAPPING = {"G" => "C", "C" => "G", "T" => "A", "A" => "U"} RNA_MAPPING = DNA_MAPPING.invert def self.of_dna(seq) of_seq(seq, DNA_MAPPING) end def self.of_rna(seq) of_seq(seq, RNA_MAPPING) end def self.of_seq(seq, mapping) seq.each_char.map { |char| ...
true
bc328ba4fef62439577e4655f2daf738ce1795f0
Ruby
stpyaruwo/ProjectEuler_ruby
/problem21/problem21.rb
UTF-8
509
3.59375
4
[]
no_license
require 'prime' def get_divisor_sum(divisor) sum_divisors = Prime.prime_division(divisor).inject(1) do |sum_divisors, prime| sum_divisors * (0..prime[1]).inject(0) {|sum, expo| sum + prime[0]**expo} end block_given? ? yield(sum_divisors) : sum_divisors end result = (1...10000).inject(0) do |result, a| b =...
true
cbc248f4c9612b02458cfad8c0600ca714c145f4
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/gigasecond/a958bf8d4e9d4cb88b540b64389f497b.rb
UTF-8
113
2.953125
3
[]
no_license
class Gigasecond def self.from(date) second = 1.fdiv(86400) date + (second * (10 ** 9)).to_i end end
true
e3ae5ce39f57a9b833c0d70fceb665fa5cd0cc0c
Ruby
peterdavidhamilton/ldap-ber
/lib/ber/function.rb
UTF-8
2,150
2.828125
3
[ "MIT" ]
permissive
# frozen_string_literal: true require 'ber/identified' module BER # @see BER.function # # Used within refinements to identify... # class Function def parse_ber_object(syntax, id, data) object_type = (syntax && syntax[id]) || IDENTIFIED[id] case object_type when :string s = Ber...
true
eade0a88a97acd34a74ba0edf3c7b28d788dd30e
Ruby
LuisDLF98/TOP-ruby-exercises
/recursion/merge_sort.rb
UTF-8
1,834
4.3125
4
[ "MIT" ]
permissive
# Helper method for merge_sort. # Merges 2 subarrays back into array def merge(array, left, middle, right) sub_left = middle - left + 1 sub_right = right - middle # Create left and right subarrays. left_array = array[left..middle] right_array = array[(middle + 1)..right] index_left_array = 0 ...
true
384b33bf58a62027f892d829bb2eec8014bf0cf6
Ruby
allthatjoy/rails-yelp-mvp
/app/controllers/reviews_controller.rb
UTF-8
1,236
2.53125
3
[]
no_license
class ReviewsController < ApplicationController def new @review = Review.new #send the restaurant object @restaurant = Restaurant.find(params[:restaurant_id]) end # def create # #i will need a restaurant object to set the id # #you'll get it from the param (the id of the restauant) # @rev...
true
d34b813c7d12afdfc959b6eac8caaa53a455e007
Ruby
lhz/mazes
/lib/maze.rb
UTF-8
2,686
3.515625
4
[]
no_license
require 'cell' class Maze attr_reader :width, :height, :cells def initialize(width, height) @width = width @height = height @cells = Array.new(@height * @width) { Cell.new } end def [](row, column) if row >=0 && row < height && column >= 0 && column < width cells[row * width + column]...
true
abd7909df0d31fa2506ba042503adccee8fbf1c2
Ruby
MargaretLangley/letting
/lib/import/contact_fields.rb
UTF-8
1,315
2.828125
3
[]
no_license
require_relative '../modules/method_missing' require_relative 'entity_fields' # rubocop: disable Metrics/MethodLength module DB #### # # ContactFields # Wraps around an imported row of data # # Called during the importing of any entity - property, agent # and client. # #### # class ContactFields...
true
ee3359ec2c399a5f0968b2836d7d04af1606d0c9
Ruby
cielavenir/procon
/euler/tyama_euler40.rb
UTF-8
124
2.640625
3
[ "0BSD" ]
permissive
#!/usr/bin/ruby s=[*1..299999]*'' p [s[0,1],s[9,1],s[99,1],s[999,1],s[9999,1],s[99999,1],s[999999,1]].map(&:to_i).reduce(:*)
true
9d01cb395c675ab56319a177829bf0f1a1770e10
Ruby
pophealth/test-patient-generator
/lib/tasks/generate.rake
UTF-8
2,231
2.671875
3
[]
no_license
require 'bundler/setup' require 'hqmf-parser' require 'hqmf2js' require 'fileutils' require_relative '../test-patient-generator' Mongoid.configure do |config| config.sessions = { default: { hosts: ["localhost: 27017"], database: "cypress_development" } } end MONGO_DB = Mongoid.default_session...
true
8956302cd4414058344c92c48083f8d2459d09a0
Ruby
Team-FOYO/foyo-work
/nagano-cake/app/models/genre.rb
UTF-8
249
2.65625
3
[]
no_license
class Genre < ApplicationRecord has_many :items validates :name ,presence: true # validates :is_active ,presence: true def if_is_active yuukou = "有効" mukou = "無効" if true == is_active yuukou else mukou end end end
true
6d99068805b8fcfd91b35171df246eefff95b37a
Ruby
daveed/code
/ruby/codewars/summation.rb
UTF-8
45
3.265625
3
[]
no_license
def summation(num) (1..num).inject(:+) end
true
d513882e5aef944e7180ca88551a43e95d364603
Ruby
fledman/runaround
/lib/runaround/manager.rb
UTF-8
3,464
3.046875
3
[ "MIT" ]
permissive
require "fiber" require "runaround/callback_hook" require "runaround/errors" module Runaround class Manager attr_reader :receiver, :apply, :for_instances def initialize(receiver, apply: true, for_instances: false) @receiver = receiver @apply = !!apply @for_instances = !!for_instances e...
true
4dbdd687ca49a6b3bba0829c4345fc1d495d3e77
Ruby
stephaniea-a/ruby-basics
/ruby-inheritance/classes/animal.rb
UTF-8
73
2.625
3
[]
no_license
class Animal < Organism def breathe puts "I can breathe!" end end
true
355ff8de5573067c189f5dc2794bdb3bb5b15d14
Ruby
hackhands/Rails-Lite
/lib/rails_lite/controller_base.rb
UTF-8
1,434
2.59375
3
[]
no_license
require 'erb' require_relative 'params' require_relative 'session' require 'active_support/core_ext' class ControllerBase attr_reader :params def initialize(req, res, route_params = {}) @req = req @res = res @params = Params.new(@req, route_params) end def session @session ||= Session.new(@re...
true
986ea62838cee2117f0694ea5777bbdb92be0810
Ruby
sdittebrand/mined_minds_kata
/array_test.rb
UTF-8
1,302
2.921875
3
[]
no_license
require "minitest/autorun" require_relative "mm_array.rb" class TestArrayFunction < Minitest::Test def test_for_100_elements results = mm_array assert_equal(100,results.length) end def test_1_returns_1 results = mm_array assert_equal(1,results[0]) end def test_15...
true
db484f818818c63edf8afa6bf7e626b51bc3b5d3
Ruby
a-G-a-o/RB101
/small_problems/easy_8/2.rb
UTF-8
882
4.53125
5
[]
no_license
=begin Write a method that returns a list of all substrings of a string that start at the beginning of the original string. The return value should be arranged in order from shortest to longest substring. Examples: leading_substrings('abc') == ['a', 'ab', 'abc'] leading_substrings('a') == ['a'] leading_subst...
true
5bc789afb923d9de971674558f06ad8af7f7269c
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/strain/6d38700f4ca74232a12ebaebdd2040d5.rb
UTF-8
301
2.921875
3
[]
no_license
# Generic solution for enumerables module Enumerable def keep(&predicate) result = [] each do |item| result << item if yield item end result end def discard(&predicate) result = [] each do |item| result << item unless yield item end result end end
true
10a1c8ca9eeadd7a23d884ed6cb7757d1f253365
Ruby
mediocretes/daibatsu
/app/models/punishment.rb
UTF-8
371
2.5625
3
[]
no_license
class Punishment < ActiveRecord::Base attr_accessible :name, :description has_many :responses has_many :simulations def get_results(value) self.responses.find_all_by_appropriate_when(value).size end def average_simulation simulations.count == 0 ? 0 : simulations.inject(0.0){ |sum, item| sum += ...
true
3c17414563a95c36f3fde02466f61a309c735065
Ruby
junderhill/ruby-playground
/lib/domain/post.rb
UTF-8
276
2.6875
3
[]
no_license
require 'json' require_relative 'baseObject' module Domain class Post extend BaseObject attr_accessor :id def initialize(id) @id = id end def self.from_json(json) postHash = super json Post.new(postHash['id']) end end end
true
6ccd160d6da97f329902d02774508e03b996f0c7
Ruby
r0tiart/anagram-detector-v-000
/lib/anagram.rb
UTF-8
352
3.640625
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# Your code goes here! class Anagram attr_accessor :word, :anagram def initialize(word) @word=word end def match(anagram) word_letters = @word.split("").sort #splits the inputed word into an array of letters & sorts it alphabetically anagram.select do |word| word.split("").sort == word_lett...
true
76af52b649ee7a053d38186b4703490fa6cf0b51
Ruby
illacceptanything/illacceptanything
/code/rails/activerecord/test/cases/adapters/postgresql/enum_test.rb
UTF-8
2,455
2.578125
3
[ "MIT", "Ruby" ]
permissive
# frozen_string_literal: true require "cases/helper" require "support/connection_helper" class PostgresqlEnumTest < ActiveRecord::PostgreSQLTestCase include ConnectionHelper class PostgresqlEnum < ActiveRecord::Base self.table_name = "postgresql_enums" end def setup @connection = ActiveRecord::Base....
true
1ef2d57f2d19ebd59c89ec97d1ff18499734f177
Ruby
gtigas/CLI-Chess
/src/board.rb
UTF-8
2,785
3.703125
4
[]
no_license
require_relative 'pieces' class Board attr_accessor :grid def initialize(grid = nil) grid = grid || new_game_grid @grid = grid end def move_piece(start_pos, end_pos) piece = self[start_pos] raise MoveError.new("That's not a valid chess move") unless piece.moves.include?(end_pos) raise Mo...
true
ed32c288738d8071d224a74a13dabff081cc76db
Ruby
JanaVPetrova/web-blackjack
/app/controllers/games.rb
UTF-8
3,422
2.671875
3
[]
no_license
class Games < Sinatra::Base set :root, File.expand_path('../../', __FILE__) helpers do def save_to_session(data = {}) session[:data] ||= {} session[:data].merge! data end def count_prize(hands) hands.inject(0) { |sum, hand| sum += (hand.result == 'win' ? 1.5 * hand.bet : 0) } en...
true