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
655cd1123b8309c7184640ace1e4065b2428f07a
Ruby
pluce/hoze
/lib/hoze/pubsub/source.rb
UTF-8
1,691
2.734375
3
[ "MIT" ]
permissive
require "hoze/interface/source" require "hoze/interface/source_error" require "hoze/pubsub/message" module Hoze class PubSubSource < Source attr_reader :topic, :subscription, :max_tries def initialize configuration @engine = Google::Cloud::Pubsub.new( project: configuration.connector.project...
true
3de079b5c7b52122ef9f637f73ba35497acee026
Ruby
ClawdStrife/simple-rock-paper-scissors-game
/animal.rb
UTF-8
445
4.21875
4
[]
no_license
class Animal #classes start with capitals def initialize(speech) @speak = speech end def speak puts @speak end def breathe #methods go in all lower case puts "*Heavy breathing*" end def sleep puts "ZZZzzzZZZ" end def eat puts "OmNomNom" end end dino =...
true
27a030d19d9e8725ea5a890bce4951e1d4b14422
Ruby
lf261/ruby-oo-self-person-lab-wdc01-seng-ft-060120
/lib/person.rb
UTF-8
1,920
4.03125
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# your code goes here require "pry" class Person #initialize with name that cannot be changed, and $25, 8 happiness, 8 hygiene, def initialize (name, bank_account = 25, happiness = 8, hygiene = 8) @name = name @bank_account = bank_account @happiness = happiness @hygiene = h...
true
d89b0f5d7e9220c072a9d020ade770930e637de6
Ruby
AlbatrosENF/enf
/test/models/user_test.rb
UTF-8
519
2.5625
3
[]
no_license
require 'test_helper' class UserTest < ActiveSupport::TestCase test "validates presence of first and last name" do user = User.new( email: "foo@bar.com", password: "foo_bar", password_confirmation: "foo_bar" ) refute user.valid? user.first_name = "John" refute user.valid? ...
true
700f6a983f4665c3aa109ee373ab3840ae34ba80
Ruby
daigaku-ruby/daigaku
/lib/daigaku/window.rb
UTF-8
2,693
3.0625
3
[ "MIT" ]
permissive
require 'curses' require 'daigaku/coloring' require 'daigaku/markdown' module Daigaku class Window < Curses::Window include Coloring def initialize(height = Curses.lines, width = Curses.cols, top = 0, left = 0) super(height, width, top, left) init_colors end def write(text, color = COLO...
true
6e5b1d4d40b98b5d39b0ab3e4f78dcc4095ee2b3
Ruby
zhengt4869/programming-univbasics-4-array-concept-review-lab-online-web-prework
/lib/array_methods.rb
UTF-8
679
3.59375
4
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
def find_element_index(array, value_to_find) # Add your solution here array.length.times do |index| if array[index] == value_to_find return index end end return nil end def find_max_value(array) if not array return nil end initialized = array[0] array.length.times do |index| i...
true
44de01ff04e73ae9298b608032442b73f3d24c2b
Ruby
blake-education/sucker_punch
/lib/sucker_punch/queue.rb
UTF-8
637
2.78125
3
[ "MIT" ]
permissive
module SuckerPunch class Queue attr_reader :name def initialize(name) @name = name end def self.[](name) Celluloid::Actor[name] end def register(klass, size, args=nil) Celluloid::Actor[name] = if size klass.send(:pool, size: size, args: ar...
true
798a38bccc8b988889c51755d85cad374752a98c
Ruby
smcunning/refactoring_patterns
/hide_delegate.rb
UTF-8
249
2.953125
3
[]
no_license
class Plane attr_reader :engines def initialize @engines = Array.new(4){ Engine.new } end end class Engine def start @running = true end def running? !!@running end end dusty = Plane.new dusty.engines.each{|e| e.start}
true
27996fca7481a6b7fdb31f2a2f6793b0a01e9b1e
Ruby
connor-t/code-test
/spec/checkout_spec.rb
UTF-8
1,834
2.78125
3
[]
no_license
require_relative '../lib/checkout.rb' describe 'Checkout' do let(:promotional_rules) do { '001' => { amount: 2, price: 8.50 }, total_spend: { amount: 60, discount: 10 } } end let(:co) { Checkout.new(promotional_rules) } let(:item) { Product.new('001', 'chair', 9.25) } let(:item_2) { Product.new('00...
true
925b4c56aada2547c4d6e28e98eb84d74fd93938
Ruby
s-shimko/ruby_learn
/lesson7/task7_3.rb
UTF-8
1,169
3.390625
3
[]
no_license
# Возьмите вашу игру, которую вы сделали в домашнем задании к уроку про «южное бутово» # (если не делали — самое время сделать). # В этой игре теперь защитите программу от неправильного ввода вариантов. # То есть если программа просит выбрать 1. ... 2. ... или 3. ... , # а пользователь вводит 7 или вообще посторонние с...
true
c649919b834e6c5182929b917b2bcf1438d50403
Ruby
elevatesystems/panomosity
/lib/panomosity/optimisation_variable.rb
UTF-8
1,756
2.828125
3
[ "MIT" ]
permissive
module Panomosity class OptimisationVariable START_LINE = 'v' @@attributes = %i(w h f v Ra Rb Rc Rd Re Eev Er Eb r p y TrX TrY TrZ Tpy Tpp j a b c d e g t Va Vb Vc Vd Vx Vy Vm n) def self.parse(pto_file) @optimization_variables = pto_file.each_line.map { |line| parse_line(line) }.compact end ...
true
b40f1b8cc7fddbc3a20d515a4e9df914c29ea22a
Ruby
senthilnayagam/training-ruby
/raj/prime.rb
UTF-8
215
3.90625
4
[ "MIT" ]
permissive
#Program to check the given number is prime or not puts "Enter a number to check:" n=gets.to_i for i in 2..n/2 flag=0 if n%i == 0 puts "num is not a prime" flag=1 break puts "num is prime" end
true
0e144711be20a1d41f59179e56c24aefb72635af
Ruby
sansuaza/RubyUdemy
/section17/Intro_Regular_Expression.rb
UTF-8
1,132
3.59375
4
[]
no_license
frase = "03 Frase pa a analizarla con una expresion regular. Tel: 212 312 1233" p frase =~ /F/ # muestra 0, que la posicion en la que encuentra el caracter p frase =~ /./ # Da 0, en expresiones regulares, el punto significa cualquier caracter. p frase =~ /w/ # da nil, no hay una w en la frase #Scan mehtod : Cantida...
true
9a2798074ab7af813370a93a36915c9ec737e147
Ruby
TedsTech/BeginningRuby
/Integer_class2_methods.rb
UTF-8
1,105
4.5625
5
[]
no_license
#Integer Methods #even - return true if the integer value is even age = 22 puts age.even? #odd - return true if the integer value is odd number = 10 puts number.odd? #to_s - converts the integer value into string value no_of_apple = 5 puts no_of_apple puts no_of_apple.class puts "..................." puts no_of_app...
true
4235f559b588f5b9904996b02c76946186ec397b
Ruby
grent/cosc480-homework2
/app/controllers/movies_controller.rb
UTF-8
1,855
2.5625
3
[]
no_license
# in app/controllers/movies_controller.rb class MoviesController < ApplicationController def index #redirect to previous session settings if new sort and ratings parameters aren't specified if params[:sort].nil? && params[:ratings].nil? && (!session[:sort].nil? || !session[ratings].nil?) flash.keep redirect_t...
true
213674b6dd0a5e00c03bc3cfe7af2d79cf036310
Ruby
hhorace/SOA_flip_flap
/tsv_buddy.rb
UTF-8
1,704
3.453125
3
[]
no_license
# frozen_string_literal: true # Module that can be included (mixin) to take and output TSV data module TsvBuddy # take_tsv: converts a String with TSV data into @data # parameter: tsv - a String in TSV format def take_tsv(tsv) people = split_string(tsv) @data = [] colname = [] people.each_with_in...
true
8c5cab7c08b192393cce5eee74387923bd53f98a
Ruby
tlanderstx/interpolation-super-power-q-000
/lib/display_rainbow.rb
UTF-8
234
3.28125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# Write your #display_rainbow method here def display_rainbow (display_colors = (['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])) puts (["R: red, O: orange, Y: yellow, G: green, B: blue, I: indigo, V: violet"]) end
true
e57c0a70617f520df24492ee2ee41465d6d83b26
Ruby
cooperka/nemo
/app/models/results/web_response_parser.rb
UTF-8
4,031
2.515625
3
[ "Apache-2.0" ]
permissive
# frozen_string_literal: true module Results # Builds (does not save) an answer tree based on answer data in a web response. class WebResponseParser TOP_LEVEL_PARAMS = %w[ type id questioning_id value option_node_id datetime_value(1i) datetime_value(2i) datetime_...
true
afc23df6a3f89c62031bf31d4535277fd8d3a43c
Ruby
gersmann/wisper
/lib/wisper/registration/registration.rb
UTF-8
592
2.734375
3
[ "MIT" ]
permissive
module Wisper class Registration attr_reader :on, :listener def initialize(listener, options) @listener = listener @on = Array(options.fetch(:on) { 'all' }).map(&:to_s) end def listener case @listener when Class clazz = Kernel.const_get(@listener.to_...
true
0eaed5c75a4d15eef779d9853fd6b375fba06881
Ruby
denniskeefe/learn_ruby
/00_hello/hello.rb
UTF-8
90
2.671875
3
[]
no_license
#write your code here def hello "Hello!" end def greet(who) "Hello, #{Alice}!" end
true
0be2f412134038fc00caffb0a78af6d50e4ca822
Ruby
Amoncio/craps
/lib/craps.rb
UTF-8
982
3.40625
3
[]
no_license
module Lib class Craps require_relative "dice" attr_reader :win_state, :rolls def initialize @rolls = [] end def start_game # Reset win state whenever we start a new game self.win_state = nil roll = roll_2d6 if seven_eleven?(roll) self.win_state = true ...
true
0166f703baef4278bca5ea82eb7de8d7d97b090a
Ruby
danyell85/phase-0
/week-4/concatenate-arrays/my_solution.rb
UTF-8
242
3.375
3
[ "MIT" ]
permissive
# Concatenate Two Arrays # I worked on this challenge by myself # Your Solution Below # def array_concat(array_1, array_2) # return array_1 + array_2 # end def array_concat(array_1, array_2) array_1.concat(array_2) end
true
ce2e4d190c98438d3a41d84ba34b1a47006d7aec
Ruby
vkamayiannis/Ruby-examples
/revsent.rb
UTF-8
157
3.78125
4
[]
no_license
print "Type a sentence: " sentence = gets.chomp print "Type a number: " number = gets.chomp.to_i i = 1 while i <= number puts sentence.reverse i += 1 end
true
3a3477f7ea170384e13de39df20a3d614a5131a0
Ruby
ArcadG/task
/task_2/purchase.rb
UTF-8
632
3.484375
3
[]
no_license
basket = {} loop do print 'Введите название товара,чтобы закончить введите стоп: ' name = gets.chomp break if name == 'стоп' print 'Введите кол-во: ' quantity = gets.chomp.to_f print 'Введите цену за ед.: ' cost = gets.chomp.to_f basket[name] = { 'quantity' => quantity, 'cost' => cost } end puts bask...
true
a9c94a12aabfa4c3310cec5c289772799fcf5801
Ruby
polyfox/moon-packages-mock
/spec/moon/mock/vector4_spec.rb
UTF-8
1,611
2.71875
3
[]
no_license
require 'spec_helper' require 'moon-mock/vector4' describe Moon::Vector4 do context '#[]' do it 'converts the given object(s) to a Vector4' do v1 = described_class[1] v3 = described_class[[1, 2], 3, 4] v2 = described_class[1, [2, 3, 4]] v4 = described_class[[1, 2, 3, 4]] v5 = descri...
true
b46afad4a46ff575175539df472dae6ff714c8b9
Ruby
oshino-taihei/mybooklog
/spec/models/review_spec.rb
UTF-8
5,303
2.625
3
[]
no_license
require 'rails_helper' describe Review, type: :model do describe '検索ができること' do it 'タイトルで検索ができること' do book1 = create(:book, title: 'プログラミング言語Ruby') book2 = create(:book, title: 'プログラミング言語Java') book3 = create(:book, title: 'Effective Ruby') review1 = create(:review, book: book1) revi...
true
cb0bf06143f6e7641675e804f06f1e5a280dcf06
Ruby
grasp/small_fish
/lib/30_signal_gen/macd_signal.rb
UTF-8
6,267
3.015625
3
[ "MIT" ]
permissive
require File.expand_path("../read_data_process.rb",__FILE__) #判断后退几天ma 信号 ##MACD 1,2,3,4,5,10,20,30,60,100,120,200 def judge_macd_signal(t_ma_array,y_ma_array,back_day) #t_ma_array=[] #full_macd_array[back_day][1].each {|i| t_ma_array<<i.to_f}#当天的macd数组 #y_ma_array=[] #full_macd_array[back_day+1][1].each {|i| ...
true
2c9c45bb947aab4234d585cc5bb08d7fbab966cc
Ruby
psuchatohuskers/CSCE155T
/theater_light.rb
UTF-8
4,537
3.40625
3
[]
no_license
class Light def on_off() if @switch == 1 return "on" else return "off" end end end class Fix < Light def initialize(input,red,blue,green) @switch = input @red_light = red @blue_light = blue @green_light = green end def fix_color() if @switch == 1 if @red...
true
8adc5170e1fbc925d37bfe1b5a362461d29b1965
Ruby
jefflunt/cortex
/app/models/stat.rb
UTF-8
540
2.6875
3
[]
no_license
class Stat < ActiveRecord::Base validates :group, :presence => true validates :name, :presence => true validates :name, :uniqueness => { :scope => :group } validates :value, :presence => true def self.increment(group, name) stat = get_stat(group, name) stat.update_attribute(:value, stat.value+1) ...
true
138389b745d5a9c3b49d034c95e28f674297e389
Ruby
agusgs/bike-store
/app/serializers/order_customized_area_serializer.rb
UTF-8
765
2.59375
3
[ "MIT" ]
permissive
class OrderCustomizedAreaSerializer attr_reader :order_customized_areas, :deep def self.serialize(order_customized_areas, deep = false) new(order_customized_areas, deep).serialize end def initialize(order_customized_areas, deep) @order_customized_areas = order_customized_areas @deep = deep end ...
true
bd7021e89f44eda80aa7799aca02d81888281fb4
Ruby
semdinsp/smsc_manager
/lib/smsc_manager/sms.rb
UTF-8
2,742
2.921875
3
[]
no_license
require 'rexml/document' # Sms stuff for handling sms require 'rubygems' gem 'stomp_message' require 'stomp_message' module SmscManager class InvalidPrefix < RuntimeError end # this class defines creating a sms # and strips out the unnecessary junk class Sms @@MAX_SIZE=1500 # 3*160 # max 1500 characters, change if...
true
7caa65114a514c4b16b3869e20ea8463391ecd2a
Ruby
Monkee45/Library
/bin/read_file.rb
UTF-8
145
3.140625
3
[ "LicenseRef-scancode-other-permissive" ]
permissive
require 'CSV' libraries = [] all_books = CSV.read('.\books.csv') all_books.each do |book| libraries << book.first(2) end puts libraries.uniq
true
6aece38c402554dc38925ab0edaa3397a957b054
Ruby
finbarr/t
/lib/t/collectable.rb
UTF-8
272
2.59375
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
module T module Collectable def collect_with_cursor(collection=[], cursor=-1, &block) object = yield cursor collection += object.collection object.last? ? collection : collect_with_cursor(collection, object.next_cursor, &block) end end end
true
b45398f6e6d82c3085f3964c4de4c895564f87f0
Ruby
EHale64/first_non_repeater
/test/first_non_repeat_test.rb
UTF-8
790
2.953125
3
[]
no_license
require 'minitest/autorun' require 'minitest/pride' require 'json' require 'pry' require_relative '../lib/first_non_repeat' class FirstNonRepeatTest < MiniTest::Test def setup @first = FirstNonRepeat.new end def test_it_returns_a_character assert_equal 'a', @first.first_non_repeater('a') ...
true
a6b9cfb91a90cf02a3a980f04dd1d4eb33d3488a
Ruby
madebydna/true_paradox
/scripts/unification-migration
UTF-8
2,966
2.984375
3
[ "MIT" ]
permissive
#!/usr/bin/env ruby # Use this script to convert a content directory containing separate # articles/ and categories/ directories into the new and improved way of # doing things, where everything is a page... # # If you're using git it'll add your changes to your git repository # for you (but you'll need to commit them...
true
d50932571f4be41fa951e1bcb7c29611e1f526db
Ruby
lngrss/ruby_in_games
/connect_four/game.rb
UTF-8
1,234
3.734375
4
[]
no_license
class Game attr_reader :players attr_reader :board def initialize(player_1, player_2) @players = [player_1, player_2] @board = Board.new(7) @message = nil end def play until @message keep_moving end @board.print_board puts @message end def keep_moving players.each ...
true
45a8731b70cae9083aa78f3806986e84e370a933
Ruby
AnjanaLP/student-directory
/directory_extras.rb
UTF-8
2,704
4.34375
4
[]
no_license
require "csv" @students = [] # an empty array accessible to all methods def print_menu puts "1. Input the students" puts "2. Show the students" puts "3. Save the list to a file" puts "4. Load the list from a file" puts "9. Exit" # 9 because we'll be adding more items end def interactive_menu loop do ...
true
3f456648261625d68915a7ff968c208403af3352
Ruby
RuxaiNezers/CLASS16-Exam
/menu.rb
UTF-8
2,117
3.71875
4
[]
no_license
def file_grades file = File.open('notas.csv', 'r') content = file.readlines file.close content end def file_average file = File.open('Promedios.csv', 'r') content = file.readlines file.close content end def menu puts 'Ingrese 1 para generar archivos con los promedios de cada alumno' puts 'Ingrese ...
true
1e1c187a3cd0a65ecec3ed800f41aca48a568007
Ruby
JoergReinhardt/hannemann
/app/models/blogpost.rb
UTF-8
914
2.53125
3
[]
no_license
class Blogpost < ActiveRecord::Base attr_accessible :bild_id, :inhalt, :titel, :url_slug def to_param url_slug end belongs_to :user before_validation :create_slug validates :user_id, presence: true validates :titel, presence: true validates :url_slug, presence: true, uniqueness: true validate...
true
ad0c6fd859e2462a22f1be389be6892e5f971122
Ruby
lacf95/Instagramo
/app/analyzers/colorscore_analyzer.rb
UTF-8
745
2.65625
3
[]
no_license
# frozen_string_literal: true # Extracts image color information class ColorscoreAnalyzer < ActiveStorage::Analyzer::ImageAnalyzer def metadata read_image do |image| data = {} data = data.merge(colors: image_colors(image.path)) data = if rotated_image?(image) data.merge(width: i...
true
c73f4f78c470cdceaff2a37939d61e2a3d752e74
Ruby
anolson/joule
/lib/joule/csv.rb
UTF-8
442
2.609375
3
[ "MIT" ]
permissive
require 'fastercsv' require 'joule/csv/parser' module Joule module CSV FILE_EXTENSION = ".csv" def CSV.is_csv_file(extension) extension.eql?(FILE_EXTENSION) end def CSV.parser(extension, data) header = FasterCSV.parse(data).shift if header[0].to_s.downcase.eql?("ibike") ...
true
e1ebb25a69b53944db199c7d38e055e27c3be440
Ruby
akutarba/courses
/lesson1/quadratic_equation.rb
UTF-8
2,596
3.796875
4
[]
no_license
=begin Квадратное уравнение. Пользователь вводит 3 коэффициента a, b и с. Программа вычисляет дискриминант (D) и корни уравнения (x1 и x2, если они есть) и выводит значения дискриминанта и корней на экран. При этом возможны следующие варианты: Если D > 0, то выводим дискриминант и 2 корня Если D = 0, то выводим дис...
true
759aa3d5058f5c5205a4acdee713bd8a7386953d
Ruby
Mia-J-Russell/LaunchSchool
/RB101/small_problems/easy_7/capitalize_words.rb
UTF-8
744
3.765625
4
[]
no_license
def word_cap(string) # array = string.split(' ') # array.each do |x| # x.capitalize! # end # array.join(' ') #string.split(' ').map {|x| x.capitalize!}.join(' ') #Further Exploration # array = string.split(' ') # array.each do |x| # x.downcase! # x[0] = x[0].upcase! unless x[0] =~ /[^a-...
true
764a93df71419ce19ad6bed9498c01f0f1637406
Ruby
stephaniejn/rio_grande_lab
/lib/EBook.rb
UTF-8
234
2.609375
3
[]
no_license
require_relative 'DigitalItem.rb' class EBook < DigitalItem attr_accessor :author, :page, :download_size def initialize name, price, download_size = 0 super(name,price,download_size) @author = "" @page = "" end end
true
a5ea0e5f0bc3cb6f9e697c9e713bba9dd57563d2
Ruby
MelanieJae/HackerRank-challenges
/day6strings.rb
UTF-8
338
3.28125
3
[]
no_license
puts "enter string:" s = gets.chomp arr = [] arr = s.scan /\w/ arr.each_index do |i| @arreven = arr[0] @arrodd = arr[1] if i > 1 if i % 2 == 0 @arreven.concat( arr[i] ) else @arrodd.concat( arr[i] ) end end end puts "#{@arreven} #{@arrodd}" T=gets.to_i for i in (1..T)do...
true
56b69e34d7c4985879a549a41f091dfab3031a8b
Ruby
ninamutty/list-implementations
/linked-list.rb
UTF-8
3,577
4.6875
5
[]
no_license
# Quick Example of a Self Referential Data Structure in Ruby # NODE -> contains a value and a pointer to (next_node) # LinkedList -> This class holds the linked list functions - adding a node, traversing and displaying the linked list class Node attr_accessor :value, :next_node def initialize(val,next_in_line=n...
true
2b412fb4594e5ee707baa7c56156f68b2154a64f
Ruby
mintona/adopt_dont_shop_part_two
/spec/models/pet_application_spec.rb
UTF-8
1,918
2.515625
3
[]
no_license
require 'rails_helper' RSpec.describe PetApplication, type: :model do describe 'relationships' do it {should belong_to :pet} it {should belong_to :application} end describe 'model methods' do before :each do @shelter_1 = Shelter.create(name: "Boulder Shelter", ...
true
b4fc82d087533c0cc64a347c90958836417da3a2
Ruby
fuchssarahe/BenchBnB
/app/models/bench.rb
UTF-8
608
2.609375
3
[]
no_license
class Bench < ActiveRecord::Base validates :description, :lat, :lng, presence: true def self.in_bounds(bounds) if bounds upper_bounds = bounds['NE'] lower_bounds = bounds['SW'] bounds_options = { upper_bound_lat: upper_bounds['lat'], lower_bound_lat: lower_bounds['lat'], ...
true
1f3d2a100a0b0e7954b48108ec46217fea96e3eb
Ruby
jtlai0921/PG20249_example
/PG20249_sample/Ruby268-SampleProgram-UTF8/Ch2/sample041-02.rb
UTF-8
153
2.796875
3
[]
no_license
p "abcdefghi"[3..5] #=> "def"(由索引值3到索引值5) p "abcdefghi"[3...6] #=> "def"(由索引值3到索引值6之前,不包含索引值6)
true
9236ed8bbd7ee9f7c431776691219dd0f09fd748
Ruby
Nick-Damico/foodieQ-API
/spec/support/login_helpers.rb
UTF-8
554
2.59375
3
[]
no_license
module LoginHelpers # Login and sign_up methods return a JSON web token, to be captured # and used on subsequent requests that require authentication def login_user(user) post api_v1_login_path, :params => {user: {email: user.email, password: user.password}} J...
true
13184363f82bf6b6aea7774f560c5454f386eeca
Ruby
charlesbjohnson/super_happy_interview_time
/rb/lib/ctci/ctci_c1_p1.rb
UTF-8
412
2.96875
3
[ "MIT" ]
permissive
# frozen_string_literal: true module CTCI module C1 module P1 # Implement an algorithm to determine if a string has all unique characters def unique_chars?(s) existing_vals = [] ascii_vals = s.bytes result = true ascii_vals.each { |v| existing_vals[v] == 1 ? ...
true
bab5ef45c4353ff60316ddbb785c8782c240ce06
Ruby
iceboundflame/anagramthief
/ai/truncate_word_list.rb
UTF-8
940
3.15625
3
[]
no_license
require 'word_utils' require 'set' MIN_LEN = 3 if ARGV.length < 3 puts "Usage: #{$0} [word-list] [freq-list] [max-rank]" exit 1 end wordfile, freqfile, maxrank = ARGV[0], ARGV[1], ARGV[2] maxrank = maxrank.to_i valid = Set.new puts "Slurping word file #{wordfile}..." IO.foreach(wordfile) {|line| word = WordU...
true
1e5d52a7d534942c69d72723eb959957a6600801
Ruby
grease082/dcp
/spec/unit/ext/string.spec.rb
UTF-8
2,088
2.984375
3
[ "MIT" ]
permissive
require File.join(File.dirname(__FILE__), '../../', 'spec_helper') describe String do describe "#camelize" do it "capitalize first letter" do 'a'.camelize.should == 'A' 'test'.camelize.should == 'Test' end it "converts underscore_format to UpperCamelCase" do 'one_underscore'.came...
true
49d3abb2140603c1ed6b838c34410953febf66bd
Ruby
ryu2129/paiza
/Brank/2-1.rb
UTF-8
125
3.375
3
[]
no_license
#1つの整数nが入力されるので、そのnに1を足した値を出力してください。 n = gets.to_i puts n += 1
true
0162c0e205c15d6e4543523167ce8df7d084630e
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/trinary/b7e915aa4bd2416fa9b14b65ad717819.rb
UTF-8
295
3.3125
3
[]
no_license
class Trinary < String def to_decimal return 0 unless valid? digits.reverse.each_with_index.reduce(0) do |base10,(digit,index)| base10 += digit * 3**index end end private def valid? self =~ /^[012]+$/ end def digits chars.map &:to_i end end
true
abee127a4e13e9ba76cf838423f5017e58b759ee
Ruby
najMaseu/CodeWars
/6kyu/Duplicate_Encoder.rb
UTF-8
773
3.84375
4
[]
no_license
#https://www.codewars.com/kata/duplicate-encoder/train/ruby #The goal of this exercise is to convert a string to a new string where each character #in the new string is '(' if that character appears only once in the original string, #or ')' if that character appears more than once in the original string. #Ignore capi...
true
4f4cb5a278f847eb355be52f0c41d1ac53817367
Ruby
MarcoMiranda05/OO-Animal-Zoo-london-web-career-042219
/lib/Animal.rb
UTF-8
586
3.171875
3
[]
no_license
class Animal @@all = [] attr_reader :specie, :nickname attr_accessor :weight def initialize(specie, weight, nickname) @specie = specie @weight = weight @nickname = nickname @@all << self end def self.all @@all end def nickname @nickname end def weight @weight end ...
true
06bd9c0237dafee4524dc4e9570e273252042994
Ruby
olwend/Oystercard
/lib/journey.rb
UTF-8
791
3.015625
3
[]
no_license
class Journey attr_reader :start_station, :end_station, :fare, :in_journey DEFAULT_PENALTY = 6 MINIMUM_FARE = 1 #add a condition here, to check in_journey = true else raise error #apply penalty_charge def initialize(start_station = nil) @start_station = start_station @in_journey = true end ...
true
b67d7b70236f9488fb275b159702e4dac2f3a5c0
Ruby
hadlocna/dummy
/Desktop/flashcards/db/seeds.rb
UTF-8
216
2.515625
3
[]
no_license
require 'csv' file = 'States.csv' @cards = [] deck = Deck.create(:category => "State Capitals") CSV.foreach(file, :headers => true) do |row| deck.cards << Card.create(:question => row[0], :answer => row[1]) end
true
c4bc4f1243e5f8aaf528526318cae089680e5604
Ruby
Maxscores/fantasy_football_forever
/spec/models/fantasy_team_spec.rb
UTF-8
639
2.640625
3
[]
no_license
describe FantasyTeam do describe "relationships" do it "has many players" do ff_team = FantasyTeam.new() expect(ff_team).to respond_to(:players) end end describe "validations" do it "is valid" do ff_team = FantasyTeam.new(name: "Squancher United", owner: ...
true
afefd15c5bdf002ec8a58a0e648364244c579b4d
Ruby
bretburau/flatiron-store-project-v-000
/app/models/cart.rb
UTF-8
599
2.703125
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Cart < ActiveRecord::Base has_many :line_items has_many :items, through: :line_items belongs_to :user def total final_total = 0 self.line_items.each do |line_item| item = Item.find(line_item.id) price = item.price * line_item.quantity final_total += price end final_total...
true
ef2bfe94242fcb7eb3127a74722084670cbb7852
Ruby
huxaiphaer/ruby_starters
/main.rb
UTF-8
1,498
3.8125
4
[]
no_license
$global_variable = 1 $age = 5 class Customer @@no_of_customers = def initialize() end def initialize(id,name, addr) @cust_id = id @cust_name = name @cust_addr = addr end def display_details() puts "Customer ID is #@cust_id" puts "Customer Name is #@cust_name" puts "Customer Address...
true
8203d2a5b1a35d8d4401eaedcf108a6a23c84d02
Ruby
bzitzow/sales_tax_calculator
/lib/order/order.rb
UTF-8
537
3.390625
3
[]
no_license
class Order attr_reader :tax_policy include PriceFormatter def initialize(args) @tax_policy = args[:tax_policy] @items = args[:items] || [] end def add_item item @items.push(item) end def items @items end def calculate_tax total_tax = 0.00 @items.each { |item| total_tax +=...
true
d03b695229b5532930f01b441afbb890e18feed2
Ruby
xhochy/scrobbler
/lib/scrobbler/session.rb
UTF-8
1,189
2.796875
3
[ "MIT" ]
permissive
# encoding: utf-8 require File.expand_path('basexml.rb', File.dirname(__FILE__)) module Scrobbler class Session < BaseXml attr_reader :key, :name, :subscriber def initialize(data={}) raise ArgumentError unless data.kind_of?(Hash) super(data) end # Load the data for this object ...
true
c7109f53a2ea8a4bcbdc4892aab8e873ca51bd38
Ruby
nixsticks/todos
/todo8/deli.rb
UTF-8
816
4.5
4
[]
no_license
# Create a class called Deli that has one instance variable: line. # In our deli, we should be able to call "take a number" that takes a customer's name, appends their number to their name and adds them to the line. # The line could look like this: ["1. Ashley", "2. Steve", "3. Blake"] # Additionally we should b...
true
7fedcd112b030beb01e728635bc0a174c54b2a94
Ruby
imcodingideas/learning_ruby
/day_3/index_of_an_array.rb
UTF-8
373
4.03125
4
[]
no_license
=begin Create a get_index method that receives an array of numbers and returns the value and rate of each of the elements in an array. =end def get_index(input) get_indices = Array.new input.each_with_index do |n, i| get_indices.push([n, i]) end get_indices end # tests p get_index([2, 10, 6, 34, 0, 3]) ...
true
395e308ad8b8668c3cfbbd17e685261c0ba240f0
Ruby
nrimal/advance
/app/controllers/anxiety_survey_controller.rb
UTF-8
1,263
2.703125
3
[]
no_license
class AnxietySurveyController < ApplicationController def show end def result @restlessness = [params[:Question4], params[:Question5]] @worry = [params[:Question2], params[:Question3], params[:Question7]] @hypernormal = [params[:Question1] , params[:Question6] ] #this is where the normal state o...
true
b2235ab9ef127c5e191ae7c37a1768068d77b6bb
Ruby
hemser1/bank-tech-test
/spec/account_spec.rb
UTF-8
1,609
3.25
3
[]
no_license
# frozen_string_literal: true require 'account' describe Account do subject(:account) { described_class.new } context 'new account' do describe '#intialization' do it 'should return a 0 balance' do expect(account.balance).to eq 0 end end end context 'depositing' do describe '...
true
fdbbf38c3ba9a73a83eb4bcddf461b89ba448c3f
Ruby
nowavailable/swagger-based-rails-api
/app/models/concerns/user_attr/guidepost.rb
UTF-8
16,603
2.5625
3
[]
no_license
module UserAttr::Guidepost # # ユーザーが、どのProfileXXXを必要としているかを判定し、 # アソシエーション名リストを返す。 # MAP = { # ------------------------------------------------------------- # 中学 DictGrade::KEYS[:juniour_high_1] => { aspiration: [ [:latest_career_decisions_history, 0], # 文理選択 [:rikejo...
true
5bd8fb480a0ede22fe707ea06b9eceb0e4800975
Ruby
hwzss/Ruby_Learning
/day_1/Test_require_pod_gem.rb
UTF-8
1,028
2.75
3
[]
no_license
require 'cocoapods' #gem 安装的cocoapods包 cmd = [] cmd << 'cd /Users/qwkj/Desktop/测试工厂/fastlane测试/SafeShield' cmd << ' && ' cmd << 'open /Users/qwkj/Desktop/测试工厂/fastlane测试/SafeShield' #这一段加着就是看看效果,打开文件说明程序成功执行了 cmd << ' && ' cmd << 'pod install' # IO.popen(cmd.join(' ')) #当cmd有命令的输出是多行时(比如这里的pod install就会多次打印pod成功的...
true
62e09a85e23aa5cef4355e2f18a91e9b86893213
Ruby
vlebedeff/exercise
/lib/exercise/min_segment_coverage.rb
UTF-8
417
3.234375
3
[]
no_license
module Exercise # Calculates the minimum number of points so that each given segment contains at least one point # # @param segments [Array<Array(Integer, Integer)>] line segments # @return points [Array<Number>] def min_segment_coverage(segments) segments.sort_by(&:last).reduce([]) do |points, (from, to)...
true
e70409d2174af7ce81c12d97619798911642fae0
Ruby
slagyr/battleship
/battleship/__resources/gems/gems/white_horseman-1.3/lib/white_horseman/cell_status.rb
UTF-8
582
2.859375
3
[]
no_license
module WhiteHorseman class CellStatus attr_accessor :ship def initialize(was_hit=nil) @ship = :none case was_hit when nil @status = :none when true hit when false miss end end def hit @status = :hit end ...
true
768f6efd11dbf5f41f2a5999a2a42a6b33e81d8a
Ruby
BRoel/badges-and-schedules-onl01-seng-pt-021020
/conference_badges.rb
UTF-8
456
3.828125
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def badge_maker(name) return "Hello, my name is #{name}." end def batch_badge_creator(names) names.map do |name| badge_maker(name) end end def assign_rooms(speakers) speakers.map.with_index do |name, index| "Hello, #{name}! You'll be assigned to room #{index + 1}!" end end def printer(attendees) bat...
true
d9c0fcaf20dff67e20846364ed934b8bb8827487
Ruby
kmcd/rails-attr-enum
/test/attr_enum_test.rb
UTF-8
782
2.828125
3
[ "MIT" ]
permissive
require 'test_helper' require 'attr_enum' SUITS = %w( clubs diamonds hearts spades ) class Card < ActiveRecord::Base attr_enum :suit, SUITS end class AttrEnumTest < ActiveSupport::TestCase load_schema def setup @card = Card.create! end test "should create a class constant" do assert_equal SUI...
true
788fa80ec825157106f34a8e6a30d651385d8cbc
Ruby
souljuse/battle
/spec/features/web_helpers.rb
UTF-8
908
2.546875
3
[]
no_license
def sign_in_and_play_human visit('/') fill_in :player_1_name, with: "Bob" fill_in :player_2_name, with: "Larry" click_button 'Submit' end def play_and_attack_human sign_in_and_play_human allow(Game.instance).to receive(:damage).and_return(10) click_link 'Attack' click_button 'OK' end def attack_to_dea...
true
25da362cb42608cfece5d1e6bd80f47dda105cb6
Ruby
paulorades/synthea
/lib/modules/lifecycle.rb
UTF-8
25,177
2.53125
3
[ "Apache-2.0" ]
permissive
module Synthea module Modules class Lifecycle < Synthea::Rules attr_accessor :races, :ethnicity, :blood_types def initialize super # this file is at synthea/lib/modules/lifecycle.rb, # we want synthea/resources/cdc_growth_charts.json gc_file = File.join(File.dirname(__...
true
91ff9f78cf2c41da189371b52ffafe0ebbb00883
Ruby
rachavez1974/ttt-with-ai-project-online-web-sp-000
/lib/board.rb
UTF-8
1,362
3.890625
4
[]
no_license
class Board attr_accessor :cells def initialize @cells = set_default_cells end def display lines = "-----------".colorize(:light_blue) puts " #{@cells[0]} | #{@cells[1]} | #{@cells[2]} " puts lines puts " #{@cells[3]} | #{@cells[4]} | #{@cells[5]} " puts lines puts " #{@cells[6]} ...
true
6e1af803ea69844f2ef51ce0374140fc5e6a6319
Ruby
luca-montaigut/Archives_THP
/3.1_tests-ruby/spec/03_basics_spec.rb
UTF-8
2,094
3.84375
4
[]
no_license
require_relative '../lib/03_basics' describe 'who is the biggest number' do # Hint: 'def who_is_bigger(a, b, c)' it 'tells me the biggest' do expect(who_is_bigger(84, 42, nil)).to eq("nil detected") expect(who_is_bigger(nil, 42, 21)).to eq("nil detected") expect(who_is_bigger(84, 42, 21)).to eq("a is b...
true
53df604b862ab890267a5e665b6350a3b0b0aaf3
Ruby
BirukAbreham/AppAcademy
/Ruby/Object-oriented programming/Class Inheritance/inheritance.rb
UTF-8
813
3.90625
4
[]
no_license
class Employee attr_reader :salary, :name def initialize(name, salary) @name = name @salary = salary end def bonus(multiplier) return (self.salary)*multiplier end end class Manager < Employee def initialize(name, salary, *employees) super(name, salary) @assigned_employees = e...
true
98e88b576937648c9662f5431a554a97acbf46d7
Ruby
getjerricko/Ruby-Precourse
/09_exercises/09_16.rb
UTF-8
397
3.671875
4
[]
no_license
# 09_16.rb # Turn array into new array consisting # of strings containing one word # Look into map, flatten, and split a = ['white snow', 'winter wonderland', 'melting ice', 'slippery sidewalk', 'salted roads', 'white trees'] b = [] a.map do |x| b << x.split(' ') end p b.flatten # tealeaf solution # No need ...
true
f37bb087d241ac0cb9dd0b6366621372847c08bd
Ruby
elct9620/5compiler
/compiler.rb
UTF-8
426
2.734375
3
[]
no_license
# frozen_string_literal: true # 5compiler require './lexer' require './tokenizer' require './parser' module C5 # :nodoc: class Compiler attr_reader :words, :tokenizer, :parser def initialize(script) @words = Lexer.new(script) @tokenizer = Tokenizer.new(words) @parser = Parser.new(tokeni...
true
c87e717b41d84f6ca835b00e1b0794af29321497
Ruby
Adrian1707/Codewars
/ruby/Welcome_to_the_city.rb
UTF-8
236
3.671875
4
[]
no_license
def say_hello(name, city, state) return "Hello, #{name.join(' ')}! Welcome to #{city}, #{state}!" end print say_hello(["Adrian", "Fintan", "Booth"], "London", "England") # name = ["Adrian", "Fintan", "Booth"] # print name.join(" ")
true
8040e6f8968a92cd0d32cbb857add9d5c30e3571
Ruby
linc01n/advent-of-code
/07/solve.rb
UTF-8
959
3.265625
3
[]
no_license
#!/usr/bin/env ruby f = File.open('input.txt') script = "require 'memoizable'\n" script += "class A7\n" script += "\tinclude Memoizable\n" f.each_line do |line| line = line.split(' -> ') line[1] = line[1].chop line[0] = line[0].gsub(/AND/, "&") line[0] = line[0].gsub(/OR/, "|") line[0] = line[0].gsub(/LSHIF...
true
14773513f12da92e83f82ef96383a13d8e69f3bc
Ruby
JasmeetChatrath/phase-0
/week-4/errors.rb
UTF-8
8,284
4.3125
4
[ "MIT" ]
permissive
# Analyze the Errors # I worked on this challenge [by myself, with: ]. # I spent [#] hours on this challenge. # --- error ------------------------------------------------------- #"Screw you guys " + "I'm going home." = cartmans_phrase =begin # 1. What is the name of the file with the error? #The file with the error ...
true
3aad76c054dd5dab2d7c65e16065520288dbf513
Ruby
alinanevins/mlb_showdown
/MLB_showdown/app/services/advantage_service.rb
UTF-8
328
3.1875
3
[]
no_license
class AdvantageService attr_accessor :roll_1, :control, :onbase def initialize(roll_1, control, onbase) @roll_1 = roll_1 @control = control @onbase = onbase end def advantage if @control.to_i + @roll_1.to_i > @onbase @advantage = "pitcher" else @advantage = "batter" end ...
true
5c25115f36f6fce9a20956638a8cad739fb1d090
Ruby
PeriwinkleBluu/ls_ruby_tut
/exercises/8_hash_styles.rb
UTF-8
84
2.59375
3
[]
no_license
#style 1 hsh = {:one=>blue, :two=>yellow} #style 2 hsh2 = { one: blue, two: yellow}
true
65511ef4f9d2632081514852d2b0c7dfef82dbff
Ruby
pstuifzand/pages
/lib/pages/generate/sitemap.rb
UTF-8
1,514
2.59375
3
[]
no_license
# This file is part of Pages. # # Pages is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Pages is distributed in the hope that it wi...
true
5c1133b5b766800391d79240c911946c639d2968
Ruby
huned/rupee
/spec/native/statistics_spec.rb
UTF-8
1,640
2.875
3
[ "MIT" ]
permissive
require File.dirname(__FILE__) + "/../spec_helper" describe Statistics do before :each do @tolerance = 0.0001 @values = [0, 1, 2, 3, 4] @more_values = [0, 1, 2, 4, 8] end it "should return an accurate cumulative normal distribution" do @result = Statistics.cnd(0) @result.should be...
true
8722bc3fa61ea6cb6111a41db980cd6a2c2027ac
Ruby
efertsch/phase-0-tracks
/ruby/iteration_v2.rb
UTF-8
2,374
4.3125
4
[]
no_license
def here_we_go_again name1 = "Ethan" name2 = "Kimberly" puts "Who is working on this project?" yield(name1, name2) end beer_brands = ["Blue Moon", "Corona", "Budweiser"] beer_brands.each do |brand| puts "#{brand} is my favorite kind of beer!" end puts "Original Data:" p beer_brands beer_brands...
true
5ac0087a50ad8df653f00329974df456a8408a13
Ruby
coderchandu/coding_interview
/ruby/src/data_structures/lists/list_merge.rb
UTF-8
1,697
3.65625
4
[]
no_license
#Find merging point if 2 link list merges # If it merges, last node will be same. Traverse both lists till end, if # last node matches, get size of each lists # size1 - size2 => length difference before merging point as number of # nodes after merging point is same. Then traverse big list that much time and then # tr...
true
0bf6679615112afae404403e8ce8fbd35b2994f8
Ruby
toumait/orbf2
/app/services/analytics/multi_entities_calculator.rb
UTF-8
1,982
2.734375
3
[ "MIT" ]
permissive
module Analytics class MultiEntitiesCalculator class MultiEntitiesResult < ValueObject attributes :activity, :org_unit_id, :solution end def initialize(org_unit_ids, package, values, period) @org_unit_ids = org_unit_ids @package = package @values = values @period = period ...
true
7e341724f39fd73ada3e95d0e60f09c7ea5a5157
Ruby
kingcoconut/wdi-20
/week-07/bank/spec/bank_spec.rb
UTF-8
1,266
3.1875
3
[]
no_license
require_relative '../bank.rb' describe Bank do describe "#add_account" do let(:bank){ Bank.new } it "should create an account with the given value" do bank.add_account("Paul", 200) expect(bank.account_value("Paul")).to eq 200 end it "should prevent duplicate account names" do bank...
true
a3394429b5aaff7140990815b24c097bd3c2d378
Ruby
retani/wwhs
/app/models/user_biography/translate_uchronia_110.rb
UTF-8
2,802
2.625
3
[]
no_license
# encoding: utf-8 class UserBiography module Translate_uchronia_110 extend ActiveSupport::Concern def translate_uchronia_110 s = "" if age(2013) <= 33 \ && self.job_changes >=4 \ && self.education == 'künstlerisch' \ && (self.childhood == 'chaotisch' || self.childhood =='neugierig' || ...
true
ce03a331e8c43535950aafbf06eb09cc69f3c0c0
Ruby
thiagokimo/manga-crawler
/test/lib/manga-crawler/crawler_test.rb
UTF-8
1,777
2.640625
3
[ "MIT" ]
permissive
require_relative "../../test_helper" module MangaCrawler describe Crawler do before do @url = File.open("test/sample_website/index.html","r") @base_url = "test/sample_website/" @sample_manga_page = File.open("test/sample_website/Bleach/bleach.html","r") @css_path_to_mangas = "a" @...
true
2f6dced7428e2fbccaa17ecde42221b547d27ddb
Ruby
rbrindamour/ruby
/AMC/sqlite.rb
UTF-8
1,382
3.03125
3
[]
no_license
require 'rubygems' require 'sqlite3' # DBNAME = "/home/rodb/Ruby/SP_500/sp500-data.sqlite" DBNAME = "/home/rodb/Documents/AMC/Products/salarysurvey.sqlite" #DBNAME = "/home/rodb/Ruby/SP_500/sp500-data.sqlite" def median(inarray) numbers = inarray.sort if (numbers.length%2 == 0) then (numbers[...
true
303fdfb7942a3e489a96a346656b5949c66ace8b
Ruby
mazz1796/benchmark
/simple-benchmarking.rb
UTF-8
3,159
4.5625
5
[]
no_license
def benchmark # Your benchmarking code goes here. i = Time.now yield f = Time.now f - i end # Be careful, pasting this into IRB will take a long time to print. # It's a loooong string. :) long_string = "apple"*1000000000 running_time = benchmark { long_string.reverse } # methodの後に、blockを呼び出す時には、yieldを使う。 p...
true
ba08bc2fcc0a37337a80f16f03b2696b72daba02
Ruby
bloombaby/TTS-Ruby-
/poptrivia.rb
UTF-8
1,180
3.609375
4
[]
no_license
# questions = [ # "Who sang Smells Like Teen Spirit?", # "Which actor played Jason Bourne", # "Who is NOT Micheal Jackson's Lover?"] # answers = [ # "nirvana", # "matt damon", # "billie jean"] questions = { "Who sang Smells Like Teen Spirit?": "nirvana", "Which actor played Jason Bourne?": "matt damon...
true
bd05363658d7d2663f0fa4887bc56227823f71ee
Ruby
BrianOReilly/brian-oreilly-solution
/spec/models/user_spec.rb
UTF-8
2,355
2.609375
3
[]
no_license
require 'spec_helper' describe User do let(:user) { create(:user) } let(:team) { create(:team) } describe "#status=" do before do user.status = status end context "when given an accepted enum value" do let(:status) { :in } it "writes the enumerated value in the database" do ...
true
8134324e02a61555943e46470f4b5fe006a81365
Ruby
Joe21/2015-summer-msk_lol
/app/models/champ.rb
UTF-8
2,125
2.578125
3
[]
no_license
class Champ < ActiveRecord::Base validates :name, presence: true validates :riot_id, presence: true validates :img_url, presence: true has_many :matchmakers has_many :rounds, through: :matchmakers # Handle Scoreboard Queries def self.marry_leaders return Champ.order("marry_count DESC").limit(10) end def ...
true
7bf5c6bb385946c13fd78032a71cd52d632bb5b0
Ruby
brian1987/fullow
/app/models/get_game_stats.rb
UTF-8
4,840
2.640625
3
[]
no_license
class GetGameStats require 'open-uri' attr_reader :player, :espn_url, :player_data, :picture, :most_recent_0, :most_recent_1,:most_recent_2,:most_recent_3,:most_recent_4, :season_averages_hash, :career_averages_hash, :game_day, :game_time, :game_matchup def initialize(player) @player = player self.call ...
true