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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
55a6bb10da75262e69d08ba5156fc34d484d7d09 | Ruby | btreim/ruby | /stock-picker.rb | UTF-8 | 778 | 3.984375 | 4 | [] | no_license |
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b = [9, 8, 7, 6, 5, 4, 3, 2, 1]
c = [3, 4, 2, 6, 7, 4, 9, 8, 5]
d = [8, 6, 9, 2, 7, 4, 1, 5 ,1]
e = [10, 11, 2, 9, 4, 3, 5, 6]
f = [17, 3, 6, 9, 15, 8, 6, 1, 10]
def stock_picker(array)
max = array.max
maxIndex = array.index(max)
min = array.min
minIndex = array.index(min)
if ma... | true |
87d2d7644cf776827863d8174cd85f47dcc48981 | Ruby | jasonthompson/csv_to_ledger | /lib/csv_to_ledger/cli.rb | UTF-8 | 1,638 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'csv'
require 'csv_to_ledger/formatter'
module CSVToLedger
class CLI
attr_reader :input_file
attr_reader :csv_settings
attr_reader :vendor_account_matcher
attr_accessor :output
def initialize(input_file)
@input_file = input_file
@csv_settings = {:headers => true,
... | true |
3509366d62febd3b54dc3ef69d4b2b538ad852d0 | Ruby | experteer/hop_hop | /lib/hop_hop/test_sender.rb | UTF-8 | 440 | 2.9375 | 3 | [
"MIT"
] | permissive | module HopHop
# This can be used in a test environment to see whats pushed into the queue.
class TestSender
def initialize
reset
end
def publish(data, options)
@events << [data, options]
end
def reset
@events = []
end
def size
@events.size
end
def empt... | true |
6b8131f9caa534a38386edbe5f0b099d144dfb43 | Ruby | techworldhello/WDI-HW | /Jessie/wk04/5-fri/shelter.rb | UTF-8 | 333 | 3.328125 | 3 | [] | no_license | require 'pry'
# The shelter should display all the clients.
# The shelter should display all the animals.
class Shelter
attr_accessor :client_base, :animal_base
def initialize
@clients = []
@animals = []
end
def is_client(client)
@clients.include? client
end
def add_animal(animal)
@animals << animal... | true |
9e826abdbe02e166cc41ef9804ef07b7265f1083 | Ruby | mforoni/ruby-launch-plan | /quickstart/examples/mutating-methods/non_mutating_method.rb | UTF-8 | 430 | 3.578125 | 4 | [
"MIT"
] | permissive | # frozen_string_literal: true
def compact_array(arr)
puts 'begin compact_array(arr)'
puts ' arr = ' + arr.inspect
copy = arr.compact
puts ' copy = arr.compact'
puts ' arr = ' + arr.inspect
puts ' copy = ' + copy.inspect
puts 'end compact_array(arr)'
end
arr = [1, nil, 2]
puts 'arr = ' + arr.inspect
... | true |
66c37d2ace342b613eb7ff33452fbcdddbfa8188 | Ruby | clynchga/class_3_exercises | /collections_exercise.rb | UTF-8 | 529 | 3.703125 | 4 | [] | no_license |
data = []
100.times do |num|
user_details = {id: num, email: "user_#{num}@gmail.com", username: "user_#{num}", age: rand(18..75)}
stored_tweets = ["I'm user #{num}", "This is my second tweet!"]
user_hash = {user: user_details, tweets: stored_tweets}
data.push(user_hash)
end
puts "=============="
puts "user_2'... | true |
e789fe97171d8df96db21cad9f9b1ebcc589da9c | Ruby | valepin/drugwar171 | /municipalities.rb | UTF-8 | 1,112 | 3.15625 | 3 | [] | no_license | # some code contained courtesy of https://github.com/cesarsalazar
require 'csv'
require 'json'
require 'net/http'
require 'uri'
#global
country = "Mexico"
CSV.open("data/latlon.csv", "wb") do |csv|
CSV.foreach("data/stateandmuni.csv") do |row|
parsed = row[0].split(/\t/)
state = parsed[0]
municipality ... | true |
525769f782450bbb62d141683117971d19511c0a | Ruby | UbuntuEvangelist/therubyracer | /vendor/cache/ruby/2.5.0/gems/cancancan-3.0.1/lib/cancan/ability/rules.rb | UTF-8 | 2,976 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module CanCan
module Ability
module Rules
protected
# Must be protected as an ability can merge with other abilities.
# This means that an ability must expose their rules with another ability.
def rules
@rules ||= []
end
private
d... | true |
5ec2ec93d496f5320445bf02a0d61a06766cc9e9 | Ruby | mCstl/h_data | /utilit/pas-unit/pass.rb | UTF-8 | 1,373 | 3.109375 | 3 | [] | no_license | #!/usr/bin/ruby
def start
print (" coose any module:\n\t(1)split log:pass\n\t(2)create log:pass \n")
mod = gets().chomp()
if mod == "1" then
split
elsif mod == "2"
join
else
start
end
end
def split
print(" split login - password\n\n")
print(" INFILE > ")
ifile = gets().chomp()
print(" infile => #{... | true |
294662e706d16af38998f0c2fb447aef8384e946 | Ruby | tommyrharper/bank-tech-test | /spec/account_spec.rb | UTF-8 | 1,123 | 2.84375 | 3 | [] | no_license | require 'account'
describe Account do
context 'deposits' do
it 'accepts a deposit and returns the amount and balance' do
transaction_double = double(:Transaction, new: '')
statement_double = double(:Statement, add: '')
account = Account.new(statement_double, transaction_double)
account.d... | true |
00f9a45e93282f54e27894ee564c90205210f338 | Ruby | petrachi/ogame_maximixe_points | /app/compilers/artillery_compiler.rb | UTF-8 | 1,384 | 2.515625 | 3 | [] | no_license | class ArtilleryCompiler < PlanetCompiler
def type
:artillery
end
def blueprint_name
"#{ ressource }_artillery"
end
def uid_buildings
/^.*_(storage|ship)$/
end
def compile_produces
building.sustains[:hull]
end
def compile_costs
building.costs
end
DEFCON = 1
def compile_u... | true |
2750683c99fd83b7692a85b670938c445d8fc565 | Ruby | mwcm/asciinema-server | /spec/models/user_spec.rb | UTF-8 | 3,051 | 2.515625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'rails_helper'
describe User do
it 'gets an auth_token upon creation' do
attrs = attributes_for(:user)
attrs.delete(:auth_token)
user = described_class.create!(attrs)
expect(user.auth_token).to be_kind_of(String)
end
describe "#valid?" do
let!(:existing_user) { create(:user, userna... | true |
17f4673ba7fd038089cd5abed8b387960550ea0f | Ruby | sergimartnez/GameStats | /exercise_1.rb | UTF-8 | 7,612 | 3.484375 | 3 | [] | no_license | require 'pry'
class String
def is_i?
/\A[-+]?\d+\z/ === self
end
end
class Game
attr_accessor :players_count, :team_1_name, :team_2_name, :team_1_players,
:team_2_players, :winner, :mvp, :team_1_points, :team_2_points
def initialize
@players_count = 0
@winner=nil
@mvp=nil
... | true |
0a28d279885dd6d75f1758d31339aebae5256310 | Ruby | JustinData/GA-WDI-Work | /w01/d03/Bradley/temperature.rb | UTF-8 | 544 | 4.46875 | 4 | [] | no_license | def convert_to_fahrenheit(c)
f = c * (9.0 / 5.0) + 32
f
end
def convert_to_kelvin(c)
k = c + 273
k
end
def converter
puts "enter a temperature (in celsius) you'd like to convert"
temp = gets.chomp.to_i
puts "convert to : (k)elvin or (f)ahrenheit"
choice = gets.chomp.downcase
case choice
when 'k'... | true |
69ec5e5fd02027a21d7d29b4bbecebe5e281bc9d | Ruby | vaheder/jekyll-picture-tag | /lib/jekyll_picture_tag/cache/base.rb | UTF-8 | 1,583 | 2.53125 | 3 | [
"BSD-3-Clause"
] | permissive | require 'json'
module PictureTag
module Cache
# Basic image information cache functionality
module Base
def initialize(base_name)
@base_name = base_name
end
def [](key)
data[key]
end
def []=(key, value)
raise ArgumentError unless template.keys.include? ... | true |
2bbe93bb87c4687577f9323416fffe1a249a4f3c | Ruby | Kadvin/beta-pdm-tools | /lib/pdm/commands/pressure_command.rb | UTF-8 | 1,154 | 2.5625 | 3 | [] | no_license | require 'pdm/command'
require 'pdm/generic_option'
module Pdm
module Commands
class PressureCommand < Pdm::Command
include Pdm::GenericOption
def initialize
super 'pressure', 'Pressure test related operations', :port => 8020
add_server_option
add_port_option
... | true |
275b4f2a0621d79f2f3fecff8b32b68dff63b9f3 | Ruby | masao/ttl2html | /bin/xlsx2shape | UTF-8 | 170 | 2.828125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require "xlsx2shape"
if ARGV.size == 0
puts "USAGE: xlsx2shape file.xlsx"
exit
end
include XLSX2Shape
turtle = xlsx2shape(ARGV[0])
puts turtle
| true |
387f549a314f0c5e32254178b0deaf84135a3d4d | Ruby | abeyuya/nodasan | /main.rb | UTF-8 | 901 | 3.515625 | 4 | [] | no_license | #!/usr/bin/env ruby
require "pp"
# 入力データ取得
data = gets.chomp.split(" ")
item_prise_count = data[0].to_i
mix_prise_count = data[1].to_i
item_prise_list = Array.new
mix_prise_list = Array.new
item_prise_count.times {
item_prise_list.push(gets.to_i)
}
mix_prise_count.times {
mix_prise_list.push(gets.to_i)
}
# 計... | true |
536be0024ef0e77557ddbbd2ece7ce579ea45059 | Ruby | konspirio/konspirio.github.io | /bin/optimze_img.rb | UTF-8 | 3,542 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
# This script crawls the Image directory and makes the graphics more render-worthy.
# This includes creating a low-resolution (20% size) JPEG that can be used as
# The background, and WEBP files for 3 sizes (Mobile, Tablet, Desktop) with 2x for UHD.
#
# I probably don't need to optimize the PNG or ... | true |
c42d686942c058efe486b45207d136ffa9dc3def | Ruby | ikeeps/demos | /pieces-script/ruby/simple/array-add-array.rb | UTF-8 | 65 | 2.9375 | 3 | [] | no_license | list = []
list += ['a', 'b']
list += ['c', 'd']
puts list.to_s | true |
62b1a8dff6efcea5ea79dca60599b6723b3c7c77 | Ruby | coderhs/benchmarking-ruby-scripts | /hash_storage/hash_storage.rb | UTF-8 | 365 | 2.859375 | 3 | [] | no_license | require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |r|
N = 100000
a = [1, 2, 3, 4, 5]
r.report('{}') do
my_hash = {}
my_hash[:t] = 1
my_hash[:b] = 2
end
r.report('store') do
my_hash = {}
my_hash.store(:t, 1)
my_hash.store(:b, 2)
end
r.report('{:a => 1}') do
my_hash... | true |
189b9b87c9ba5782c79f4e8d8ce5a83be5e74f1a | Ruby | burtlo/ruby-metrics-core | /lib/ruby-metrics/instruments/gauge.rb | UTF-8 | 546 | 2.625 | 3 | [
"MIT"
] | permissive | require_relative 'instrument'
module Metrics
module Instruments
class Gauge < Instrument
attr_reader :units
def initialize(options = {}, &block)
raise ArgumentError, "a block is required" unless block_given?
@block = block
@units = options[:units]
end
def get
... | true |
6e7a47ccc46de8fa34851712ab0ae6fe5176464c | Ruby | rejmama1/SemestralProject | /SemestralProject/lib/naive/naive_algorithm.rb | UTF-8 | 1,667 | 3.234375 | 3 | [] | no_license | require 'lib/naive/stack'
require 'lib/problem/configuration'
require 'lib/problem/writable_result'
#Brute-force algorithm to solve knapsack problem
class NaiveAlgorithm
#Gives best found fitness
attr_reader :best_fitness
#Gives best found configuration of knapsack
attr_reader :best_configuration
include Writ... | true |
5a966b68d0550502aaaafb3a845efc44b7407450 | Ruby | JEG2/warehouse_keeper | /lib/warehouse_keeper/animation.rb | UTF-8 | 1,146 | 2.96875 | 3 | [] | no_license | module WarehouseKeeper
class Animation
def initialize(length = nil)
@length = length
@start_code = nil
@started_at = nil
@started = false
@update_code = nil
@finish_code = nil
@finished = false
end
attr_reader :length, :start_code, :started_at, :upd... | true |
3414717996cde96e93a6b36cb848726103a8a054 | Ruby | Mirrior/code_exercises | /ruby_exercises/next_letter.rb | UTF-8 | 565 | 3.796875 | 4 | [] | no_license | require 'rspec'
#My way
# def increment_value str
# str.concat(str.next.split(//)[-1])
# end
# Different way (Fewer Methods than first time)
def increment_value str
str.concat str.next.slice(-1)
end
#Jordan's way
#def increment_value str
# str + str.next.slice(-1)
#end
describe 'Increment string value sequence... | true |
ff62ab2c4b97768787f32fb2fa61a4792a38a6ac | Ruby | sdexter91/what_should_i_eat | /lib/what_should_i_eat.rb | UTF-8 | 1,159 | 3.015625 | 3 | [
"MIT"
] | permissive | =begin require "what_should_i_eat/version."
require 'net/http'
require 'json'
module WhatShouldIEat
def WhatShouldIEat.fresh
result = Net::HTTP.get('www.edamam.com', '/search?type=Feeds')
recipes = JSON.parse(result)
name = recipes.first['items'].first['label']
url = recipes.first['items'].first['u... | true |
01174131f157279a7433d7145571c71d353a011d | Ruby | repomaa/dimscan | /lib/dimscan/png_scanner.rb | UTF-8 | 668 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'dimscan/base_scanner'
module Dimscan
# Scans dimensions from a PNG image
class PNGScanner < BaseScanner
IHDR = [0x49, 0x48, 0x44, 0x52]
protected
def scan(bytes)
# Dimensions are in 8 bytes after IHDR
last_slice = nil
bytes.each_cons(IHDR.size + 8) do |slice|
yield ... | true |
7ef1146a33d9a07ff0c166f0c7fc5eedc80eb682 | Ruby | sellis7/chess-project | /app/models/rook.rb | UTF-8 | 703 | 3.046875 | 3 | [] | no_license | class Rook < GamePiece
# parameters should be converted to intgers in caller
def valid_move?(new_x, new_y)
# cannot land on similar player piece - handled by is_obstructed? method, game.rb
# any pieces in path from start to finish? - handled by is_obstructed? method, game.rb
# self.x = Column index; self.y = ... | true |
6c1976ab3542b84f4c84e58dc62eb18b3f914d96 | Ruby | cromulencellc/chess-aces | /phase_2/example/beacon/reference_pov_1_s1/pov.rb | UTF-8 | 1,760 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #!/bin/env ruby
require "logger"
require "http"
require "nokogiri"
require 'active_support/core_ext/object/to_query'
LLL = Logger.new(STDERR,
formatter: proc do |sev, datetime, progname, msg|
"#{sev}: #{msg}\n"
end)
MAX_PIN = 0xffffffffffffffff
class Pov
att... | true |
7878056667d3cdbf0d040de3658f9ab2a113403c | Ruby | lubosmichalic/boris_bikes | /spec/docking_station_spec.rb | UTF-8 | 1,394 | 3.203125 | 3 | [] | no_license | require "docking_station"
describe DockingStation do
it "assigns object in the DockingStation to the bike variable" do
is_expected.to respond_to(:release_bike)
end
it "gets a bike and expects the bike to be working" do
bike = Bike.new
expect(bike).to be_working
end
it "docks the bike back to a do... | true |
0b343a00caa8b9453db61a248744d68d43df766c | Ruby | DerDackel/hbase101companies | /total.rb | UTF-8 | 712 | 2.890625 | 3 | [] | no_license | import 'org.apache.hadoop.hbase.client.HTable'
import 'org.apache.hadoop.hbase.client.Scan'
import 'org.apache.hadoop.hbase.util.Bytes'
def jbytes(*args)
args.map {|arg| arg.to_s.to_java_bytes}
end
employees = HTable.new(@hbase.configuration, "meganalysis_employees")
depts = HTable.new(@hbase.configuration, "megana... | true |
0c54b84f0e06029c6c91873dc4e0ad082cd27719 | Ruby | lfrancoeur/Ruby | /The_fist_adn_last_Methods.rb | UTF-8 | 968 | 4.71875 | 5 | [] | no_license | arr = [1, 3, 5, 7, 9, 15, 21, 18, 6]
p arr.first #extracts first element of array
p arr.last #extracts last element of the array
p arr.first(3) #calls the first 3 elements of the array
p arr.last(2) #calls teh last 2 elements of an array
p arr.first #this will return a num
p arr.last #this will return a num
p arr.f... | true |
c0d402d4834c9b19a919a94f48399f54f5503b25 | Ruby | roseweixel/lacquer-lover | /app/models/friendship.rb | UTF-8 | 1,327 | 2.625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # == Schema Information
#
# Table name: friendships
#
# id :integer not null, primary key
# user_id :integer
# friend_id :integer
# created_at :datetime
# updated_at :datetime
# state :string(255)
#
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_nam... | true |
fcc34252ee1ed21f67ff10a9154fc905766e7d9d | Ruby | boof/expect-me | /lib/expect/expectation/results.rb | UTF-8 | 464 | 2.765625 | 3 | [] | no_license | class Expectation
class Result
attr_reader :object, :clause
def initialize(object, clause)
@object, @clause = object, clause
end
def ok?
false
end
def failed?
false
end
def to_s
@clause
end
end
class Success < Result
def ok?
true
end
... | true |
6f827b9e738c696080197837e8a569063c273a5a | Ruby | Agathasta/exercism_ruby_track | /acronym/acronym.rb | UTF-8 | 121 | 2.734375 | 3 | [] | no_license | # frozen_string_literal: true
class Acronym
def self.abbreviate(str)
str.scan(/\b[a-zA-Z]/).join.upcase
end
end
| true |
a3db6f43fe321b1751af4dcdf0fd2a6f8ded192c | Ruby | caiusmersa/app-academy-work | /w2d4/game_input.rb | UTF-8 | 2,432 | 3.484375 | 3 | [] | no_license | require_relative 'game.rb'
require_relative 'pos_helper.rb'
require "io/console"
class GameInput
def self.new_game_from_menu
p1, p2 = 0, 0
cur = [2, 0]
while true
GameInput.draw_menu(p1, p2, cur)
input = GameInput.read_char
case input
when "\e[A" # ... | true |
9841f0dfec8d6558d7187c9c6192defa57e61f7f | Ruby | zjucsxxd/similie | /test/test_distance.rb | UTF-8 | 638 | 2.640625 | 3 | [
"MIT"
] | permissive | require_relative 'helper'
describe 'Similie image distance' do
it 'should work for similar images' do
images = (1..5).map {|n| Similie.new(File.join($testdir, 'lena%d.png' % n ))}
images.unshift nil
assert_equal 2, images[1].distance(images[2])
assert_equal 9, images[2].distance(images[3])
ass... | true |
2faca00d7cb7dc3b14df2bb58886ba15ef151f3d | Ruby | strathmeyer/18xx | /lib/engine/hex.rb | UTF-8 | 2,754 | 3 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative 'connection'
module Engine
class Hex
attr_reader :connections, :coordinates, :layout, :neighbors, :tile, :x, :y, :location_name
DIRECTIONS = {
flat: {
[0, 2] => 0,
[-1, 1] => 1,
[-1, -1] => 2,
[0, -2] => 3,
[1, -1]... | true |
8ebb2f9aa7d49bcff618d0e2f520864082988308 | Ruby | ClayShentrup/method_man | /spec/method_man_spec.rb | UTF-8 | 3,504 | 2.96875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require('method_object')
require('ostruct')
RSpec.describe(MethodObject) do
context('with attrs') do
let(:method_object) do
Class.new(described_class) do
attrs(:block, :attr1, :attr2)
def call
instance_eval(&block)
end
def local_met... | true |
9e5a5374464a7c4aa19b7269103d265c2b4e9902 | Ruby | dnewbie25/App-Academy-Open | /blocks_project/lib/part_1.rb | UTF-8 | 555 | 3.703125 | 4 | [] | no_license | def select_even_nums(array)
return array.select {|el| el.even?}
end
def reject_puppies(dogs)
return dogs.reject {|dog| dog['age'] <= 2}
end
def count_positive_subarrays(array)
return array.count {|sub_arr| sub_arr.sum > 0}
end
def aba_translate(word)
vowels = 'aeiou'
aba_word = ''
word.each_char do |char... | true |
eeee3c1a64f287fa3b67d11e72699ac4a6a49302 | Ruby | gwan93/ruby_math_game | /player.rb | UTF-8 | 192 | 3.578125 | 4 | [] | no_license | class Player
attr_accessor :current_life, :name
def initialize(name)
@name = name
@current_life = 3
end
def lose_life
self.current_life = self.current_life - 1
end
end | true |
cff8c49626168b7ef994f2a639c19add939046b4 | Ruby | matthewpeak/ruby-enumerables-reverse-each-word-lab-nyc-web-021720 | /reverse_each_word.rb | UTF-8 | 310 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word_with_each(str)
og_array = str.split(" ")
array = []
og_array.each do|str|
array << str.reverse
end
array.join(" ")
end
def reverse_each_word(str)
array = str.split(" ")
xarray = []
array.collect do|string|
xarray << string.reverse
end
xarray.join(" ")
end | true |
fc20eec03545399904e2e26e06cb0fa1e757091e | Ruby | bsaliba1/leet-code-questions | /problems/arrays/238.rb | UTF-8 | 1,229 | 3.390625 | 3 | [] | no_license | # @param {Integer[]} nums
# @return {Integer[]}
def product_except_self_slow(nums)
output = []
i = 0
while i < nums.size do
output.push(
nums.each_with_index.reduce(1) do |product, (element, index)|
index == i ? product : product*element
end
)
... | true |
cff83870c82e641d40360d7f0fb94747b06c04d5 | Ruby | danhealy/dragonruby-zif | /app/ui/labels/form_field.rb | UTF-8 | 1,500 | 2.78125 | 3 | [
"MIT"
] | permissive | module ExampleApp
# This is an example of bundling Zif::UI::Input together with a descriptive label and a background sprite
class FormField < Zif::CompoundSprite
attr_accessor :input, :background, :label
def initialize(name: Zif.unique_name('form_field'), x: 0, y: 0, label: 'Input: ', char_width: 10)
... | true |
4d08270439a91ad3221622584907aa9305d9a7f0 | Ruby | blobbyblobfish/ruby-oo-relationships-practice-auto-shop-exercise-nyc01-seng-ft-042020 | /tools/console.rb | UTF-8 | 1,073 | 2.890625 | 3 | [] | no_license | require_relative '../config/environment.rb'
def reload
load 'config/environment.rb'
end
tahoe = Car.new("Chevy", "Tahoe", "Pickup")
bus = Car.new("School Bus", "Bluebird", "Bus")
little_horse = Car.new("Honda", "Accord", "Standard")
puma = Car.new("Jaguar", "Puma", "Sports")
ted = CarOwner.new("Ted")
alice = CarO... | true |
c6653f0d32a3bbbf1457303ebe9a9f4c842d4b91 | Ruby | tsaldanha/inventos | /app/controllers/cart_controller.rb | UTF-8 | 2,215 | 2.515625 | 3 | [] | no_license | class CartController < ApplicationController
helper ApplicationHelper
def index
check
@items = []
session[:cart].each do |item|
@items.push(get_item(item["id"]))
end
@total = get_total
end
def get_item(id)
@item = Product.find(id)
... | true |
2c89e2377dd203b743b8fa985813ce9293911d64 | Ruby | nobuosan/joint_dev_task | /game/monster.rb | UTF-8 | 328 | 3.25 | 3 | [] | no_license | require './character'
class Monster < Character
def attack(brave)
damage = @attack-brave.defense
brave.hp -= damage
brave.hp=0 if brave.hp <= 0
puts <<~EOF
モンスターが攻撃
勇者に#{damage}のダメージ
勇者の残りのHP: #{brave.hp}
-------------------------
EOF
end
end
| true |
4acad694d3073ffdcfc17a682b1c2d287e73d04c | Ruby | spiffistan/kush | /lib/kush/input.rb | UTF-8 | 3,497 | 2.90625 | 3 | [] | no_license | require_relative 'keycodes'
require_relative 'glyphs'
require_relative 'cursor'
require_relative 'refinements/string_extensions'
module Kush
module Input
include Keycodes
include Glyphs
extend Cursor
using Refinements::StringExtensions
def self.buffer
@@buffer ||= String.new
en... | true |
6ba74de1eac08119160a9e4520379b99b2bf96b3 | Ruby | jkvyff/OO-Animal-Zoo-seattle-web-career-042219 | /lib/Zoo.rb | UTF-8 | 602 | 3.59375 | 4 | [] | no_license | class Zoo
attr_accessor :name, :location
@@all = []
def initialize(name, location)
@name = name
@location = location
@@all << self
end
def animals
Animal.all.select do |animal|
animal.zoo == self
end
end
def animal_species
self.animals.map do |animal|
animal.species
end.uniq
end
def fi... | true |
8e02bb026f0168f7a0bdfad925fe8d07c5d0beea | Ruby | sasadangelo/CourseRuby | /Excercise8.rb | UTF-8 | 213 | 3.78125 | 4 | [] | no_license | # Excercise 8
#
# Same as Excercise 7 but with parameters.
def who_says_what
yield("Dave", "hello")
yield("Andy", "goodbye")
end
who_says_what {|person, phrase| puts "#{person} says #{phrase}"}
| true |
2889990d6aa58af18af75be065276e6ff9ff7d23 | Ruby | Nazarii1017/console_program | /figures_menu.rb | UTF-8 | 193 | 2.609375 | 3 | [] | no_license | require File.expand_path('../menu.rb', __FILE__)
class FiguresMenu
attr_accessor :area, :perimeter
def initialize(area, perimeter)
@area = area
@perimeter = perimeter
end
end
| true |
ba1f111900901654f6a23f52834aad77c38d73fe | Ruby | rmatambo8/Ruby-Small-Problems | /easy_3/palindromic_numbers.rb | UTF-8 | 304 | 3.546875 | 4 | [] | no_license | def real_palindrome?(str)
str = str.downcase.delete('^a-z0-9')
str == str.reverse
end
def palindromic_number?(numbers)
real_palindrome?(numbers.to_s)
end
p palindromic_number?(34543) == true
p palindromic_number?(123210) == false
p palindromic_number?(22) == true
p palindromic_number?(5) == true | true |
aa0fc2977511b53788a2b07548c8bc63635af1f5 | Ruby | sumoist/basic_course | /Lesson_7/classes/carriage/passenger_carriage.rb | UTF-8 | 385 | 3.34375 | 3 | [] | no_license | class PassengerCarriage < Carriage
attr_reader :used_seat
def initialize(seats)
@seats = seats
@used_seat = 0
super (:passenger)
end
def take_seat
@used_seat += 1 if @used_seat < @seats
end
def free_seat
@free_seat = @seats - @used_seat
end
def to_s
"Вагон номер:#{number}, т... | true |
cff5431a86be13ecb6aed79e0bf60b5d7ed2d21c | Ruby | rhykw/RubyPico | /resources/sample/chat.rb | UTF-8 | 800 | 2.84375 | 3 | [
"Unlicense",
"BSD-2-Clause",
"MIT"
] | permissive | # Define "main" function or "Chat" class
require 'chat_maker'
require 'chat/google'
require 'chat/hit_and_blow'
require 'chat/irb'
require 'chat/map'
require 'chat/openlink'
require 'chat/wiki'
class ChatSample
def initialize
@chat = ChatMaker.new
@chat.add :google, Google
@chat.add :hit_and_blow,... | true |
b80c14f4976857be1ac8ba28d001611b27df069f | Ruby | bruno248/morpion | /lib/board.rb | UTF-8 | 808 | 3.078125 | 3 | [] | no_license | require 'pry'
require_relative 'Boardcase'
class Board
attr_accessor :board_hash, :round
def initialize
@round = 0
@board_hash = Hash.new
named= %w(A B C)
named.each do |n|
3.times do |i|
@board_hash["#{n}#{i+1}"] #= CaseBoard.new("#{n}#{i+1}")
end
end
end
def chang... | true |
9daa15e797a93972aa3091318a4d36c1d1fb3fe3 | Ruby | FrancescoPalma/CodeClan---CX3 | /week_2/d2/snakes_and_ladders/specs/game_spec.rb | UTF-8 | 1,279 | 3.265625 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../game')
require_relative('../board')
require_relative('../player')
class TestGame < Minitest::Test
def setup
positions = {
2 => 4,
7 => -7
}
board = Board.new(9, positions)
@player1 = Player.new('Tony')
@player1... | true |
ea049a8053e87ca25e90f63ad8bccfeafb04f0f0 | Ruby | NoMoreZer0/Ruby-Quests | /ruby-quest01/ex04/my_first_incrementation.rb | UTF-8 | 64 | 2.796875 | 3 | [] | no_license | val = 0
val += 1
puts(val)
val -= 2
puts(val)
val += 3
puts(val) | true |
2c399d2269926d284949ac04594d8bccb16ebb43 | Ruby | robteaw/MemActTrac | /app/models/prospect.rb | UTF-8 | 824 | 2.53125 | 3 | [] | no_license | class Prospect < ApplicationRecord
belongs_to :membership_type
belongs_to :class_time
before_create :set_defaults
def convert_to_member
self.signed_up = true
end
def set_defaults
self.showed=0
self.signed_up=0
end
def full_name
#this function is to make the prospect views easier
... | true |
6b7a2aa2d9a0b5efb882939d6353379e211da2e2 | Ruby | TheGuth/launch_school | /course_120/optional_oop/lecture_classes_and_objects.rb | UTF-8 | 3,353 | 4.75 | 5 | [] | no_license | # Lecture: Classes and Objects
# 1. Given the below usage of the Person class, code the class definition
class Person
attr_accessor :name
def initialize(n)
@name = n
end
end
bob = Person.new('bob')
bob.name
bob.name = 'Robert'
bob.name
# 2. Modify the class definition from the above to facilitate the fol... | true |
e7c068dc142bf7b8067c4170ae61a5340bb82091 | Ruby | j-wilkins/enum-rb | /lib/enum/store/memory_store.rb | UTF-8 | 391 | 3.140625 | 3 | [
"MIT"
] | permissive |
class Enum
class MemoryStore
def initialize(store = nil)
@store = store || Hash.new
end
def get_value(key)
@store.fetch(key) rescue fail_fetch(key)
end
def set_value(name, value)
@store[name] = value
end
private
def fail_fetch(key)
raise ArgumentError.new(... | true |
09295d11a46ddffd06f461df1c184148160a125b | Ruby | GeovaneDaSilva/console-rock | /app/lib/database_timeout.rb | UTF-8 | 919 | 2.84375 | 3 | [] | no_license | # Enables an extended database operation by setting the statement_timeout to a custom value, in seconds.
# You can also pass 0, or :unlimited, to indicate that the query can run for as long as it wants.
# It also accepts duration objects, e.g., 1.hour
module DatabaseTimeout
module_function
def timeout(value_in_sec... | true |
7f7444f5806d9d22fdc583fd74f1995e404b20cf | Ruby | nanma80/euler_project | /p226_250/p234/main.rb | UTF-8 | 1,142 | 3.03125 | 3 | [] | no_license | require '../../common'
def semidivisibles_sum(limit)
prime_limit = Math.sqrt(limit) + 100
primes = Prime::Cache.new(prime_limit).primes
semidivisibles_sum = 0
(0..primes.length - 2).each do |index1|
prime1 = primes[index1]
break unless prime1 * prime1 < limit
prime2 = primes[index1 + 1]
mult... | true |
bcaae7061f2c52630c88e3c65a11aaca2f788c65 | Ruby | emsk/backlog_kit | /lib/backlog_kit/response.rb | UTF-8 | 498 | 2.734375 | 3 | [
"MIT",
"Ruby"
] | permissive | require 'backlog_kit/resource'
module BacklogKit
class Response
attr_reader(:headers, :status, :body)
def initialize(response)
@headers = process(response.headers)
@status = process(response.status)
@body = process(response.body)
end
private
def process(raw)
case ra... | true |
4b3db23ac16c24008833b00a89f5acdbd48e7ff5 | Ruby | rusllonrails/ruby_challenges | /challenges/21_write_number_in_expanded_form.rb | UTF-8 | 1,012 | 4 | 4 | [] | no_license | # frozen_string_literal: true
#
# 21: Write a number in expanded form
#
# BRIEF:
#
# You will be given a number and you will need to return it as a string in Expanded Form.
#
# For example:
#
# 12 should return '10 + 2'
# 42 should return '40 + 2'
# 70304 should return '70000 + 300 + 4'
#
# NOTE:
#
# All n... | true |
eceebec0f6b6c20855d615b626c52934428f311c | Ruby | masterzora/tawny-cdk | /lib/cdk/alphalist.rb | UTF-8 | 15,718 | 2.671875 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] | permissive | require_relative 'cdk_objs'
module CDK
class ALPHALIST < CDK::CDKOBJS
attr_reader :scroll_field, :entry_field, :list
def initialize(cdkscreen, xplace, yplace, height, width, title, label,
list, list_size, filler_char, highlight, box, shadow)
super()
parent_width = cdkscreen.window.getmax... | true |
16823f43a08226afec68116fba7d575f25a73026 | Ruby | AndSecYi/ruby-dtrace | /lib/dtrace.rb | UTF-8 | 2,211 | 2.734375 | 3 | [
"MIT"
] | permissive | #
# Ruby-DTrace
# (c) 2007 Chris Andrews <chris@nodnol.org>
#
require 'dtrace_api'
require 'dtrace/record'
require 'dtrace/consumer'
require 'dtraceconsumer'
require 'dtrace/aggregate'
require 'dtrace/aggregateset'
require 'dtrace/probedata'
require 'dtrace/probedesc'
require 'dtrace/stackrecord'
require 'dtrace/print... | true |
7a31953f489142919c90e9e18d186d6526e88e09 | Ruby | minaiDocus/idocussave | /tmp_cleaner.rb | UTF-8 | 1,074 | 2.625 | 3 | [] | no_license | require 'date'
class TmpCleaner
def initialize
tmp_dir = '/home/deploy/main/current/tmp/'
today = Date.today.strftime('%Y%m%d')
20.times do |i|
day = Date.today.prev_day(i).strftime('%Y%m%d')
p "=========================================[ #{day} ]=========================================="
... | true |
69bc00ff6d42fb4c699cfee62ca11a68a86f263c | Ruby | jonathanbgjo/aA_classwork | /W5D1/lib/p04_linked_list.rb | UTF-8 | 2,202 | 3.53125 | 4 | [] | no_license | class Node
attr_reader :key
attr_accessor :val, :next, :prev
def initialize(key = nil, val = nil)
@key = key
@val = val
@next = nil
@prev = nil
end
def to_s
"#{@key}: #{@val}"
end
def remove
# optional but useful, connects previous link to next link
# and removes self from... | true |
cb501294704615b6ca73a0297d231c191eaf9dfc | Ruby | ibadora/Thomas | /tf-idf.rb | UTF-8 | 4,542 | 3.46875 | 3 | [] | no_license | # encoding: utf-8
# Wp2TXTで抽出したWikipediaの全文データからTfIdfを算出.
# 自作バージョン
class TfIdf_Thomas
# 各記事の単語タイプをカウント 出力:word_type.txt
def type_counter(en_wiki)
@ewiki_hash = Hash::new()
p "Preparating for Wikipedia in English"
# 英語:奇数行(記事タイトル)をkey,偶数行(本文)をValueに設定
ewiki = open(en_wiki, 'r')
i = 0
... | true |
00dab90cb93f7b70350591a4977eb86d75d59605 | Ruby | StoneFrog/exercism | /ruby/beer-song/beer_song.rb | UTF-8 | 1,149 | 3.78125 | 4 | [] | no_license | class BeerSong
VERSION=2
def verse(number)
template_number_mapping(number).detect { |key, val| key === number}.last
end
def verses(start_verse, end_verse)
(start_verse.downto(end_verse)).map { |num| verse(num)}.join("\n")
end
def lyrics
verses(99, 0)
end
private
def template_number... | true |
3a78fb504691c0a4c11a27ef391653b725e39f1d | Ruby | muhammadzesshanshafqat/badges-and-schedules-cb-000 | /conference_badges.rb | UTF-8 | 647 | 3.96875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def badge_maker(name)
"Hello, my name is #{name}."
end
def batch_badge_creator(array)
array.collect do |name|
"Hello, my name is #{name}."
end
end
def assign_rooms(array)
new_array = Array.new
array.each_with_index do |name, index|
new_array << "Hello, #{name}! You'll be assi... | true |
b6cb9dd4ac5d68f96228684180998d7988c5cdc9 | Ruby | hoelscher-berlin/aoc2018 | /09_slow.rb | UTF-8 | 1,302 | 3.3125 | 3 | [
"MIT"
] | permissive | players = 0
last_marble = 0
File.open('inputs/09').each do |line|
players = line.split(' ')[0].to_i
last_marble = line.split(' ')[6].to_i
end
circle = [0]
current_marble = 0
round = 1
current_player = 1
score = 0
scoreboard = [0] * players
while round <= last_marble do
# positioning first marble
if circle.le... | true |
b8c094d09b35f5df24c3b105bb34078270538585 | Ruby | ekim86/ruby-oo-practice-relationships-silicon-valley-exercise-nyc-web-120919 | /tools/console.rb | UTF-8 | 1,523 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative '../config/environment.rb'
def reload
load 'config/environment.rb'
end
# Insert code here to run before hitting the binding.pry
# This is a convenient place to define variables and/or set up new object instances,
# so they will be available to test and play around with in your console
s1 = Startup.... | true |
062caaac451fc962f2d7282f48219e9fad61640a | Ruby | karthicksmail/progs | /rb/address_book.rb | UTF-8 | 1,030 | 3.390625 | 3 | [] | no_license | # Melissa's address
melissa_addr = {
"street" => "23 St George St.",
"city" => "Silver Spring",
"state" => "MD",
"zip" => "20465"
}
# Sandy's address
sandy_addr = {
"street" => "324 Campus Dr.",
"city" => "College Park",
"state" => "MD",
"zip" => "23659"
}
# Joe's address
joe_add... | true |
1137ce75e0e469d6a12fb8c95c32574c4d919ce9 | Ruby | John-Hayes-Reed/project_euler_problems | /problem_1_multiples_of_3_and_5/multiple_detector.rb | UTF-8 | 337 | 3.390625 | 3 | [] | no_license | class MultipleDetector
attr_accessor :multiples_to_detect
def initialize(multiples_to_detect:)
@multiples_to_detect = multiples_to_detect
end
def sum_of_all_multiples_under(roof)
sum = 0
(1...roof).each do |n|
sum += n if multiples_to_detect.any? { |multiple| (n % multiple).zero? }
end
... | true |
85d3a255adc495b3fe846b1de425629d811fb0b8 | Ruby | tebatalla/Blocks-Recursions | /block.rb | UTF-8 | 1,034 | 3.421875 | 3 | [] | no_license | class Array
def my_each(&prc)
i = 0
while i < length
prc.call(self[i])
i += 1
end
end
def my_map(&prc)
result = []
my_each do |item|
result << prc.call(item)
end
result
end
def my_select(&prc)
[].tap do |result|
self.my_each do |item|
result <<... | true |
2f174a7f907b776044e1fea563f2060dcab69e79 | Ruby | rasmar/programming_concepts | /logic/bitwise_addition_refactored.rb | UTF-8 | 569 | 3.875 | 4 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Sample of Bitwise Addition (Refactored) in Ruby
#
# Input:
# A (number)
# B (number)
#
# Output:
# Addition result
module Logic
class BitwiseAdditionRefactored
def self.call
puts "\nWelcome to the Bitwise Addition (Refactored)!"
puts 'Please provide input A (number):'... | true |
9f20eea8f67a818590d1949fe5ccfba51ad03a6f | Ruby | mikethorpe/ruby_codeclan_course | /cchw_wk2_day2/bear.rb | UTF-8 | 310 | 3.609375 | 4 | [] | no_license | require_relative("river")
require_relative("fish")
class Bear
def initialize(name, type)
@name = name
@type = type
@stomach = []
end
def food_count
return @stomach.count
end
def take_fish(river)
@stomach << river.lose_fish()
end
def roar()
return "Rawwr!!"
end
end
| true |
ad003ba7b24150ba1c1f84d0f9d36576677ecb90 | Ruby | breakfasting/SWE_Remote | /W2D3/tic_tac_toe_v3/computer_player.rb | UTF-8 | 200 | 3.203125 | 3 | [] | no_license | class ComputerPlayer
attr_reader :mark
def initialize(mark_val)
@mark = mark_val
end
def get_position(legal_pos)
legal_pos[rand(0...legal_pos.length)]
end
end | true |
c67e6d7c6d0620256110bdf6128977a9eb944679 | Ruby | ryandotsmith/Bacon | /test/movie_industry_test.rb | UTF-8 | 1,578 | 2.890625 | 3 | [] | no_license | require File.expand_path(File.dirname(__FILE__) + '/../bacon')
Shindo.tests do
test("connecting actors") do
storage = Graph.new
hollywood = MovieIndustry.new(storage)
hollywood.connect(Actor.new,[Actor.new,Actor.new])
end
test("connecting actors by using a movie and an array of actors") do
sto... | true |
cb58ac761f1c5d727a023c0548c7ca8be2dc91b0 | Ruby | uabassguy/ewigehoffnung | /lib/gui/textfield.rb | UTF-8 | 1,540 | 2.9375 | 3 | [
"MIT"
] | permissive |
module EH::GUI
# Displays text in the given font and alignment
class Textfield < Element
attr_accessor :max_width
def initialize(x, y, w, h, txt="", size=20, align=:left, fixed=true, maxw=w)
super(x, y, w, h)
@bg = EH.sprite("gui/container_background")
@font = EH.font(EH::DEFAUL... | true |
7219a2d33b1d5950a0f080bd4a0a731356ddb79a | Ruby | KennethLim119/VIVIXX | /customer/customer.rb | UTF-8 | 398 | 3.5 | 4 | [] | no_license | #customer_test.rb
class Customer
def initialize (first_name, last_name, age)
@first_name = first_name
@last_name = last_name
@full_name = "#{@first_name} #{@last_name}"
@age = age
end
def first_name
puts "what is your first name?"
@first_name = gets.chomp
end
def full_name
@fu... | true |
79aeb717c30bbf2f41fd5768806af1641d08610a | Ruby | xfun68/api_demo | /spec/models/query_spec.rb | UTF-8 | 1,132 | 2.671875 | 3 | [] | no_license | require 'spec_helper'
require 'query'
describe Query do
START_ADDRESS = "钟楼 西安"
END_ADDRESS = "鼓楼 西安"
before(:each) do
@attr = { "start_address" => START_ADDRESS, "end_address" => END_ADDRESS }
end
it "should create a new instance given valid attributes" do
Query.new @attr
end
it "should get ... | true |
99cc3285c9550c71d57f8a7ec1e17dbb396a4967 | Ruby | AnkDos/location-index | /twitter_stream.rb | UTF-8 | 923 | 2.703125 | 3 | [] | no_license | require "twitter"
require "curl"
class TwitterStream
@@url = "http://localhost:3000/api/bot/tweet"
@@admin_access_token = "EdAvEPVEC3LuaTg5Q3z6WbDVqZlcBQ8Z"
def initialize
@client = Twitter::Streaming::Client.new do |config|
config.consumer_key = "xnGybakbU03ZiAQLFjpEvVbxL"
config.consumer_secret... | true |
85e8d8c3a7dd50b8a3c8d0da230592291368bcd1 | Ruby | codeunion/topics-in-cs | /session-notes/2015-02-06/scratch.rb | UTF-8 | 1,852 | 4 | 4 | [] | no_license | # Write a recursive function for generating all permutations of an input
# string, returning them as an array.
# Accepts a String as input and returns a Set containing all
# the permutations of the input String
def permutations(string)
end
if __FILE__ == $PROGRAM_NAME
p permutations(["a", "b", "c"]).sort == ["aaa",... | true |
1868c8ecd178d9ae9e30e8d0efeeb3f65d36abe2 | Ruby | jkharv/ecological-composition | /ambient_track.rb | UTF-8 | 1,295 | 2.8125 | 3 | [] | no_license | require 'csv'
samples = "/Users/jake/Research Projects/ecological-composition/samples/"
ASMR1 = samples + "ASMR1.wav"
ASMR2 = samples + "ASMR2.wav"
ASMR3 = samples + "ASMR3.wav"
Frog1 = samples + "Frog1.wav"
Frog2 = samples + "Frog2.wav"
Frog3 = samples + "Frog3.wav"
Water1 = samples + "Water1.wav"
Water2 = samples... | true |
daa04d8a6fe3c89824a8ced4caca1fa43ef4c0c4 | Ruby | egamasa/study | /ruby-cherry-book/Section5/5-idiom2_self_assignment.rb | UTF-8 | 326 | 3.6875 | 4 | [] | no_license | ### ||= での自己代入 ###
# x ||= n
## 変数xがfalse値(nil/false)であればnを代入、そうでなければ変数xの値そのまま
## 「x = x || n」と同義
limit = nil
# 「limit = limit || 10」と同義
limit ||= 10
p limit #=> 10
# 「limit = limit || 20」と同義
limit ||= 20
p limit #=> 10
| true |
b775463cac5e08ea7ca8559ea657fc046be46e48 | Ruby | j-xu/proj2 | /db/seeds.rb | UTF-8 | 2,280 | 2.53125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
d156a163568a8293b5246586259692b658444283 | Ruby | miriamhit02/tv_network_2107 | /lib/network.rb | UTF-8 | 626 | 3.34375 | 3 | [] | no_license | require 'pry'
class Network
attr_reader :name, :shows
def initialize(name)
@name = name
@shows = []
end
def add_show(show)
@shows << show
end
def main_characters
all_characters = @shows.map do |show|
show.characters
end.flatten
all_characters.find_all do |character|
ch... | true |
fc51b615d010632b8484d0b9b08c148754f5ee97 | Ruby | rickwxc/moving-robots | /spec/map_spec.rb | UTF-8 | 1,829 | 2.875 | 3 | [] | no_license | require 'spec_helper'
RSpec.describe "Map" do
describe Map do
subject(:map) do
map = Map.new(5, 5)
end
it 'origin at 0,0' do
expect(map.origin).to eq [0,0]
end
it 'end at 4,4' do
expect(map.top_corner).to eq [4,4]
end
it 'is_valid point' do
expect(map.is_valid([0, 0])).to eq true
expect(m... | true |
17da5dff09aef034e95417b14c95a01dae50beaf | Ruby | kcinnoy/school-domain-online-web-sp-000 | /lib/school.rb | UTF-8 | 400 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
require 'pry'
class School
attr_reader :school_name, :roster
def initialize(school_name)
@school_name = school_name
@roster = {}
end
def add_student(student_name,grade)
self.roster[grade] ||= []
self.roster[grade] << student_name
end
def grade(grade)
@roster[grade]
end
def sor... | true |
dc693349047128b518dafc2eea8a3cd0a56254b3 | Ruby | Dante8399/Daily_Deal | /lib/CLI.rb | UTF-8 | 1,551 | 3.671875 | 4 | [
"MIT"
] | permissive |
class CLI
def call
Scraper.scrape_article_list
sleep 3
list_articles
# Runs scraper of initial site that returns list of articles (.scrape_article_list method). Assigned to .call method. Returns a list of articles with list_articles variable (see below).
loop do
puts ... | true |
734dd25fcb9622bc855313f79bace0a741129080 | Ruby | jakebills1/ruby_scripts | /string_reverse.rb | UTF-8 | 566 | 3.703125 | 4 | [] | no_license | class StringParser
def string_reverse(str)
# reverses a string by pushing and popping from a stack
arr = str.split("")
stack = []
results = []
for c in arr
stack << c
end
arr.length.times do
results << stack.pop
end
return results.join("")
end
end
describe "An in... | true |
5f9984d921ddd450fec0d33ca63753633e0daa86 | Ruby | WardustNaman/asessment | /15.rb | UTF-8 | 120 | 3.15625 | 3 | [] | no_license | a1 = []
i1 = [9,4,9,6,7,4]
flag = 0
i1.each do |ele|
if i1.count(ele) == 1
a1.push(ele)
end
end
puts a1[0]
| true |
5b0f1a02fed4f1ec908139780da1ff8df035c610 | Ruby | spradhan10/Ruby | /person_project/person.rb | UTF-8 | 881 | 3.578125 | 4 | [] | no_license | require 'date'
class Person
attr_accessor :first_name, :surname, :emails
attr_reader :phone_numbers, :dob
def initialize(fname, sname, dob = 'nill')
@first_name = fname.capitalize
@surname = sname.capitalize
@dob = Date.parse(dob)
@emails = []
@phone_numbers = []
end
def fullname
"#... | true |
4ee548e43cbe0f9239854e44c108f1249b386fec | Ruby | mafolz/reaper--rest-in-peace | /app/models/genre.rb | UTF-8 | 492 | 2.546875 | 3 | [] | no_license | class Genre < ActiveRecord::Base
#belongs_to :path#, :foreign_key => "path_id"
has_many :artists,:dependent=>:destroy, :order=>"name"
validates_presence_of :name
def validate
#self.Name=self.Name.strip
# Schauen ob das genre schon erstellt wurde
if Genre.exists?(:name=> self.name)
error... | true |
bb30de02e765a2150ce0384b79bbd4e5f7c02c36 | Ruby | rmathur101/DataStructuresRuby | /lib/merge_sort.rb | UTF-8 | 749 | 3.8125 | 4 | [] | no_license | def merge_sort(array)
return if array.length < 2
mid = array.length / 2
left = []
right = []
(0..(mid-1)).each do |i|
left << array[i]
end
(mid..(array.length - 1)).each do |i|
right << array[i]
end
merge_sort(left)
merge_sort(right)
merge(left, right, array)
end
def merge(left, right, array)
i = 0
j ... | true |
9909b9598d7c35f127835dd3b22319b4c889792d | Ruby | playtaplabs/itr_homework | /msclvr/app/models/network.rb | UTF-8 | 591 | 2.546875 | 3 | [] | no_license | class Network < ActiveRecord::Base
attr_accessible :network_name, :owner_first_name, :owner_last_name, :owner_password
# networks can have many users
has_many :users
# owner password and network name are required
# password length must be between 8 and 14 characters long and must include at least one numb... | true |
f7a625ffb3425a8275d5c4dde4bb0c059d7a67d7 | Ruby | rubystudent/GeekHub | /lesson1/array/2.rb | UTF-8 | 110 | 2.890625 | 3 | [] | no_license | array = Array.new(4)
array.each do |value|
value = []
4.times { value.push(rand(-10..10)) }
p value
end
| true |
f91ae592a24a44801e63c28b1c046799e89094a3 | Ruby | dpkerins/OysterCard-Doug- | /lib/journey.rb | UTF-8 | 486 | 3.3125 | 3 | [] | no_license | class Journey
attr_reader :entry_station, :exit_station
MIN_FARE = 1
def initialize
@entry_station = nil
@exit_station = nil
end
def fare
return 0 if @entry_station.nil? && @exit_station.nil?
return 6 if @entry_station.nil? || @exit_station.nil?
MIN_FARE + (@entry_station.zone - @exit_s... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.