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
0f8ac756964dcd0094b1a2d45c866f748539ee7f
Ruby
goldstar/blackbeard
/lib/blackbeard/cohort_metric.rb
UTF-8
1,227
2.59375
3
[ "MIT" ]
permissive
module Blackbeard class CohortMetric include ConfigurationMethods include Chartable attr_reader :cohort, :metric def initialize(cohort, metric) @cohort = cohort @metric = metric end def type metric.type end def add(context, amount) uid = context.unique_ident...
true
6115c2687d500b2f901381e9a9954cfdfeb7a0c9
Ruby
avinash-vllbh/programming-journal
/ruby/bit_manipulation/reverse_bits_integer.rb
UTF-8
2,836
4.3125
4
[]
no_license
### # Reverse the bits of an unsigned integer # Direct approach # Convert to base 2 string or array and reverse # Time complexity: O(n) loop through all the bits ### def reverse_bits(num, size) # To make the input number into binary of 16 or 32 bit format binary = "%0#{size}d" % num.to_s(2) #convert decimal to stri...
true
7a94d4c8212706983f126c8f9a17cbfb58815e7e
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/difference-of-squares/4f96adde98244ebda7dbd54966695370.rb
UTF-8
328
3.4375
3
[]
no_license
class Squares def initialize(upper_bound) @upper_bound = upper_bound end def square_of_sums @square_sums ||= (1..@upper_bound).reduce(&:+)**2 end def sum_of_squares @sum_squares ||= (1..@upper_bound).inject(0) { |sum, i| sum + i**2 } end def difference square_of_sums - sum_of_squares ...
true
3982839c2c85edd066a6e079f27247fc2553cb33
Ruby
Anikram/hanged_man
/lib/result_printer.rb
UTF-8
1,929
3.28125
3
[]
no_license
# promoted to print out game's feedback class ResultPrinter attr_accessor :game, :status_image def initialize(game) @game = game # array of images @status_image = [] # full path for asset loading current_path = File.dirname(__FILE__) # load images to array load_images(current_path) end...
true
907a9d4a94ddf961bbafeab61c5de73a8c2156e1
Ruby
BrianMehrman/class_eval-vs-define_method
/dynamic_methods.rb
UTF-8
1,207
3.8125
4
[]
no_license
# Defines the methods normally module Foo def my_method 'text' end end # Defines the methods using class_eval module ClassFoo class_eval <<-RUBY def my_method 'text' end RUBY end # Defines the methods using define_method module DefineFoo define_method 'my_method' do 'text' end end # ...
true
5ea25fc19b9220a8461682ce14f54251cb93d108
Ruby
storywr/storywr-cli-app
/lib/scraper.rb
UTF-8
1,028
2.859375
3
[]
no_license
require 'nokogiri' require 'open-uri' class Scraper def self.get_games(week) doc = Nokogiri::HTML(open("http://www.espn.com/nfl/schedule/_/week/#{week}")) games = doc.css("#sched-container .responsive-table-wrap tr") games.each do |game| home = game.css(".home .team-name span").text unless home...
true
4fb9dcd51f65e4ddd8a9950ec61fd9918db95fce
Ruby
ham357/expressive-writing
/spec/models/user_spec.rb
UTF-8
2,373
2.546875
3
[]
no_license
require 'rails_helper' describe User do describe '#create' do it "すべてのデータがあり、正常に登録できる" do user = build(:user) expect(user).to be_valid end it "ニックネームなしでは保存不可" do user = build(:user, nickname: nil) user.valid? expect(user.errors[:nickname]).to include("が入力されていません。") end ...
true
a4c10fbeb7bc17853084782414127060ffebe170
Ruby
trollepierre/ruby_game_of_life
/spec/route_app_spec.rb
UTF-8
2,348
2.546875
3
[]
no_license
require 'spec_helper' require_relative '../route_app' require_relative '../lib/file_manager' require_relative '../lib/controller' describe RouteApp do describe 'GET /' do it 'should be ok' do get '/' expect(last_response).to be_ok end it 'should display content through controller' do g...
true
a91ef2dfca6d76409f0dda4ca87c98f7b53cb842
Ruby
jimmoore225/ruby_test_project
/myFirstMethod.rb
UTF-8
646
3.921875
4
[]
no_license
#!/usr/bin/env ruby def hello 'Hello' end puts hello def hello1(name) 'Hello ' + name end puts(hello1('Jimbob')) def hello2 name2 'Hello ' + name2 end puts(hello2 'Jim') def mtd(arg1="Arlo", arg2="Effie", arg3="Tasha") "#{arg1}, #{arg2}, #{arg3}." end puts mtd puts mtd("Stick") puts mtd("Stick", "Ma...
true
9359f8cc9e5e4114f442adab493e7131d9454224
Ruby
marlbones/CFA-TrentTracker-Project
/TrentTracker.rb
UTF-8
1,843
2.96875
3
[]
no_license
require 'terminal-table' # require 'rspotify' # require 'geocoder' rows = [] rows << ['Where is Trent?', 1] rows << ['Make a Mix Tape', 2] rows << ['Love Letter', 3] table1 = Terminal::Table.new :title => " \u2665 Trent Tracker \u2665 ", :headings => ['Options', 'Number'], :rows => rows, :style => {:width => 3...
true
734b6dcce2785276ca2d93f3c1f96798b29aebe1
Ruby
martiantim/Crossword-Adventure
/app/controllers/puzzles_controller.rb
UTF-8
1,848
2.609375
3
[]
no_license
class PuzzlesController < ApplicationController def show @me = User.find(1284) @puzzle = Puzzle.find(params[:id]) end def edit @me = User.find(1284) @puzzle = Puzzle.find_by_id(params[:id]) if !@puzzle @puzzle = Puzzle.create!(:width => 15, :height => 15, :name => "New Puzzle") ...
true
ccf9b903f2a394460ca8751d88e71f7331c492f6
Ruby
swdonovan/night_writer
/test/night_write_test.rb
UTF-8
763
2.78125
3
[]
no_license
gem 'minitest', '~>5.0' require 'minitest/autorun' require 'minitest/pride' require './lib/night_write' require 'pry' class NightWriteTest < Minitest::Test def test_NightWrite_reads_other_file_content file_name = File.read(ARGV[0]) text = NightWrite.new actual = text.reader.incoming_text expected = ...
true
89ea701d1120f4ca438e5b8c7a8fddf61b5791b7
Ruby
dotthespeck/fs_week_one
/monday/strings1.rb
UTF-8
1,218
4.75
5
[]
no_license
#You can leave comments in your Ruby code by starting a line with a number sign #Feel free to make changes to the code to see what happens! You can always pull down a new copy of the original #strings--lines of text--in Ruby need be enclosed in single or double quotes #if you use a contraction, you will need double qu...
true
0a168384ef36f62045086a96be54a2eb83d46dcf
Ruby
americac/alice
/alice/listeners/beverage.rb
UTF-8
3,474
2.53125
3
[ "MIT" ]
permissive
require 'cinch' module Alice module Listeners class Beverage include Alice::Behavior::Listens include Alice::Behavior::TracksActivity include Cinch::Plugin match /^\!spill (.+)/i, method: :spill, use_prefix: false match /^\!pour (.+)/i, method: :spill, use_pre...
true
78a91ca6bd5d4bf2757abd2a603f1c45f17b068c
Ruby
yoatnic/til-understanding-computation
/Section2-denotational-semantics/main.rb
UTF-8
995
3.828125
4
[]
no_license
require './number.rb' require './boolean.rb' require './variable.rb' require './add.rb' require './multiply.rb' require './lessthan.rb' p Number.new(5).to_ruby p Boolean.new(false).to_ruby puts "---------Number----------" p proc1 = eval(Number.new(5).to_ruby) p proc1.call({}) puts "---------Boolean----------" p pr...
true
5923738593aa6496172e1942ca41639ce39c1d03
Ruby
BennyLouie/oo-relationships-practice-dumbo-web-82619
/tools/console.rb
UTF-8
4,760
2.984375
3
[]
no_license
require_relative '../config/environment.rb' def reload load 'config/environment.rb' end ###Airbnb Excercise### house1 = Listing.new("NYC") house2 = Listing.new("Seattle") house3 = Listing.new("Vegas") ap1 = Listing.new("L.A.") ap2 = Listing.new("New Orleans") ap3 = Listing.new("NYC") bob = Guest.new("Bob") alex ...
true
4763bdeed52406d571384e5ddf6fb6c82c826c77
Ruby
HuzaifaSaifuddin/blackjack
/dealer.rb
UTF-8
140
2.734375
3
[]
no_license
# Create Dealer class Dealer attr_accessor :full_name, :hand, :score def initialize @full_name = "Dealer" @hand = [] end end
true
3c2551fc67f5cfd7d42b93ee1bd030bb7c2aeca1
Ruby
runt18/rfc
/rfc.rb
UTF-8
14,127
2.609375
3
[ "CC0-1.0" ]
permissive
require 'nokogiri' require 'delegate' require 'forwardable' require 'active_support/memoizable' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/array/grouping' require 'erubis' # This module and accompanying templates in "templates/" ...
true
3d44fa5fd26787a5012c56f0e140d259c728d841
Ruby
jbyrnesshay/launchschool_enrolled
/lesson_2/test.rb
UTF-8
126
3.015625
3
[]
no_license
name = 'billy' def name 'lisa' end def display_name puts name def dingo puts "wawa" end end display_name dingo
true
ea643ee9bfbebb1393dde9f0a9b92276c82b3bd9
Ruby
pracstrat/mym
/app/models/receipt.rb
UTF-8
1,246
2.796875
3
[]
no_license
require 'tesseract' class Receipt < ActiveRecord::Base attr_accessor :ocr_error attr_accessor :from_scan validates :name, :purchase_date, presence: true has_many :line_items, dependent: :destroy after_create do |record| ReceiptMailer.new_scan_notification(record).deliver if record.from_scan end de...
true
dd08b889bbc90d6211574e475498e75e1757d169
Ruby
ecandino/euler
/ruby/problem16.rb
UTF-8
301
3.921875
4
[]
no_license
=begin 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? =end def power_sum(base, exp) total = base ** exp a = total.to_s.split("") a.map!{|i| i.to_i }.reduce{ |sum, i| sum + i } end puts power_sum(2,15) puts power_sum(2,1000)
true
bcd49a0b1ab72c5d1fabca5c73ed65ddfb887197
Ruby
willfowls/prepcourse
/ruby_books/intro_to_ruby/2nd_attempt_at_exercises/19.rb
UTF-8
314
3.671875
4
[]
no_license
# write a method that takes a string as an argu,ent. the method should return a new all caps version of the string # only if the string is longer than 10 characters def capitalize(string) if string.length > 10 puts string.upcase else puts string end end p capitalize('willardelphia')
true
48de77618e5cd4a17be7a4a44b93a3ae86b0d917
Ruby
xiaket/euler-ruby
/31-40/38.rb
UTF-8
1,169
3.375
3
[]
no_license
#!/usr/bin/env ruby # encoding: UTF-8 # Author: Kent Xia/Xia Kai <kentx@pronto.net/xiaket@gmail.com> # Filename: 38.rb # Date created: 2016-08-15 20:40 # Last modified: 2016-08-15 21:11 # # Description: # # if base is a single digit, then it must be 9. for the product is pandigital, # a factor of 9 is ...
true
5b5ccfbd10d4771980469a214f7e7233ca2e0763
Ruby
ccashwell/rpn
/script/tests
UTF-8
582
3.296875
3
[]
no_license
#!/usr/bin/env ruby require_relative "../lib/calculator" puts "Running test cases specified in the requirements..." test_cases = { "5 8 +" => 13, "-3 -2 * 5 +" => 11, "2 9 3 + *" => 24, "20 13 - 2 /" => 3.5 } test_cases.each do |test_case, expected_output| calculator = Calculator.new output = 0 test_ca...
true
b9b8ac4c65b515a8256b39a29c2532ee74eb0d67
Ruby
wdrougas/programming-univbasics-4-square-array-dc-web-102819
/lib/square_array.rb
UTF-8
135
2.96875
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
numbers = [1,2,3] def square_array(numbers) counter = 0 while counter < array.length do puts numbers** counter += 1 end
true
93ae4997eea1362607a93c751a7ec29664d11485
Ruby
vip-ck/Ruby-part3
/Lesson1/1.rb
UTF-8
71
2.578125
3
[]
no_license
file = File.readlines(ARGV.first).map(&:chomp) puts file.shuffle.first
true
68beec2a34791fed2d74bfac19c535eb1f7955e5
Ruby
dpnemergut/csci602
/Assignment3/bdd-cucumber/rottenpotatoes/features/step_definitions/movie_steps.rb
UTF-8
2,029
3.265625
3
[]
no_license
# Add a declarative step here for populating the DB with movies. Given /the following movies exist/ do |movies_table| movies_table.hashes.each do |movie| # each returned element will be a hash whose key is the table header. # you should arrange to add that movie to the database here. Movie.create!(movie)...
true
1c892d3f092882dc91db5b63cbd828fa9638838f
Ruby
joeziemba/write_lab_app
/spec/models/post_spec.rb
UTF-8
1,451
2.734375
3
[]
no_license
require 'rails_helper' RSpec.describe Post, type: :model do it 'should initiate with attributes' do post = Post.new expect(post).to have_attributes(content: nil) expect(post).to have_attributes(character_id: nil) expect(post).to have_attributes(arc_id: nil) end it 'should be invalid without con...
true
671c6b16ccc71b6507b53f455f1f7853b6452dff
Ruby
TeriEich/ar-exercises
/exercises/exercise_5.rb
UTF-8
581
3.109375
3
[]
no_license
require_relative '../setup' require_relative './exercise_1' require_relative './exercise_2' require_relative './exercise_3' require_relative './exercise_4' puts "Exercise 5" puts "----------" # Your code goes here ... @entire_company_revenue = Store.all.sum("annual_revenue") puts "Annual revenue of entire company: #{...
true
78800dc8b9ed0bdd5584f9750e72f839bf84d609
Ruby
rjb16/pub_lab
/specs/pub_spec.rb
UTF-8
714
2.875
3
[]
no_license
require('minitest/autorun') require('minitest/reporters') Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new require_relative('../pub.rb') require_relative('../drink.rb') class TestPub < Minitest::Test def setup() @drink_1 = Drink.new("Beer", 3.5) @drink_2 = Drink.new("Whiskey", 5) ...
true
3788968da5533a4f0802616f7a1f983e7c40d38c
Ruby
vibraniumforge/triangle-classification-v-000
/lib/triangle.rb
UTF-8
685
3.421875
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
require "pry" class Triangle # write code here attr_reader :x, :y, :z def initialize(x,y,z) @x=x @y=y @z=z end def kind validate_triangle if (x.positive? && y.positive? && z.positive? ) && ((@x+@y>@z && @y+@z>@x && @x+@z>@y)) if x==y && y==z :equilateral elsif x==y |...
true
a5c8f323063ebcb60a86c221ce9b92d737baf578
Ruby
searmijo/Programario-Ruby
/Sintaxis_Ruby/io.rb
UTF-8
314
4.5
4
[ "MIT" ]
permissive
#Pide el dato al usuario y lo devuelve en una cadena. print "Dame tu nombre: " nombre = gets puts "Hola #{nombre}" #Contar letras de la cadena: puts "Tu nombre tiene #{nombre.length - 1} letras" #chomp quita el último caracter de la cadena: nombre = nombre.chomp puts "Tu nombre tiene #{nombre.length} letras"
true
1745becb9f8b9dcd3d7a5be23aafa84948c7304b
Ruby
ewlarson/picturepages
/picturepages.rb
UTF-8
3,235
2.671875
3
[]
no_license
# === Author === # * Eric Larson # * UW-Madison Libraries # === License === # * No license # === REQUIREMENTS === # * ruby # * imagemagick # - brew install imagemagick # 1) Set up our directory structure # - british_flora # - british_flora/working # - british_flora/images `mkdir british_flora` `mkdir british_flor...
true
54b7cdd605c46364cd5d5584028389548d9fd07a
Ruby
chelseatroy/first-ruby-programs
/pop_quiz.rb
UTF-8
638
3.921875
4
[]
no_license
@answers_correct = 0 @number_of_questions = 0 def ask_question(question, answer) @number_of_questions = @number_of_questions + 1 puts question user_response = gets.chomp if answer.include?(user_response) @answers_correct = @answers_correct + 1 end end ask_question("How far is it from Earth to the Sun?", ["93...
true
bd0f6b07f4e759c94319eba73ad4a1b0b3a4e859
Ruby
brettapeters/project-euler
/32_regex.rb
UTF-8
708
3.1875
3
[]
no_license
require 'benchmark' solve = Proc.new do two_three = [] one_four = [] (12..98).each do |a| (123..987).each do |b| product = a*b if product <= 9876 && product >= 1234 two_three << "#{a}#{b}#{product}" end end end (1..9).each do |a| (1234..9876).each do |b| product ...
true
9363d0179e7e412d64d63c77361e6fca928cd32f
Ruby
BenTem/contact_list
/contact_list.rb
UTF-8
1,661
3.53125
4
[]
no_license
require_relative 'contact' require_relative 'contact_database' def accept_argv # input = ARGV.shift input = [] while !ARGV.empty? input << ARGV.shift end case input[0] when'help' puts "Here is a list of available commands: new - Create a new contact list - List all c...
true
3d34baff3cfe338931d3282344666d98ea639324
Ruby
norbert/quixotic
/lib/qu/backend/sequel.rb
UTF-8
4,242
2.578125
3
[ "MIT" ]
permissive
require 'sequel' module Qu module Backend class Sequel < Base JOB_TABLE_NAME = :qu_jobs WORKER_TABLE_NAME = :qu_workers attr_accessor :database_url, :poll_frequency def initialize self.database_url = ENV['DATABASE_URL'] self.poll_frequency = 5 end def self.c...
true
8ef159bf5bb746ea30dbd1e7bf03f5bf2981f39a
Ruby
hcbl1212/design_patterns
/singleton/development_logger.rb
UTF-8
287
2.53125
3
[]
no_license
require './custom_logger' class DevelopmentLogger < Logger def initialize(*args, &block) @log = File.open('log/development.log', 'a') end def log information #development log does not need to redact any information logger_mutex { @log.puts information } end end
true
ab47cff1349f06d51fdbe88b75a7304a431af8ed
Ruby
NickPalmucci/coderbyte
/ExOh.rb
UTF-8
140
3.390625
3
[]
no_license
def ExOh(str) @x = str.scan(/[o, O]/).size @y = str.scan(/[x, X]/).size if @x == @y return "true" end if @x != @y return "false" end end
true
795147cc54177160ae01444f4ba7cbb7a9c6ce37
Ruby
mohamednajiullah/go-server-test
/spec/unit/expense_spec.rb
UTF-8
770
3.1875
3
[]
no_license
require 'rspec' require_relative '../../app/person' require_relative '../../app/expense' describe 'Expense' do person_a = Person.new('A') person_b = Person.new('B') person_c = Person.new('C') expense = Expense.new(500, [person_a], [person_b,person_c]) it 'should be able to create an expense with given para...
true
bc2a23039507a9c154727427be7e296887276b8b
Ruby
Elise000/ar_todos
/app/models/task.rb
UTF-8
519
2.921875
3
[]
no_license
require_relative '../../config/application' class Task < ActiveRecord::Base def self.list self.all.each_with_index do |value, index| puts "#{index + 1}. " + value.item + "----->" + "#{value.status}" end end def self.delete(no) task_arr = self.all task_arr[no-1].destroy list end ...
true
db9653dbca2b538405d931c0e67a82a98301feb5
Ruby
puzzle/bleib
/lib/bleib/database.rb
UTF-8
2,448
2.65625
3
[ "MIT" ]
permissive
module Bleib # Finds out if a database is running and accessible. # # Does so by using ActiveRecord without a booted rails # environment (because a non-accessible database can # cause the bootup to fail). class Database def initialize(configuration) @configuration = configuration end def ...
true
b33a666c1a7275bf9566d681ae356e2a132b0112
Ruby
CarlyReiter/ride-share-rails
/app/models/driver.rb
UTF-8
724
3
3
[]
no_license
class Driver < ApplicationRecord has_many :trips, dependent: :nullify validates :name, presence: true validates :vin, uniqueness: true def rating num_trips = self.trips.length ongoing_trips = 0 rating = 0 num_trips.times do |i| if self.trips[i].rating != nil rating += self.trips...
true
496cf278417f3be7e0807c71bde741915d432bef
Ruby
jcovell/my-first-repository
/final_exercises/FinalEx3.rb
UTF-8
208
4.25
4
[]
no_license
# 3.Now, using the same array from #2, use the select method to extract all odd numbers into a new array. arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] new_arr = arr.select do |num| num.odd? end puts new_arr
true
18151e4f256ace613ba845c90a34593f0435e48c
Ruby
danreedy/rspec-html-matchers
/script/assets.rb
UTF-8
658
2.859375
3
[ "MIT" ]
permissive
class Asset @@assets = {} PATH = File.expand_path(File.join(File.dirname(__FILE__),'..','assets','*.html')) def self.[] name @@assets[name.to_s] end def self.<< asset @@assets.merge! asset.name => asset end def self.list @@assets.keys end attr_reader :name def initialize name, path...
true
bfcbddd76fa08b3825b65d50a8155b191c22029c
Ruby
rcjara/project-euler
/6-Problem/ruby/solve.rb
UTF-8
224
3.296875
3
[]
no_license
sum_of_squares = (1..100).inject(0){|sum, num| sum + num ** 2 } square_of_sum = (1..100).inject(0){|sum, num| sum + num } ** 2 answer = square_of_sum - sum_of_squares puts "#{answer} (#{square_of_sum} - #{sum_of_squares})"
true
460a9f73971e677ff0fc3832d9ef565c0ba682ec
Ruby
felix-93/key-for-min-value-prework
/key_for_min.rb
UTF-8
272
3.15625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def key_for_min_value(name_hash) if name_hash == {} return nil elsif minimum = 15 minimumKey = "" name_hash.each do |key, value| if value < minimum minimumKey = key value = minimum end end return minimumKey end end
true
40cd6d1cb438b0860d4dfa4863bf70a64215c9bc
Ruby
joelhelbling/mother
/lib/mother.rb
UTF-8
1,125
3.28125
3
[ "MIT" ]
permissive
require "mother/version" require "mother/collection" require "yaml" require "json" class Mother attr_reader :data def initialize(argument) self.class.argument_failure! unless argument.is_a?(Hash) @data = argument end def [](key) self.class.create ___fetch(key) end def keys self.class.cr...
true
423c5901153e7aa60eca5ecab835f3ea8f9c3bc6
Ruby
Aschnied/ph2-pA-week-1-passion-project
/app/controllers/user.rb
UTF-8
508
2.609375
3
[]
no_license
get '/users' do "show all users" end get '/users/new' do "show html form for creating a new user" end post '/users' do "a new user was just created!" end get '/users/:id' do @user = User.find(params[:user_id]) @decks = @user.decks erb :user end get '/users/:id/edit' do "show a form to edit a user with...
true
129503a8c026550e032066facbd4ec43e7506ade
Ruby
callum-marshall/battle_challenge
/app.rb
UTF-8
618
2.546875
3
[]
no_license
require 'sinatra/base' require_relative 'player' class Battle < Sinatra::Base enable :sessions get '/' do erb :index end post '/names' do $p1 = Player.new(params[:p1_name]) $p2 = Player.new(params[:p2_name]) redirect '/play' end get '/play' do @p1_name = $p1.name @p2_name = $p2.n...
true
022041c0b5b85ee33a8298d8dc2938beab2e82d3
Ruby
coderica/survey_monkey
/source/app/helpers/helpers.rb
UTF-8
225
2.765625
3
[]
no_license
helpers do def login(user) session[:id] = user.id end def logged_in? !!current_user end def current_user @current_user ||= User.find(session[:id]) if session[:id] end def logout session[:id] = nil end end
true
f32b0dfa8315cbc85850460be2ad8ad3aa45aeec
Ruby
vosyk/remote_repository
/ItPwRuby/7-hashes/exer3.rb
UTF-8
184
3.15625
3
[]
no_license
hashtest = { num1: 1, num2: 2, num3: 3 } hashtest.select do |k,v| puts k end hashtest.select do |k,v| puts v end hashtest.select do |k,v| puts "key: #{k} value: #{v}" end
true
3fc5b7f6fe861de238b3698cdc0a3714667f8d7b
Ruby
zhon/metrics
/lib/literalreporter.rb
UTF-8
1,198
3.109375
3
[]
no_license
require 'reporter' class LiteralReporter < Reporter def initialize(collector) @literals = collector.result[LiteralCollector::LITERALS] @total_literals = collector.result[LiteralCollector::TOTAL_LITERALS] end def summary return <<-EOD Literals Summary: Total Literals: #{@total_literals} To...
true
9f33daef92ebda1a9e160b08fa97f875db4459b5
Ruby
foneandrew/nonogram-rails
/app/services/win_game.rb
UTF-8
284
2.984375
3
[ "MIT" ]
permissive
class WinGame def initialize(game:, answer:) @game = game @answer = answer end def call @game.with_lock do if @game.nonogram.solution.eql?(@answer) @game.time_finished = Time.now @game.save! else false end end end end
true
818e61acf927d48eb24ca895e7235d7f604ddbd9
Ruby
kevinladenheim/appr_traffic
/lib/base.rb
UTF-8
835
2.921875
3
[]
no_license
require "typhoeus" class Base attr_reader :data, :message, :code def initialize(cue) @cue = cue @success = false @message = "" @code = "" end def success? @success end private def http_request(url,options = {}) hydra = Typhoeus::Hydra.new request = Typhoeus::Request.new(ur...
true
74a1146fecf239874845c8a46298e9bd07579cd9
Ruby
tim0414/ruby_practice
/singleton_point.rb
UTF-8
449
3.5
4
[]
no_license
#require_relative "point_class" require "singleton" class PointStats include Singleton def initialize @n, @totalX, @totalY = 0, 0.0, 0.0 end def record(point) @n += 1 @totalX += point.x @totalY += point.y end def report puts "number of points created: ...
true
a289020ac47e89b835b5401c57cfe5f9c90c1695
Ruby
dropkickfish/LRTHW
/ex19.rb
UTF-8
1,151
4.375
4
[]
no_license
# defines the cheese_and_crackers function with input variables def cheese_and_crackers(cheese_count, boxes_of_crackers) #puts string including cheese_count variable puts "You have #{cheese_count} cheeses!" #puts string including boxes_of_crackers variable puts "You have #{boxes_of_crackers} boxes of crack...
true
9f811e59b59066f9ec4afabd863ba8947c52d11f
Ruby
hkeefer18/ruby-basics-exercises
/conditionals/4.rb
UTF-8
82
3.53125
4
[]
no_license
boolean = [true, false].sample boolean ? puts('I\'m true!') : puts('I\'m false!')
true
74171a5779b700ed6814226141b99a4e8e3b91e1
Ruby
gabrielbursztein2/urlshortener-backend
/app/models/url_short.rb
UTF-8
518
2.53125
3
[ "MIT" ]
permissive
class UrlShort < ApplicationRecord TOP_AMOUNT = ENV['TOP_AMOUNT'].to_i validates :url, presence: true, uniqueness: true validates :visits, presence: true, numericality: { greater_than_or_equal_to: 0 } after_create :generate_short_url private def generate_short_url range = (('a'..'z').to_a << ('A'..'...
true
0ded33699b49c96982b9534bf4ab8a4c42e0244a
Ruby
neostoic/vouch
/app/models/city.rb
UTF-8
277
2.703125
3
[]
no_license
class City < ActiveRecord::Base attr_accessible :name, :display_name validates_presence_of :name validates_uniqueness_of :name def my_name display_name.present? ? display_name : name end def self.alphabetical self.find(:all, order: "name ASC") end end
true
eebc6c9d1505add520487ffa639e965398af0c3c
Ruby
missamii/GA-Mirror
/w10/Homework/roleplayHW.rb
UTF-8
1,421
3.5
4
[]
no_license
class Being #the first class starts it all off! #a list of symbols attr_accessor :spieces, :gender, :level, :hp, :max_hp, :current_hp #attr_accessor :gender, :spieces #so things aren't change-able, @@count = 0 def initialize( opts = {} ) # variables start here @spieces = opts[:spieces] @gender ...
true
f371b5ef24476c3b04bf2316adad6325d3001f5d
Ruby
mzakany23/farkle
/spec/stats_spec.rb
UTF-8
1,918
3.109375
3
[]
no_license
require_relative '../helper/stats' require_relative '../lib/rules' require_relative '../lib/turn' describe "Stats" do before do @roll = [2,3,4,2,1,5] @arr = [1,2,3,4,5,6,7,8,9,10] @turn = Turn.new(1) @turn.roll end it 's' do turn = Turn.new(1) turn.current_roll = @roll.sort turn.dice_left -= 2 t...
true
b0f5fd34d3b53e11a2d38570fc154b77bac214f1
Ruby
puppetlabs/rototiller
/spec/rototiller/task/collections/options_collection_spec.rb
UTF-8
2,277
2.640625
3
[ "Apache-2.0" ]
permissive
require "spec_helper" module Rototiller module Task # rubocop:disable Metrics/BlockLength describe OptionCollection do context "#allowed_class" do it "allows only Options" do expect(described_class.new.allowed_class).to eql(Option) end end context "#to_s" do ...
true
477b400e2a7e5d5312d29f3c0085f6fc86308d83
Ruby
remieldy/rocket_elevators_machine_learning
/lib/ElevatorMedia/Streamer.rb
UTF-8
918
2.546875
3
[]
no_license
require "rest-client" require 'open_weather' require 'net/http' require 'rest-client' require 'rspotify' class Streamer def getContent(type='weather') getHtmlFromCloud(type) end def getHtmlFromCloud(type) if type == 'weather' return "<div>#{JSON.parse(self.GetCurrentWeathe...
true
406d6e8f8532c5507403b8b15daa54117353fc92
Ruby
hellouniverse26/lec_prev
/w1d5-data-structures/adt.rb
UTF-8
1,250
4.28125
4
[]
no_license
# Abstract Data Types! # STACK # can push/pop or shift/unshift # LIFO: Last In, First Out class Stack attr_reader :elements def initialize @elements = [] end def empty? end def push(el) self.elements.push(el) # specific implementation doesn't matter as long as you're consistent # self.elemen...
true
02adb4a7a6d0ef5da023e4ac0202b3db87be8d3d
Ruby
mikbe/commandable
/spec/source_code_examples/class_methods_nested.rb
UTF-8
676
3.359375
3
[ "MIT" ]
permissive
require "commandable" class ClassMethodsNested class << self extend Commandable command "class foo, look at you!" def class_foo(int_arg1, number_arg2) [int_arg1, number_arg2] end command "classy bar? probably not" def class_bar(int_arg1, string_arg2="Number 42") [int_arg1, ...
true
e61d75f3dddb1203637af238815d813cc1073925
Ruby
buckethead1986/oo-cash-register-web-091817
/lib/cash_register.rb
UTF-8
1,238
3.78125
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require 'pry' class CashRegister attr_accessor :total, :discount def initialize(discount = 0) @total = 0 @discount = discount @items = [] @previous_total = 0 end def add_item(title, price, *quantity) # binding.pry @previous_total = @total #set previous total to total before modifying t...
true
dd1e68bb4468ed7f011fc87a379b5bcaf0cbc4e2
Ruby
yrosenberg1/Classwork_aA
/W4D4/spec/tdd_exercise_spec.rb
UTF-8
2,089
3.796875
4
[]
no_license
require "tdd_exercise" describe "my_uniq" do let(:array) {[1, 2, 1, 3, 3]} it "accepts an array as an argument" do expect{my_uniq(array)}.not_to raise_error end it "returns a new array of the unique elements in the same order of the original array" do expect(my_uniq(array)).to eq([1, 2...
true
111da317cc6ec2d5d4c235f66723d308ea200bc9
Ruby
hannahstwinter/tag_migration
/parse_unique_ddis_from_cass_dump.rb
UTF-8
611
2.8125
3
[]
no_license
require 'json' require_relative 'helper_methods' # json_should_skip - skips if line does not include json # clean - unescapes string and strips whitespace def get_unique_ddis(tags_file, output) ddis = [] tags_file.each do |line| next if json_should_skip line hashed_line = JSON.parse(clean(line)) ...
true
5a9d69c228552dfd604ca8a6508a2b33fb9f764a
Ruby
simplificator/rwebthumb
/lib/rwebthumb/job.rb
UTF-8
6,164
2.671875
3
[]
no_license
module Simplificator module Webthumb class Job < Base attr_reader :duration_estimate, :submission_datetime, :cost, :job_id, :url # Constant for the status attribute when job is beeing processed STATUS_PROCESSING = 100 # Constant for the status attribute when job is done STATUS_PICK...
true
5f343d5a3215b65e21deb98dd96c3af8691335ce
Ruby
007mike/rb101_109_small_problems
/medium1/diamonds2.rb
UTF-8
246
3.84375
4
[]
no_license
def diamond(number) half = number / 2 stars = 1 1.upto(half) do |row| puts ('*' * stars).center(number) stars += 2 end (half + 1).downto(1) do |row| puts ('*' * stars).center(number) stars -= 2 end end diamond(9)
true
4c120ee9b9dd469c65e8592b70eb3152d1a78cdb
Ruby
stukalo/ruby_basics
/home_work.rb
UTF-8
4,237
3.625
4
[]
no_license
class HomeWork # Найти сумму четных чисел def self.get_sum_even start, _end sum = 0 for i in start.._end if i % 2 == 0 then sum += i end end return sum end # Проверить простое ли число? (число называется простым, если оно делится только само на себя и на 1) def self.is_sim...
true
d8ea805d902c990efebadc4ca59284c846ba56f0
Ruby
DentVega/Curso-De-Ruby
/11_clases_y_objetos.rb
UTF-8
1,117
3.78125
4
[]
no_license
# clases y objetos class Persona def initializer(nombre) @nombre = nombre end def nombre=(nombre) @nombre = nombre end def nombre @nombre end def self.suggested_names ["Pepe", "Pepito", "Sutano", "Sutanito"] end end Persona.suggested_names matz...
true
b172398e4e11b4149b23c3f75f297aa69fd2fc2d
Ruby
jdcalvin/mortgage
/lib/mortgage.rb
UTF-8
5,231
2.921875
3
[]
no_license
require 'pry' require 'finance' require 'colorize' class Mortgage include Finance attr_reader :apr, :rate, :amortization, :value, :duration attr_accessor :loan_amount def initialize(apr:, loan_amount:, duration:, value:) @apr = APR.new(apr) @loan_amount = loan_amount @duration = duration @r...
true
a418329e64d52e2b88b7e51be9a670fdfdc51801
Ruby
CelsoDeSa/ecommerce_app
/app/models/produto.rb
UTF-8
1,533
2.515625
3
[]
no_license
class Produto < ActiveRecord::Base include PgSearch pg_search_scope :search, against: :descricao, using: { tsearch: { dictionary: "portuguese" } } def self.import(file) spreadshee...
true
8b1a02519a3d28d957decb5e25aeb0874b27671d
Ruby
atton/AtCoder
/AC/008D.rb
UTF-8
346
2.984375
3
[]
no_license
# -*- coding: utf-8 -*- all_takoyaki = [1] N,M = gets.chomp.split(" ").map{|a|a.to_i} machines = Array.new(N, [1,0]) M.times do update = gets.chomp.split(" ").map{|a|a.to_f} machines[update[0]-1] = [update[1], update[2]] all_takoyaki.push machines.inject(1.0){|stat,m|stat * m[0] + m[1]} end puts all_takoyaki....
true
f911fd4f63e4336b5588d66feda55b785abe89c8
Ruby
lucademontis/restaurantbnb
/app/models/booking.rb
UTF-8
694
2.796875
3
[]
no_license
class Booking < ApplicationRecord belongs_to :user belongs_to :restaurant validates :number_of_people, presence: true validates :start_date, presence: true validates :end_date, presence: true validate :dates # validates :end_date, presence: true, end_date: { after_or_equal_to: :start_date} def dat...
true
850d5490946a635bc4800113c67ebb81c1a446d4
Ruby
TheRusskiy/ParkingSimulator
/src/road/road.rb
UTF-8
5,988
2.875
3
[]
no_license
class Road require_relative 'state' require_relative 'distance_calculator' require_relative '../exceptions/accident_exception' require_relative '../exceptions/car_added_twice_exception' require 'awesome_print' include Math attr_reader :length, :cars, :angle attr_accessor :parking_lot attr_accessor :sp...
true
3a9238fc73d8beeb106d361daecc66614814715f
Ruby
philest/yale_athletics_data
/yale_athletics_app/app/models/rosters_students_through.rb
UTF-8
448
2.53125
3
[ "MIT" ]
permissive
class RostersStudentsThrough < ApplicationRecord require 'csv' # associations has_one :roster has_one :student # imports csv file into db def self.import csv_text = File.read('../data/processed/rosters_players_processed.csv') csv = CSV.parse(csv_text, headers: true) csv.each do |row| Ros...
true
2085241fde1e153960cbb3e3d93b06542f9134c6
Ruby
VIMVIW/rubyrush
/steps/arrays-thread-02/solution/array.rb
UTF-8
1,115
3.703125
4
[]
no_license
# encoding: utf-8 # Создаем исходный массив и записывем в переменную numbers numbers = [1, 2, 3, 4, 5] # Выводим исходный массив на экран puts 'Исходный массив:' puts numbers.to_s # Получаем перевернутый массив методом reverse (при этом сам массив numbers # остается прежним) и выводим его на экран puts 'Массив в обр...
true
904c1f649cf3f654f97599357b2397d8dd1ae073
Ruby
MariKats/object-relations-assessment-final-web-040317
/app/models/movie.rb
UTF-8
539
3.171875
3
[]
no_license
class Movie attr_accessor :title ALL = [] def self.all ALL end def initialize(title) @title = title ALL << self end def self.find_by_title(title) Movie.all.find {|movie| movie.title = title} end def ratings Rating.all.find_all {|rating| rating.movie == self} end def viewe...
true
7d8363ea05126abde62d98cd01c8dac27b9125ad
Ruby
enova/katas
/prerequisites/course_library.rb
UTF-8
12,294
2.890625
3
[ "MIT" ]
permissive
require "forwardable" require_relative "course" class CourseLibrary include Enumerable extend Forwardable def_delegators :@courses, :each, :to_a def initialize(courses = nil) @courses = courses || COURSES end def [](name) @courses.find { |c| c.name.to_s.upcase == name.to_s.upcase } end end CO...
true
7d75ee11f17c1e96486e4501f0cc6a8a8ad795fd
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/word-count/b329cfe583124236b19abfaf62ad35eb.rb
UTF-8
265
3.4375
3
[]
no_license
class Phrase def initialize(phrase) @words = phrase_to_array(phrase) end def word_count @words.each_with_object(Hash.new(0)){ |word, hash| hash[word] += 1 } end private def phrase_to_array(phrase) phrase.downcase.split(/\W+/) end end
true
cfe55d95bbe2995ab4e2abb9cce9287094d5ad83
Ruby
esumerfd/Active-Model-Command
/lib/active_model_command.rb
UTF-8
1,100
2.75
3
[]
no_license
# # Allow commands to be created and set on models for integration with the model # lifecycle events. # # class MyModel # extend ActiveModelCommand # after_save_command :send_emails # end # # class MyController # def create # my = MyModel.new # my.send_emails = SendEmailCommand.new(current...
true
033e11f8f223166dfb4ed0899eefa36c19d7f004
Ruby
mcouraud/immoscan
/db/seeds.rb
UTF-8
2,503
2.625
3
[]
no_license
require 'dbf' data = File.open('public/france2016.dbf') widgets = DBF::Table.new(data) widgets.each do |record| City.new(name: "#{record['NCC']}", ci:"#{record['DEP']}0#{record['COM']}") end # require 'open-uri' # require 'nokogiri' # require 'json' # puts "dans quelle ville cherchez vous ?" # ville = gets.ch...
true
128aa24f31f7973d6d93c6ab1a91d17b709d08a2
Ruby
windeye/casekit
/em/defer.rb
UTF-8
167
2.578125
3
[]
no_license
require 'eventmachine' EM.run do op = proc do 3+3 end callback = proc do |count| puts "3+3 = #{count}" EM.stop() end EM.defer(op,callback) end
true
25c92cefcfbf75182ddde8434bf2f421cc5d003f
Ruby
cyrusinnovation/ratgraph
/lib/csv_processor.rb
UTF-8
2,043
2.765625
3
[ "MIT" ]
permissive
require 'csv' require 'set' demographics = CSV.read('../source/data/nyc_zip_demographics.csv', headers:true) index = Hash.new demographics.each do |row| index[row['zip_code']] = row end errors = CSV.open('../source/data/error_log.csv', 'w') bad_dates = CSV.open('../source/data/bad_dates_log.csv', 'w') CSV.open('../...
true
8b2737689963518fb8f7d50584c818ebae5061d7
Ruby
tashua314/gcs_api_gem
/lib/gcs_api_gem/search_api.rb
UTF-8
2,268
2.875
3
[ "MIT" ]
permissive
module GcsApiGem # SearchApi class SearchApi # Decide to what range of page you want to acquire SEARCH_RANGE = 3 def initialize @items = [] @search_result = nil @keyword = nil @start_index = nil end # Select one piece randomly from images searched by keyword def ran...
true
4a46e2c5b1bc3cd5a51d5b43ba70be7df0fb67bf
Ruby
Retechnica/clusterer
/tests/inverse_document_frequency_test.rb
UTF-8
2,931
2.53125
3
[ "MIT" ]
permissive
#-- ###Copyright (c) 2006 Surendra K Singhi <ssinghi AT kreeti DOT com> # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use...
true
bb6e7c8c387f50079b0c6b65f2e0d1a0c8a66ad3
Ruby
VINichkov/jobs_channel
/app/keyboard/callbacks.rb
UTF-8
923
2.6875
3
[]
no_license
module Callbacks class Like LIKE = 'like' attr_reader :text, :id def initialize(text = nil, id: nil) if text.present? begin params = JSON.parse(text, opts={symbolize_names:true}) @action = params[:action] @count = params[:count] @text = params[:text] ...
true
474d8d9b21fef59507cd2ddbc01b69dd9f4ffb94
Ruby
k-coffee/atcoder
/Beginner27/4-3.rb
UTF-8
623
3.25
3
[]
no_license
#!/usr/bin/ruby -Ku x = gets().chomp.split(//) score = Array.new() count = 0 x.each_with_index do |tmp, i| if tmp == "+" for j in 0..count-1 score[j] += 1 end end if tmp == "-" for j in 0..count-1 score[j] -= 1 end end if tmp == "M" count += 1 score << 0 end end if ...
true
38440254c38f846ed278b28939f3f95b2e112976
Ruby
economica-zz/funglish
/app/utils/utils.rb
UTF-8
526
2.640625
3
[]
no_license
class Utils CACHE_KEY_CHOICES = "_choices" class << self def get_choices(class_name, order) cache_key = class_name + CACHE_KEY_CHOICES choices = Rails.cache.read(cache_key) if choices.blank? choices = get_mst_records(class_name, order).map {|i| [i.name, i.id]} Rails.cache.wr...
true
03f1001e32a0aefea7bd176ba64409558b2c05cc
Ruby
nevans/state_chart
/lib/state_chart/attrs/initial_state.rb
UTF-8
1,622
2.609375
3
[ "MIT" ]
permissive
# frozen_string_literal: true module StateChart module Attrs module InitialState def initialize(*args, initial: nil, **opts, &block) self.initial = Transition.new(nil, target: initial) if initial super(*args, **opts, &block) end # @return [Transition,nil] an initial state tra...
true
f7423a83f8b180f8012e9cad5d219a47831218f7
Ruby
the-color-bliu/backend_mod_1_prework
/day_4/exercises/methods_and_return_values.rb
UTF-8
742
4.5
4
[]
no_license
def add(a, b) puts "ADDING #{a} + #{b}" a + b end def subtract(a, b) puts "SUBTRACTING #{a} - #{b}" a - b end def multiply(a, b) puts "MULTIPLYING #{a} * #{b}" a * b end def divide(a, b) puts "DIVIDING #{a} / #{b}" a / b end puts "Let's do some math with just some functions!" age = add(25, 5) he...
true
ed5900592a407183b5a6ee0798d2aefe74042ba9
Ruby
HartasCuerdas/MADinfo
/shot_csv.rb
UTF-8
113
2.671875
3
[]
no_license
load 'process_csv.rb' def shot_csv(filename) data = IO.readlines(filename) process_csv(data) puts '' end
true
dbc2908803fcd341d20b73cd3334104c5f270fc4
Ruby
JoshCheek/rack-josh
/lib/rack/josh/dev_reload2.rb
UTF-8
2,555
2.578125
3
[]
no_license
module Rack module Josh class DevReload2 def initialize(app, to_require) @app = app @to_require = to_require @prev_added_constants = [] @prev_added_loaded_features = [] end def call(env) # remove prev additions...
true
58317c72d0803b428298be43cb7f4a558b3ca767
Ruby
cupakromer/code-puzzles
/spec/project_euler/p5_smallest_multiple_spec.rb
UTF-8
1,086
3.734375
4
[]
no_license
# 2520 is the smallest number that can be divided by each of the numbers from 1 # to 10 without any remainder. # # What is the smallest positive number that is evenly divisible by all of the # numbers from 1 to 20? require 'prime' Factor = Struct.new(:base, :power) do def self.to_proc ->(ary){ self.new *ary } ...
true
e8e0ec96f7d74ad493c835f1c51deea0c053f831
Ruby
emmajhf/apply-for-postgraduate-teacher-training
/app/presenters/candidate_interface/personal_details_review_presenter.rb
UTF-8
2,446
2.53125
3
[]
no_license
module CandidateInterface class PersonalDetailsReviewPresenter def initialize(form:, editable: true) @form = form @editable = editable end def rows [ name_row, date_of_birth_row, nationality_row, english_main_language_row, language_details_row, ...
true
6ad09adb5a989e0e96c3fb4077fbc766b5007904
Ruby
NinjaButtersAATC/admintocrm-migration
/app/models/store.rb
UTF-8
576
2.546875
3
[]
no_license
class Store < ActiveRecord::Base has_many :orders, foreign_key: :store_id validates :name, presence: true def self.determine_store_name(admin_order) name = admin_order.ship_method if name.nil? || !name.downcase.include?("ypsi") return "Ann Arbor T-shirt Company" else return "Ypsilanti T...
true
ab342354f80287b1f6e961e6f3a8f69ba9d3252f
Ruby
hieroglyphical/CSC-450-Project
/simulation/lib/hero.rb
UTF-8
3,423
3.703125
4
[]
no_license
=begin This class mocks the abilities of a hero in the game and keeps track of all importan hero data. =end class Hero attr_accessor :name attr_accessor :hero_class attr_accessor :health attr_accessor :amour attr_accessor :attack attr_accessor :weapon attr_accessor :hand attr_accessor :deck attr_acc...
true