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
4d30f8911192a518cfc6832080f68709c7e23bc3
Ruby
patrodriguez108/sort-an-array
/sort_an_array.rb
UTF-8
638
4.09375
4
[]
no_license
# @param {Integer[]} nums # @return {Integer[]} def sort_array(nums) # nums.sort_by { |s| s } # go through array # find element with least value # place element with least value into new array # go through array again array = [] until nums.length == 0 nums.map do |num| if array.empty? ...
true
1352e9c89026abf23139d92010139d587434bce7
Ruby
josfervi/ruby_playground
/00-Before_first_coding_interview/00-practice_problems--prompts_and_solutions/solutions-GIVEN/16-nth-prime.rb
UTF-8
2,262
4.25
4
[]
no_license
# Write a method that returns the `n`th prime number. Recall that only # numbers greater than 1 can be prime. # # Difficulty: medium. # You may use our `is_prime?` solution. def is_prime?(number) if number <= 1 # only numbers > 1 can be prime. return false end idx = 2 while idx < number if (number...
true
62b47c3d4227076513157ec9808c0c8337038cd6
Ruby
jvanbaarsen/dixit
/lib/random_word.rb
UTF-8
155
2.796875
3
[]
no_license
class RandomWord WORDS = %w{tree sea car computer building board painting flower lamp glass coffee tea movie} def self.word WORDS.sample end end
true
af6f71bdffb40adb52380a4023c23e96195c12bf
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/grains/37321d398c1b43d994f01363ca33fbd0.rb
UTF-8
236
3.375
3
[]
no_license
=begin File: grains.rb Author: sherinom =end class Grains def square(number) 2**(number - 1) end def total total_grains = 0 (1..64).each do |x| total_grains += square x end total_grains end end
true
b21e5c95900ba781230052f55ce159b84f00b4bf
Ruby
KiryhaPikoff/nmax
/lib/array.rb
UTF-8
593
3.34375
3
[ "MIT" ]
permissive
require 'big_number' class Array def insert_bin(query) find = ->(start, finish) do len = finish - start + 1 med = len / 2 + start return self if len == 0 comp_res = query <=> self[med] if comp_res == -1 self.insert med, query if len == 1 find.call(med + 1, finish)...
true
0107a14f616d562cba736187cd4e6b9ef6768f71
Ruby
NRothera/sparta-repos
/xml_restfulapi/models/devices.rb
UTF-8
582
2.671875
3
[]
no_license
require 'sinatra' require_relative '../schema/xml_parsing' require 'json' class Devices attr_accessor :name, :value, :notes def self.all set_up_json = DeviceXml.new set_up_json.get_device_names set_up_json.get_device_values set_up_json.get_device_notes device_hash = set_up_json.devices_to_...
true
0f3b99b00a5a36da9efd403f173506784e5f543e
Ruby
cul-it/archival-storage-ingest
/lib/archival_storage_ingest/disseminate/request.rb
UTF-8
1,779
2.59375
3
[]
no_license
# frozen_string_literal: true require 'csv' require 'archival_storage_ingest/manifests/manifests' module Disseminate PACKAGE_ID = 'package_id' FILEPATH = 'filepath' FIXITY = 'sha1' SIZE = 'size' class Request attr_reader :zip_filename def initialize(manifest:, csv:) @manifest = Manifests.rea...
true
1427f501a096a9a89771c5c4a778fdde2bdcde14
Ruby
Axeia/AAClasswork-Minesweeper
/spec/tile_rspec.rb
UTF-8
1,376
3.3125
3
[]
no_license
require 'rspec' require 'tile.rb' describe "Tile#revealed?" do it "Returns boolean depending on whether it's revealed or not" do tile_1 = Tile.new() tile_2 = Tile.new() tile_2.reveal expect(tile_1.revealed?).to eq (false) expect(tile_2.revealed?).to eq (true) e...
true
d8ccc8b1d47acc58fc0b29398e21dbf9b6a1167d
Ruby
justinphelps/borderland-dreams
/lib/tasks/import_burnertickets.rake
UTF-8
1,740
2.671875
3
[ "WTFPL" ]
permissive
# to import run bundle exec rake importtixwise require 'rest-client' require 'json' desc "Import Ticket from tickets events url" task :import_burnertickets => [:environment] do file = ENV['TICKETS_EVENT_URL'] if file.nil? puts "Error: Please set env TICKETS_EVENT_URL" next end begin counter = 0 ...
true
09c583545ef5a19899104187a343b973ed7670eb
Ruby
code-builders/curriculum
/playground/pet.rb
UTF-8
574
3.234375
3
[]
no_license
require 'httparty' class Pet attr_accessor :id, :name, :breed, :human, :species def initialize(attrs) @id = attrs["id"] @name = attrs["name"] @breed = attrs["breed"] @human = attrs["human"] @species = attrs["species"] end def self.find(id) response = HTTParty.get("https://...
true
d5f556e424841d6542f939e1608ce314ca00b7ca
Ruby
whatupdave/wod
/lib/wod/commands/help.rb
UTF-8
2,451
2.734375
3
[]
no_license
module Wod::Command class Help < Base class HelpGroup < Array attr_reader :title def initialize(title) @title = title end def command(name, description) self << [name, description] end def space self << ['', ''] end end def self.gro...
true
5e01824d457872cd0a171005b135252c05c3cd15
Ruby
nchambe2/phase-0
/week-4/concatenate-arrays/my_solution.rb
UTF-8
661
3.8125
4
[ "MIT" ]
permissive
# Concatenate Two Arrays =begin INPUT: Obtain two collections of values If both collections are empty THEN return the empty collection else add collection one + collection two THEN return the combined collections END IF OUTPUT: Combine the two collections of words into one =end # I worked on this challenge [...
true
5341040e3e79c1ae58cb0776977e69d58010ae70
Ruby
mare-imbrium/umbra
/lib/umbra/tabular.rb
UTF-8
12,987
2.96875
3
[ "MIT" ]
permissive
#!/usr/bin/env ruby -w =begin * Name : A Quick take on tabular data. Readonly. * Description : To show tabular data inside a control, rather than going by the huge Table object, I want to create a simple, minimal table data generator. This will be thrown into a Tex...
true
5e4141905e06a041ddfd6dd0a40b02fd6e61323c
Ruby
ajLapid718/CodeWars-Problems
/6Kyu Kata/ROT13_variant_cipher.rb
UTF-8
1,432
4.375
4
[]
no_license
# You have been recruited by an unknown organization for your cipher encrypting/decrypting skills. # Being new to the organization they decide to test your skills. # Your first test is to write an algorithm that encrypts the given string in the following steps. # # The first step of the encryption is a standard ROT13 c...
true
7452eeea9314695ce96a97b3a7e90d89576de857
Ruby
urubatan/ruby101samples
/intro/22numberandclass.rb
UTF-8
200
3.625
4
[ "MIT" ]
permissive
def number_and_class(n) puts "#{n} -> #{n.class}" end i =1 i1 = 1.1 i2 =111_222_333 i3 =999999999999999999 number_and_class i number_and_class i1 number_and_class i2 number_and_class i3
true
4511c7b4a9f18e1fd3bffd9d404321256e267e59
Ruby
OWASP/owasp-esapi-ruby
/lib/codec/javascript_codec.rb
UTF-8
3,792
3
3
[ "LicenseRef-scancode-unknown-license-reference", "BSD-3-Clause" ]
permissive
module Owasp module Esapi module Codec class JavascriptCodec < BaseCodec # Returns backslash encoded numeric format. Does not use backslash character escapes # such as, \" or \' as these may cause parsing problems. For example, if a javascript # attribute, such as onmouseover, conta...
true
94912467a825171de397ae61f7f4a50fe7317658
Ruby
sajid1760/square_array-onl01-seng-ft-030220
/square_array.rb
UTF-8
113
3.203125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def square_array(array) squares = [] array.each do |number| squares.push(number*number) end squares end
true
4f9c28ffb52ae2d5c48faec3c73595f12500410e
Ruby
kasai441/ruby-practices
/08.ls_object/lib/segment/size.rb
UTF-8
332
2.796875
3
[]
no_license
# frozen_string_literal: true require_relative 'segment' class Segment::Size include Segment attr_accessor :value, :space def display SPACE_STRING * @space + @value end BLANK_NUM = 2 def need_space(max_size) max_size - @value.size + BLANK_NUM end def choose(stat) @value = stat.size.to_...
true
e998580cbf77a6d8e9c891d2c514feaf413e44af
Ruby
jsoong1962/greeting-cli-ruby-intro-000
/lib/greeting.rb
UTF-8
93
3.015625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# code the # method he def greeting(name) puts "Hello #{name}. It's nice to meet you." end
true
83cb7f8c026396024255e1e3c069875eec3442d8
Ruby
madsimian/little-league-rails-app
/app/models/game.rb
UTF-8
522
2.578125
3
[]
no_license
# create_table "games", force: true do |t| # t.string "location" # t.date "date" # t.integer "team_id" # t.datetime "created_at" # t.datetime "updated_at" # end class Game < ActiveRecord::Base has_many :matchups has_many :teams, -> {select("teams.*, matchups.score")}, :through => :matchups ...
true
6a5e5def6e77b81169b4a7e3c0e9a71066582ffb
Ruby
GSergeevich/ruby
/exercises/class.rb
UTF-8
1,229
3.640625
4
[]
no_license
# frozen_string_literal: true ## # Create user with description methods # # # = Usage example: # usr = User.new # # usr.fio # # usr.profession # # # class User @@count = 0 ## # Revolucioneers count # def counter @@count end ## # Set revolucioneers count # def set_count(count) @@count = cou...
true
b4990cffb09201810b779585d8d6c3e86d459eaf
Ruby
AaronJoseCabreraMartin/pruebas-travis
/lib/impactoambiental/Lista.rb
UTF-8
5,281
4.03125
4
[]
no_license
class Lista include Enumerable attr_reader :head, :tail, :nodos # Head es el primer elemento, tail el ultimo. El initialize esta preparado para funcionar pasandole tanto el valor que queremos guardar en los nodos como con el nodo en si, tambien se puede iniciar con 1 solo argumento o con 2 def initialize(head,...
true
3f83a014ef21eaf5218dd24790ef77f040bd079b
Ruby
Alnakhlani/rubysproutsapp
/test.rb
UTF-8
96
3.25
3
[]
no_license
def name (first_name="First", last_name) "#{first_name} #{last_name}" end puts name("Jane")
true
88839818eb2aa3be6a02ad3848ca7f5869b2a763
Ruby
scottpersinger/mysql_replication_adapter
/test/test_mysql_replication_adapter.rb
UTF-8
4,415
2.6875
3
[ "MIT" ]
permissive
require File.dirname(__FILE__) + '/test_helper.rb' require 'optparse' class Person < ActiveRecord::Base end class TestMysqlReplicationAdapter < Test::Unit::TestCase @@user = "root" @@password = nil @@host = "localhost" @@options = nil def self.parse_opts @@options = OptionParser.new do |o| o....
true
5550814a0cab3f8f05933a01c7d0ad5597f4aaec
Ruby
FrederikNS/advent-of-code
/ruby/2022/02/part2.rb
UTF-8
1,829
3.1875
3
[]
no_license
require_relative 'part1.rb' module Y2022 module Day2 module Part2 @part1 = Y2022::Day2::Part1 @symbol_lut = { A: :rock, B: :paper, C: :scissors, X: :lose, Y: :draw, Z: :win ...
true
7203f6b2638cd7b8a08241f7434302a82dfab8a9
Ruby
ryancurtin/iron_cache_ruby
/lib/iron_cache/caches.rb
UTF-8
1,443
2.734375
3
[]
no_license
require 'uri' module IronCache class Caches attr_accessor :client def initialize(client) @client = client end def path(options={}) path = "projects/#{@client.project_id}/caches" end def list(options={}) ret = [] res = @client.get("#{path(options)}", options) ...
true
cbc0df2ae62016cb8730365a01092eec709a12ce
Ruby
cielavenir/procon
/atcoder/codefestival/tyama_atcodercodefestival2014morningB.rb
UTF-8
58
2.578125
3
[ "0BSD" ]
permissive
#!/usr/bin/ruby n=(gets.to_i-1)%40 n=n<20 ? n : 39-n p n+1
true
f615abb7076f70b76ba98e925d03457f34376e5c
Ruby
jniemisto/rails-basic
/app/models/reservation.rb
UTF-8
804
2.578125
3
[]
no_license
class Reservation < ActiveRecord::Base belongs_to :book belongs_to :user delegate :email, to: :user before_validation :make_reserved, :on => :create STATES = %w( free reserved ) validates :book_id, :presence => true validates :user_id, presence: true validates :state, :inclusion => { :...
true
5e7df5806ed9da2f5b0069172c97909ea8b5999b
Ruby
QnYosa/Game-ruby
/lib/player.rb
UTF-8
2,427
3.734375
4
[]
no_license
class Player attr_accessor :name, :life_points def initialize (player, life = 10) @name = player.to_s @life_points = life end def show_state puts "#{@name} a #{@life_points} points de vie. " end def gets_damage (damage) damage = damage.to_i @life_points = @l...
true
0e8990824c1366120b0bc2496c482a68629a0eb4
Ruby
night1ightning/ruby_course
/listen6/models/train/cargo_train.rb
UTF-8
784
2.6875
3
[]
no_license
class Model::CargoTrain < Model::Train def initialize(number) super(:cargo, number) end def self.collection_name :cargo_train end def valid! super return if wagons.empty? wagons.each do |wagon| unless wagon.is_a? Model::CargoWagon raise Err::InvalidModelAttributes.new model...
true
9efa595384237442aedada43b9ae4ab7c966f208
Ruby
mbehrlich/ruby-chess
/queen.rb
UTF-8
191
2.6875
3
[]
no_license
require_relative 'piece' require_relative 'sliding_piece' class Queen < Piece include SlidingPiece def to_s piece_symbol = " \u265B " piece_symbol.encode('utf-8') end end
true
98fea017c8e96c04463e6221dad01e1c0ca1777c
Ruby
mkrahu/launchschool
/170_web_development/cms-project/cms.rb
UTF-8
5,884
2.515625
3
[]
no_license
require 'sinatra' require 'sinatra/reloader' require 'tilt/erubis' require 'redcarpet' require 'yaml' require 'bcrypt' require 'pry' def data_path if ENV['RACK_ENV'] == 'test' File.expand_path('./test/data', __dir__) else File.expand_path('./data', __dir__) end end def users_path if ENV['RACK_ENV'] == ...
true
b8b440c88449b8dbbf6b37f13902c94dd43fca82
Ruby
kyletress/sledsheet
/test/models/entry_test.rb
UTF-8
868
2.625
3
[]
no_license
require 'test_helper' class EntryTest < ActiveSupport::TestCase def setup @entry = entries(:kyle) end test "should be valid" do assert @entry.valid? end test "should have an athlete id" do @entry.athlete_id = nil assert_not @entry.valid?, "saved entry without an athlete id" @entry.athl...
true
0d194fd13721950d2f3af016b36b04713459eee6
Ruby
zato91/dc-web-060120
/05-one-to-many/sandbox.rb
UTF-8
486
2.796875
3
[]
no_license
class Car NUM_WHEELS = 4 ALL_CARS = ["test"] def initialize(make, model) @make, @model = make, model end # def self.NUM_WHEELS=(new_number) # NUM_WHEELS = new_number # end def self.clear_cars ALL_CARS.clear end def self.all_cars ALL_CARS[0] = "so...
true
41f0e6f1d39080f53bf201a8a50dadbcb921603c
Ruby
sarah-mcculley/mocking
/lib/wardrobe_chooser.rb
UTF-8
345
2.84375
3
[]
no_license
require 'weather_service' class WardrobeChooser WEATHER = { 'rain' => 'carry an umbrella', 'snow' => 'wear snow boots', 'sun' => 'wear sandals', } attr_accessor :weather_service def initialize @weather_service = WeatherService.new end def shoes_for_today WEATHER[@weather_ser...
true
afa4e03b5a4a93c48a83307a1d1e3067fdeb6af4
Ruby
jessgenualdi/object-oriented-ruby
/manager/main.rb
UTF-8
175
2.703125
3
[]
no_license
require './employee.rb' require './manager.rb' require './intern.rb' employee1 = Employee.new(first_name:"Jess", last_name: "Genualdi", salary: 99000) employee1.print_info
true
0160525e59bae98423ca5c6ab5e2611291769847
Ruby
mschaf/advent_of_code
/lib/day_12/part_2.rb
UTF-8
979
2.984375
3
[]
no_license
module Day12 module Part2 def self.run(input) moon_positions = input.scan(/<x=(?<x>-?\d+), y=(?<y>-?\d+), z=(?<z>-?\d+)>/m).map{ |row| row.map(&:to_i) }.transpose moon_velocities = [[0] * 4] * 3 start_positions = moon_positions.map(&:clone) start_velocities = moon_velocities.map(&:clone) ...
true
33b19c56337c5aa6b049c8269446d83d5cd7e1f2
Ruby
abelardogilm/organic-sitemap
/lib/organic-sitemap/redis_manager.rb
UTF-8
1,036
2.546875
3
[ "MIT" ]
permissive
module OrganicSitemap class RedisManager def self.add(key) return unless key redis_connection.zadd(storage_key, (DateTime.now + expiry_time).to_time.to_i, key) end def self.clean_set(time = Time.now) redis_connection.zremrangebyscore(storage_key, "-inf", time.to_i) end def self...
true
8ca36b21b10ead445acf2637ec71ff1673174fd3
Ruby
depaolif/ruby-objects-has-many-through-lab-web-0217
/lib/patient.rb
UTF-8
319
3.328125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Patient attr_accessor :name, :appointments def initialize(name) self.name = name self.appointments = [] end def add_appointment(appointment) self.appointments << appointment appointment.patient = self end def doctors self.appointments.map do |appointment| appointment.doctor end end end
true
5c44395d3e7d8611c27bdf512332a35ff669ff25
Ruby
aaduru/algorithms
/ujwala aaduru graph/lib/topological_sort.rb
UTF-8
737
3.28125
3
[]
no_license
require_relative 'graph' # Implementing topological sort using both Khan's and Tarian's algorithms # khan's algorithm def topological_sort(vertices) vertex_queue = [] sorted_queue = [] vertex_count = {} #vertex queue has vertex which do not have any in_edges vertices.each do |vertex| vertex_count[verte...
true
6ce1e40133f05bc318ea00eb67a3b7d185b82635
Ruby
coins5/tareas-fundamentos-programacion-upc
/Ejercicios_cadenas/pregunta15_sol.rb
UTF-8
2,821
2.796875
3
[]
no_license
def calcular_PersonasMesNacimiento(codigos,mes) cantidad=0 for i in 0...codigos.size if mes == codigos[i][2..3] cantidad=cantidad+1 end end return cantidad end def calcular_coincidenApellido(codigos,apellido) cantidad=0 for i in 0...codigos.size if apellido[...
true
14dc8320c0b25048dd1880a5689176f22b78e314
Ruby
aleksuk/Anadea-Task-Rack
/models/cart.rb
UTF-8
498
3.40625
3
[]
no_license
class Cart def initialize @cart = [] end def add product @cart << product end def delete product el_index = @cart.find_index do |el| el.name == product end @cart.delete_at el_index end def show_price @cart.reduce 0 do |sum, el| sum += el.price end end ...
true
3e9222138f49635ee4e796394b7a230743ed4fad
Ruby
marmer7/my-collect-web-080717
/lib/my_collect.rb
UTF-8
173
3.28125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def my_collect(collection) i = 0 newA = Array.new while i < collection.size x = collection[i] yield(x) newA << yield(x) i += 1 end return newA end
true
a4da19a1b46ce8f819857398b8d0cf5ad3ddf674
Ruby
Nigel33/LS_130_ruby_foundations_more_topics
/exercises/ex37.rb
UTF-8
261
3.03125
3
[]
no_license
def check_return_with_proc my_proc = proc { return } my_proc.call puts "This will never output to screen." end check_return_with_proc my_proc = proc { return } def check_return_with_proc_2(my_proc) my_proc.call end check_return_with_proc_2(my_proc)
true
345e07a216985fb66f9650eb0e3190c4f1ef2c8b
Ruby
estebanpetaflop/Ruby
/exo_10.rb
UTF-8
189
3.28125
3
[]
no_license
#age eu en 2018 puisque c'est de circonstance puts "Tu es né en quelle année?" print "> " year=gets.chomp() puts "Tu as donc eu #{2018-year.to_i} ans l'année dernière, félicitations!"
true
e80c34aed5808c8913bb7556db090d8c037fba9b
Ruby
carlosmendes/sql_crud_b425
/recap.rb
UTF-8
630
3.03125
3
[]
no_license
# SCHEMA DESIGN # A company sells products to customers # Products have name, description and price # Customers have email and phone # Customers can have multiple orders # An order is only of one customer # An order can have multiple products # A product can be in multiple orders # SQL # SELECT column(s) -> SELECT ...
true
3b10a6b49717268f54c41b61162b089186118aa3
Ruby
caseydailey/ruby-orientation-exercises
/tests/magic_ball/magic_ball.rb
UTF-8
370
3.640625
4
[]
no_license
class MagicBall ANSWERS = [ "Outcome does not look likely", "Not now", "Better lock next time", "Absolutely" ] def ask(question) raise "Question has invalid format." unless is_question_valid? question ANSWERS.sample end private def is_question_valid?(question) question....
true
7e18d516a3ded5fe29310f95b379e26106a9880d
Ruby
Ankita-1105/book-store
/app/models/supplier.rb
UTF-8
195
2.53125
3
[]
no_license
class Supplier < ApplicationRecord has_many :book validates :first_name, :last_name, presence: true attr_accessor :full_name def full_name "#{first_name} #{last_name}" end end
true
581ab37c8daa2901d0c465ca7bd6dedd9c70a6d0
Ruby
shule517/life-game
/lib/cell.rb
UTF-8
436
4.03125
4
[]
no_license
class Cell attr_reader :x, :y def initialize(x, y, alive) @x = x @y = y @alive = alive end def alive? @alive end def die @alive = false end def born @alive = true end def next(arround_alive_count) if alive? die if arround_alive_count <= 1 || 4 <= arround_alive_c...
true
e41297a901d985e93d02b837ed4337a3fd319b15
Ruby
gtrevg/pokr
/spec/models/room_spec.rb
UTF-8
5,504
2.6875
3
[]
no_license
require 'rails_helper' RSpec.describe Room, type: :model do subject(:room) { Room.new } describe '#name' do it "is invalid if no name specified" do expect(subject.valid?).to be false expect(subject.errors[:name]).to include "can't be blank" end it "is valid if name specified" do roo...
true
9b786c19644d000230c7930940470599a9a4f2ef
Ruby
morizotter/SwiftyDrop
/vendor/bundle/gems/activesupport-4.2.10/lib/active_support/core_ext/thread.rb
UTF-8
2,825
3.46875
3
[ "MIT" ]
permissive
class Thread LOCK = Mutex.new # :nodoc: # Returns the value of a thread local variable that has been set. Note that # these are different than fiber local values. # # Thread local values are carried along with threads, and do not respect # fibers. For example: # # Thread.new { # Thread.current....
true
d2fbd9b2cf47916a1c47f372fc83e70be142f196
Ruby
jamespeerless/weebly_api
/lib/weebly_api/paged_weebly_response.rb
UTF-8
1,697
2.921875
3
[ "MIT" ]
permissive
require_relative "paged_enumerator" # Public: Presents a paged Weebly response as an Enumerator with a # PagedEnumerator # # Example # # response = PagedWeeblyResponse.new(client, "products", priceFrom: 10) do |product_hash| # Product.new(product_hash, click: client) # end # # response.each do |product| # ...
true
74857952c6b51ccd0c409a1c12df98d9e2061aee
Ruby
dmyers3/launch_school_130_exercises
/easy_2/each_with_index.rb
UTF-8
98
3.171875
3
[]
no_license
def each_with_index(array) 0.upto(array.size) { |index| yield(array(index), index) } array end
true
6a8f31bc187a0bf24fc6470d83937892c876b937
Ruby
haugenc/ruby-object-attributes-lab-oc-000
/lib/dog.rb
UTF-8
184
3.015625
3
[]
no_license
class Dog def name=(name_string) @name = name_string end def name @name end def breed=(breed_string) @breed = breed_string end def breed @breed end end
true
725e9e88281d7a9cf7bb105be69dcefa9637fa79
Ruby
jameshughes7/bank_tech_test
/lib/statement.rb
UTF-8
459
3.15625
3
[]
no_license
require_relative 'account' class Statement attr_reader :headings def initialize @headings = { 'date' => 'date', 'credit' => 'credit', 'debit' => 'debit', 'balance' => 'balance' } end def print(account) account.transactions << @headings printout = account.transactions.reverse.each do |transaction|...
true
2fb0668ecfdd320b89e843fb0845e522162cb6d2
Ruby
phlipper/ruby-lint
/lib/ruby-lint/definition/constant_proxy.rb
UTF-8
1,995
2.890625
3
[ "MIT" ]
permissive
module RubyLint module Definition ## # {RubyLint::Definition::ConstantProxy} is a proxy class for constant # definitions. The primary use case for this class is inheriting constants # in the pre-generated definitions found in the definitions directory. By # using this class when creating definitio...
true
31df3f1f94b81b9ee2bbb43ddf70d618ee3e1130
Ruby
aliyyanajya/PR-Matematika
/soalnomer3.rb
UTF-8
761
2.609375
3
[]
no_license
############################################################################### # Tugas lingkaran sebagai prasyarat ulangan # Mapel Matematika # # Soal Nomer 3 # Menghitung biaya menanam pohon pada taman berbentuk lingkaran # # Author: Aliyya N. Aurelia #############################################################...
true
df576b6261e186523e0501369aaede9a8f8aee0c
Ruby
steven-solomon/card_type
/spec/cards_spec.rb
UTF-8
2,100
2.546875
3
[]
no_license
require 'rspec' require 'card_type' require 'date' describe 'CardType' do context 'make' do context 'when card_number is Amex' do it 'returns Amex instance' do card_number = '341111111111111' card_instance = double(:card_instance) expect(Amex) .to receive(:new) ...
true
bd77a152372db07dc00b874ef3af472645730460
Ruby
qytiz/rubyRepo
/ruby b.rb
UTF-8
739
3.453125
3
[]
no_license
def an(result,total) print("Введите название товара: ") productName = gets.chomp().to_s if productName!="стоп" print("Введите цену товара: ") productCost= gets.chomp().to_f print("Введите количество товара: ") productCounter= gets.chomp().to_f result[productName]={productCost=>productCounter} tot...
true
f7fc875bae454ec1b3b9c616a0f815931190124b
Ruby
ayqazi/boxgame
/ruby/Container.rb
UTF-8
442
2.953125
3
[]
no_license
module Container def init_container @entities = [] end def add_entity(entity) entity.__send__(:container=, self) # only we can do this! @entities << entity end def draw_entities(canvas, offset) offset = offset.clone @entities.each do |entity| entity.draw(canvas, offset) end e...
true
39475c450d157939f8c9a78c7c5740f0d1561231
Ruby
tannyque/Week02-Caraoke
/specs/bar_spec.rb
UTF-8
337
3
3
[]
no_license
require("minitest/autorun") require("minitest/rg") require_relative("../bar") class BarTest < MiniTest::Test def setup() @bar = Bar.new(10) end def test_bar_has_money_in_till() assert_equal(10, @bar.till()) end def test_add_money_to_till() @bar.add_money_to_till(5) assert_equal(15, @bar.ti...
true
56258358e3442c1337ac605f972fc397d65ea16b
Ruby
uakatt/ojbequel
/lib/ojbequel/repo_files/spring_load.rb
UTF-8
3,836
2.84375
3
[]
no_license
# Use SpringLoad if the OJB repository files are all indicated in a Spring XML file or a Spring # properties file. class OJBequel::RepoFiles::SpringLoad < OJBequel::RepoFiles::Base attr_accessor :files, :spring_bootstrap_file, :repo_re, :spring_base_dir, :type # Create a new {OJBequel::RepoFiles::SpringLoad} to ma...
true
a442041af23c876753437e7a4338b2baeb6a3d4c
Ruby
ceciwang/sevenWeeks
/ruby/random2.rb
UTF-8
164
3.734375
4
[]
no_license
puts "Let's guess the random number:" random = rand(10) while (guess=gets().to_i) != random puts "smaller" if guess < random puts "bigger" if guess > random end
true
314faeb711e28fe324710185a4637640887e9e85
Ruby
f3mmedia/rxl
/lib/cell.rb
UTF-8
7,452
2.875
3
[ "MIT" ]
permissive
require 'rubyXL' module Cell ############################################## ### GET HASH CELL FROM RUBYXL CELL ### ############################################## def self.rubyxl_cell_to_hash_cell(rubyxl_cell = nil) rubyxl_cell_value = rubyxl_cell.nil? ? RubyXL::Cell.new.value : rubyxl_cell.value ...
true
e6245cd84d7407caf84130c17a0bfb0da6246ba1
Ruby
aakacenoks/project-euler
/8/main.rb
UTF-8
1,069
4.15625
4
[]
no_license
# Problem 8: Largest product in a series # Answer: 23514624000 def get_number_from_file(file) number_source = File.open(file).read number = '' number_source.each_line do |line| number += line.strip end number end def get_sum_of_array(array) sum = 0 array.each do |number| sum += number end su...
true
8ad6ec98285e5062aa61fbce36fce446ef157c51
Ruby
lacresni/101_programming_foundations
/lesson_2/calculator.rb
UTF-8
767
4.65625
5
[]
no_license
# ask user for two numbers # ask user for an operation to perform # perform the operation on the two numbers # output the result Kernel.puts("Welcome to calculator!") Kernel.puts("What's the first number?") number1 = Kernel.gets().chomp().to_i Kernel.puts("What's the second number?") number2 = Kernel.gets().chomp()....
true
214c2022055af33cdb0a8d76a6e70079b87d6154
Ruby
Ahmed-Araby/tic-tac-toe
/Board.rb
UTF-8
1,683
3.640625
4
[]
no_license
require_relative 'Move' class Board def initialize(winningAlogrithm) @board = Array.new(3) {Array.new(3)} @markersCnt = 0 @winning_algorithm = winningAlogrithm # obj @last_move = Move.new(-1,""); init end def render i = 0 line ...
true
bff6cd515a406331cd6307a8f497335a48005c87
Ruby
ndelforno/reinforcement_tdd_simon
/simon_says.rb
UTF-8
235
3.5
4
[]
no_license
def echo(str) str end def shout(str) str.upcase end def repeat(text,num) (("#{text} ") * num).strip end def start_of_word(text,num) text[0..num-1] end def first_word(text) splited_text = text.split(" ") splited_text[0] end
true
7e0699da3bf2389a6e24f49e467326b8450d1b97
Ruby
gnclmorais/advent-of-code
/2020/day18/solution_part2.rb
UTF-8
1,498
3.28125
3
[]
no_license
total = File.read("#{__dir__}/input.txt").split("\n").reduce(0) do |memo, line| # Remove spaces 'cause we don't really need them line = line.gsub(/ /, "") # Scan the whole line until we can move to the next one loop do # Handle simplifications just in case, like "6+(11)" --> "6+11" simplification = lin...
true
84d38512656b363e0bbf643b98e278bccd81e87f
Ruby
daybreak/daybreak
/vendor/extensions/events/lib/events/extend/date.rb
UTF-8
651
3.40625
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
class Date def first_day self.strftime('%m/1/%Y').to_date end def days_in_month d,m,y = mday,month,year d += 1 while Date.valid_civil?(y,m,d) d - 1 end def last_day self.first_day + self.days_in_month - 1 end def ordinal_day(ordinal, day) # ordinal_day(1, 'Monday') month_start =...
true
b751b44b161410a4c0fbf1502bc076037288368a
Ruby
ajipionero/curso67RoR
/Ruby/range.rb
UTF-8
406
4.09375
4
[]
no_license
=begin Desafíos Métodos Útiles Adelante, intenta los siguientes métodos: .include?(value) => devuelve true or false .last => devuelve el último objeto en el Range .max => devuelve el valor máximo en el Range .min => devuelve el valor mínimo en el Range =end a= ["Andres","Catalina","Elisha"] b= [37,34,1,0]...
true
548e8f55c51763460eca2d9658ff77d010098319
Ruby
murphybytes/pqr
/script/thermal-storage
UTF-8
5,493
2.765625
3
[]
no_license
#!/usr/bin/env ruby $: << File.join( Dir.pwd, 'lib' ) require 'date' require 'mongoid' require 'models/sample' require 'models/data_set' require 'models/thermal_storage' require 'ostruct' require 'trollop' create_proc = proc { | global_options, command_options | puts puts "Creating a thermal storage record '#{com...
true
69c6e129dbc774b620a33131561712ef2815cb01
Ruby
marsh-sb/Ruby_practice
/Lesson10_04.rb
UTF-8
154
3.015625
3
[]
no_license
age = 21 if age >= 10 && age < 20 p "10代" elsif age >= 20 && age < 30 p "20代" elsif age >= 30 && age < 40 p "30代" else p "それ以外" end
true
42878e17b2c9001abc7b9e82738f9f5dc91e01ad
Ruby
cde/algorithms
/recursion/fibonnaci.rb
UTF-8
69
3.03125
3
[]
no_license
def fibonacci(n) n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2) end
true
ffb57b8bbe042db9ea95b565d71cdeff3bd3049d
Ruby
afishcalledrob/bank_tech_test
/lib/statement.rb
UTF-8
291
2.96875
3
[]
no_license
class Statement def pretty_print(history) printout = "Date || Credit || Debit || Balance\n" history.each do |transaction| printout += "#{transaction[:date]} || #{transaction[:credit]} || #{transaction[:debit]} || #{transaction[:balance]}\n" end p printout end end
true
7a55495d3befbb96e4152e6c64f2ce3faa8e39d4
Ruby
avsej/gson.rb
/benchmark/benchmark.rb
UTF-8
2,399
2.5625
3
[ "Apache-2.0" ]
permissive
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..') $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rubygems' require 'benchmark' require 'gson' require 'optparse' begin require 'json' rescue LoadError end options = { :times => 1_000, :file => File.expand_path(Fi...
true
ebabc5d1982231ed41874f620a250ecd2ed54676
Ruby
irshadkhan248/ruby
/Section 1:gettingStarted/helloWorld.rb
UTF-8
91
2.90625
3
[]
no_license
puts('helloWorld') puts('iam alive') puts(5) puts("3.14") puts "3"+"4" p true p "5" p 13/1
true
b23af386983f562e943ebc28df682fc89f3cb80e
Ruby
s8852s/ZCard-demo
/app/models/comment.rb
UTF-8
676
2.640625
3
[]
no_license
class Comment < ApplicationRecord acts_as_paranoid belongs_to :user belongs_to :post validates :content, presence: true default_scope { order(id: :desc) } # default_scope { where(deleted_at: nil) } # default_scope預設過濾器,就算進console查詢也會強制套用,除非用.unscope() # 平常少用 def owned_by?(user) self.user == ...
true
a509ebb1e630806c2172a2371dd10553fcc14709
Ruby
MitsunChieh/learn-ruby-the-hard-way
/ex3.rb
UTF-8
805
4.46875
4
[]
no_license
puts "I will now count my chickens." # print out string on display puts "Hens #{ 25 + 30 / 6 }" # 25 + 5 = 30 puts "Roosters #{ 100 - 25 * 3 % 4 }" # 100 - 75 % 4 = 100 - 3 = 97 puts "Now I will count the eggs." # print out string on display puts 3 + 2 + 1 - 5 + 4 % 2 - 1.0 / 4 + 6 # 6 - 5 + 0 - 0(0.25) + 6 = 7(6.75...
true
62783ad4e1d8d909f0cd0913d4ef2195bbbece36
Ruby
kukenko/mvc
/cgi-bin/search_03.rb
UTF-8
994
2.515625
3
[]
no_license
#coding: utf-8 require 'cgi' require 'httpclient' require 'simple-rss' require 'json' require 'tilt' require 'haml' def search_videos(query) url = 'http://gdata.youtube.com/feeds/api/videos' client = HTTPClient.new res = client.get(url, {'vq' => query, 'orderby' => 'viewCount'}) parse_videos(res.content) end ...
true
84aaa78df52885f90f86b689dc0bd3f5359abb99
Ruby
anaisbetts/Istoria
/lib/importers/mint_importer.rb
UTF-8
3,732
2.515625
3
[]
no_license
########################################################################### # Copyright (C) 2010 by Paul Betts # # paul.betts@gmail.com # # # # This program...
true
28d2e3dea0dcc4d3b3d745f66b00a30d36c18086
Ruby
peterlazzarino/vaccinetime
/lib/twitter.rb
UTF-8
1,370
2.6875
3
[ "Apache-2.0" ]
permissive
require 'twitter' class FakeTwitter def initialize(logger) @logger = logger end def update(str) @logger.info "[FakeTwitter]: #{str}" end end class TwitterClient def initialize(logger) @logger = logger @twitter = if ENV['ENVIRONMENT'] != 'test' && env_keys_exist? Twitter::R...
true
cdd7ce853bea2004f23c7da5a22dae39ed8bcc6c
Ruby
benfalk/picky_planner
/lib/picky_planner/meal_item_filter.rb
UTF-8
641
2.59375
3
[]
no_license
module PickyPlanner class MealItemFilter attr_reader :food_scope, :attributes def initialize(food_scope:, attributes:) @food_scope = food_scope @attributes = attributes end def call attributes.select do |_key, value| value.is_a?(Hash) && scoped_ids.include?(value[:food_id])...
true
93aaad502d7265fdb9b294888aed6a7ab70e0cb2
Ruby
ANILREDDY36/Basic-Rails-App
/app/models/game.rb
UTF-8
321
2.796875
3
[]
no_license
class Game < ApplicationRecord belongs_to :user def correctness return '-' if total_answers_count.zero? value = (good_answer_count.to_f / total_answers_count) * 100 value = value.round(2) value.to_s + '%' end private def total_answers_count good_answer_count + bad_answer_count end end...
true
fb39d31abdcc29a1206dbd7f558e1eabda36b0b9
Ruby
southpawgeek/perlweeklychallenge-club
/challenge-164/robert-dicicco/ruby/ch-2.rb
UTF-8
497
3.4375
3
[]
no_license
#!ruby.exe # AUTHOR: Robert DiCicco # DATE: 2022-05-10 # Challenge #164 Happy Numbers ( Ruby ) a = {} Seen = {} def SumDigitSquares(n) sum = 0 a = n.digits a.each do |d| sum += d**2 end if sum == 1 return 1 end if Seen.has_key?(sum) return 0 end Seen[sum] = 1 SumDigitSquares(sum) ...
true
c6edef5da2bb9539081c2bf7ce4eba3a1a77f07b
Ruby
Dol17480/cx3-7_files
/Labs/week_1/revision/universe/universe.rb
UTF-8
262
2.640625
3
[]
no_license
require('pry-byebug') def add_galaxy(universe, galaxy) universe[:galaxies].push(galaxy) end def get_spaceships(universe) spaceships = [] for spaceship in universe[:spaceships] binding.pry spaceships << spaceship end return spaceships end
true
892133f7716a4716ba2a3f482050ac2edb5b20ca
Ruby
salizzar/introduction-to-ruby
/exercises/03.rb
UTF-8
260
3.4375
3
[]
no_license
# common way def prime?(x) i = 2 limit = Math.sqrt(x) while i <= limit if x % i == 0 return false end i += 1 end return true end # ruby way def prime?(x) (2 .. Math.sqrt(x)).each { |n| return false if x % n == 0 } true end
true
94a59314444d99ecbc4d3db8e1b0f32df67a250f
Ruby
gengogo5/atcoder
/ABC/abc140/ABC140_C.rb
UTF-8
173
2.796875
3
[]
no_license
N = gets.to_i B = gets.split.map(&:to_i) s = 0 (N-1).times do |i| if i == 0 s += B[0] next end s += [B[i],B[i-1]].min end s += B[-1] # 最後の要素分 p s
true
e2dafc3362d2ebc4475d6b277b442a423b72d0da
Ruby
orangeman/RCG-Rails
/app/models/car.rb
UTF-8
474
2.96875
3
[]
no_license
class Car @@id = 0 attr_accessor :id, :route def initialize @id = @@id += 1 @route = Route.all[rand*Route.all.size] @route.rides << self end def to_s "Auto #{@id}: #{@route}" end def to_text @route.to_text end def detour @route.detour end def distan...
true
6106c363163b6411acd17d748b602379b7f5aeb2
Ruby
dspina79/webelosgamedesign
/ruby/battle/battle.rb
UTF-8
1,664
3.96875
4
[]
no_license
def play_round(p1Cards, p2Cards) player1_pile = [] player2_pile = [] while p1Cards.size() > 0 && p2Cards.size() > 0 p1Card = p1Cards.pop() p2Card = p2Cards.pop() if p1Card >= p2Card #puts "Player 1 wins" player1_pile.push(p1Card) player1_pile.pus...
true
4ab286ae836bfbbdcd2244241b8d42b5438cb720
Ruby
greghorne/CoordinateInfoAPI
/lib/CoordinateInfoModuleV1.rb
UTF-8
3,891
2.90625
3
[]
no_license
module CoordinateInfoModuleV1 require 'rest-client' require 'json' $db_host = ENV["RAILS_API_HOST"] $db_name = ENV["RAILS_API_DB"] $db_port = ENV["RAILS_API_PORT"] $db_user = ENV["RAILS_API_USER"] $db_pwd = ENV["RAILS_API_PWD"] # ========================================= class Co...
true
4e950dd7cc271f985f32e4be368934c01850da11
Ruby
sigilworks/LatinVerb
/lib/linguistics/latin/verb/latinverb/latinverb_input_sanitizer.rb
UTF-8
929
2.6875
3
[]
no_license
# encoding: UTF-8 # vim: set fdm=marker tw=80 sw=2: module Linguistics # Generalized module for handling lingustics related to Latin module Latin # Generalized module for handling lingustics related to Latin's verbal aspects module Verb class LatinVerb class LatinVerbInitializationError < Ex...
true
dc13a439a708a79afca2811ad4ac0ffcded133ab
Ruby
innhyu/Competency_Assessment
/app/models/question.rb
UTF-8
1,067
2.671875
3
[]
no_license
class Question < ActiveRecord::Base # Relationships has_many :indicator_questions, :dependent => :destroy has_many :indicators, through: :indicator_questions # Validations validates_presence_of :question # Scopes scope :active, -> { where("questions.active = ?", true) } scope :inactive, -> {...
true
9c4211a96b2475b857a220b50b26dc17d2586e44
Ruby
otobrglez/promet-rb
/lib/promet/jruby_decoder.rb
UTF-8
2,045
2.984375
3
[ "MIT" ]
permissive
# coding: utf-8 require 'java' require 'singleton' # 'java_import' is used to import java classes java_import 'java.util.concurrent.Callable' java_import 'java.util.concurrent.FutureTask' java_import 'java.util.concurrent.LinkedBlockingQueue' java_import 'java.util.concurrent.ThreadPoolExecutor' java_import 'java.uti...
true
3dcbaebcacfa016a2810168a36f10f0f8d1e938c
Ruby
HELENE-AUERBACH/LN_The-Hacking-Project-ln-eventbrite-minimum
/app/helpers/events_helper.rb
UTF-8
301
2.5625
3
[]
no_license
module EventsHelper def admin?(user, event) result = false if event.admin == user result = true end result end def attending?(user, event) result = false if !event.attendings.nil? && event.attendings.include?(user) result = true end result end end
true
48b001bcdc98f0b444842e180e9febf1191a2be6
Ruby
DouglasAllen/code-The_Book_of_Ruby
/code/ch04/array_index.rb
UTF-8
500
4.5625
5
[]
no_license
# ch04 The Book of Ruby - http://www.sapphiresteel.com arr = ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] # Here we print each char in sequence print(arr[0, 5]) puts print(arr[-5, 5]) puts print(arr[0..4]) puts print(arr[-5..-1]) puts # Here we inspect the chars. Notice that we can # index into an array ...
true
b83bb192a056800d75c4a4add0d19f7f1dfc0095
Ruby
cfan-guo/leetcode-curation-topical
/algorithm-study-plan/two-sum.rb
UTF-8
291
3.421875
3
[]
no_license
# https://leetcode.com/problems/two-sum/ # [Easy] # # @param {Integer[]} nums # @param {Integer} target # @return {Integer[]} def two_sum(nums, target) indices = {} nums.each_with_index do |num, idx| return [idx, indices[num]] if indices[num] indices[target-num] = idx end end
true
3e46bf7ff9f61ce88cf3429b638032062b54ae24
Ruby
KazuCocoa/koboldy
/lib/koboldy/io.rb
UTF-8
681
2.625
3
[ "MIT" ]
permissive
require "open3" class Koboldy module Io class << self def capture_stdout out = StringIO.new $stdout = out yield out.string ensure $stdout = STDOUT end def capture_stderr out = StringIO.new $stderr = out yield out.str...
true
d81c2433d79c43a722284e215ff962a187e8fc22
Ruby
marcocarvalho/technical_analysis
/lib/technical_analysis/data/load/from_csv.rb
UTF-8
1,074
2.640625
3
[ "MIT" ]
permissive
module TechnicalAnalysis::Data::LoadInterfaces module ClassMethods def load_from_csv(filename, options = {}) s = self.new s.load_from_csv(filename, options) s end end def load_from_csv(filename, options = {}) opt = { format: :first_line, period: :day, skip_first_line: false }.merg...
true
5a55894241b01acd4c158fbb44d117c73d3d6392
Ruby
hckim/ruby
/1.String.rb
UTF-8
551
3.34375
3
[]
no_license
#puts "this.".class #puts "this".respond_to?(:upcase) #puts "this".is_a? String #puts "this".kind_of? Object #puts "this".instance_of? String # puts "this".methods ## String # count # split #a="this is a string" # gsub #c=a.split(" ") #puts c.length #puts c[3] #puts a.gsub!(" ", "*") #puts a # upcase # downcas...
true