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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
532412db0e988f6761aedec7daf57551c4670737 | Ruby | edhuang24/RailsLite | /bin/router_server.rb | UTF-8 | 2,127 | 2.640625 | 3 | [] | no_license | require 'webrick'
require_relative '../lib/controller_base'
# http://www.ruby-doc.org/stdlib-2.0/libdoc/webrick/rdoc/WEBrick.html
# http://www.ruby-doc.org/stdlib-2.0/libdoc/webrick/rdoc/WEBrick/HTTPRequest.html
# http://www.ruby-doc.org/stdlib-2.0/libdoc/webrick/rdoc/WEBrick/HTTPResponse.html
# http://www.ruby-doc.or... | true |
844ea9f8211d466e9c6462561a86a0710dbb2834 | Ruby | bitops/linen | /report.rb | UTF-8 | 496 | 2.734375 | 3 | [] | no_license | require 'benchmark'
require File.expand_path(File.join(File.dirname(__FILE__), 'foo'))
include Benchmark
Benchmark.benchmark(CAPTION, 15, FORMAT) do |b|
b.report("not threaded") do
f = Foo.new
f.long
f.longer
f.longest
end
b.report("threaded") do
threads = []
f = Foo.new
threads <<... | true |
77320fd3d68860ffb7c4712a131c5f1f65348bbe | Ruby | rkgordon3/electoral | /app/models/game.rb | UTF-8 | 1,569 | 2.703125 | 3 | [] | no_license | # == Schema Information
#
# Table name: games
#
# id :integer not null, primary key
# election_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# config_file :string(255)
# start_date :date
# candidate_id :integer
# current_turn :integer ... | true |
1c775db39b7dc861fbbca5b5786820a64149936c | Ruby | verybland/collections_practice-v-000 | /collections_practice.rb | UTF-8 | 687 | 3.875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def sort_array_asc(array)
array.sort
end
def sort_array_desc(array)
array.sort.reverse
end
def sort_array_char_count(array)
array.sort {|x, y| x.length <=> y.length}
end
def swap_elements(array)
temp = array[1]
array[1] = array[2]
array[2] = temp
array
end
def reverse_array(array)
array.reverse
end... | true |
9b379fc56f7d56d6f2f6e45d9e9c6e6dd5797e44 | Ruby | meghaniankov/oystercard | /spec/station_spec.rb | UTF-8 | 301 | 2.84375 | 3 | [] | no_license | require 'station'
describe Station do
it 'stores name in name variable' do
station = Station.new("station1", 1)
expect(station.station_name).to eq "station1"
end
it 'stores zone in zone variable' do
station = Station.new("station1", 1)
expect(station.zone).to eq 1
end
end | true |
ce1dd398ce709161526ddf1f5203e6ae5a2320ba | Ruby | jyschwrtz/AppAcademyProjects | /w3d3/URLShortener/bin/cli | UTF-8 | 762 | 2.796875 | 3 | [] | no_license | #!/usr/bin/env ruby
#io9JtEaqVsYxPtNAdRFygQ
require "launchy"
puts "Please provide your email"
email = gets.chomp
user = User.find_by(email: email)
puts "Would you like to visit a URL (1) or create one (2)?"
input = gets.chomp.to_i
def process_input(input,user)
if input == 1
puts "Please provide shortened UR... | true |
e9518f04d2d810bf28554c17f55fe4238d043896 | Ruby | colinjh/rails-react-crud | /db/seeds.rb | UTF-8 | 329 | 2.953125 | 3 | [] | no_license | class Seed
attr_reader :seed
def initialize
@seed
end
def run
generate_data
end
def generate_data
10.times do
item = Item.new
item.name = "Item"
item.description = "I am a description."
item.save!
item "Generated item # #{item.id}"
end
end
end
seed = Seed.new
... | true |
b99bae9903134c4b8cfd6a547e5210ff8d704ae3 | Ruby | thebestofal/ruby-repo | /spec/grade_school_test.rb | UTF-8 | 2,215 | 3.21875 | 3 | [] | no_license | require_relative("../lib/grade_school")
RSpec.describe School do
it("empty grade") do
school = School.new
expected = []
expect(school.students(1)).to(eq(expected))
end
it("add student") do
school = School.new
expect(school.add("Aimee", 2)).to(be_truthy)
expected = ["Aimee"]
expect(scho... | true |
ea2c412482d8929cadd7e4ce88709b8c8f8fe067 | Ruby | ERRECabrera/algorithms_to_sort_people | /Object Oriented/order_algorithm.rb | UTF-8 | 2,187 | 3.453125 | 3 | [] | no_license | require_relative 'algorithm_to_sort.rb'
class Order_algorithm < Algorithm_to_sort
def initialize(people_list)
super(people_list,'order')
end
def sort_people
alternative_a = generate_possible_list('height')
alternative_b = generate_possible_list('weight')
return alternative_a.size > alternative... | true |
c9fd5656303d0e31d97d8ec0eeffe65ead7e45cb | Ruby | startkladde/sk_web | /app/models/plane_log.rb | UTF-8 | 1,099 | 2.9375 | 3 | [] | no_license | # encoding: utf-8
class PlaneLog
# Create a log for flights of a single plane, merging if possible
# Returns an array of entries
def PlaneLog.create_for_plane(flights)
# Without merging:
#flights.map { |flight| PlaneLogEntry.create(flight) }
result=[]
entry_flights=[]
# Iterate over the flights. Flights... | true |
8b862929e545facc65307ee10b842f69b39deaf6 | Ruby | mehagel/old-programs | /fib2.rb | UTF-8 | 195 | 3.6875 | 4 | [] | no_license | def fib(i)
num= [0, 1,1,2,3]
(i).times do
num.push(num[-1] + num[-2])
end
if num.include? (i)
puts 'True'
return true
else
puts 'False'
return false
end
end
fib(144) | true |
729649930a6acc1ef56b11012d48a73c519bdfa2 | Ruby | mileshobby/aa-daily-pairing | /W2D1/chess/slidingpiece.rb | UTF-8 | 971 | 3.125 | 3 | [] | no_license | module SlidingPiece
def moves
possible_moves = []
move_dirs.each do |move_dir|
dx, dy = move_dir
possible_moves += grow_unblocked_moves_in_dir(dx, dy)
end
possible_moves
end
private
def move_dirs
if self.class == Rook
vertical_dirs + horizontal_dirs
elsif self.class ... | true |
1407be164a789b3a3395a3be3df69fbc4add121f | Ruby | dclorena11/developer-exercise | /ruby/where/searchable.rb | UTF-8 | 274 | 2.78125 | 3 | [] | no_license | module Searchable
def where(search)
self.select do |el|
search.all? do |key,value|
if value.kind_of?(Regexp)
value =~ el[key]
else
value == el[key]
end
end
end
end
end
class Array
include Searchable
end
| true |
e0e548c555238204b7da4c1dd6e2833ca4501b1f | Ruby | Dan2552/rebase-face | /face.ruby | UTF-8 | 246 | 2.609375 | 3 | [] | no_license | #!/usr/bin/env ruby
filename = ARGV.first
File.open("/tmp/rebaseface.lock", 'w') { |f| f.write(filename) }
puts "locked /tmp/rebaseface.lock"
until !File.exist?("/tmp/rebaseface.lock")
#puts "locked /tmp/rebaseface.lock"
end
puts "unlocked"
| true |
b23121d0990f8dabcf746a92c28e6068541b51b2 | Ruby | rabGIT/assignment_oop_warmups_1 | /TowerOfHanoi/game_board.rb | UTF-8 | 1,884 | 3.953125 | 4 | [] | no_license |
class GameBoard
def initialize(disks)
@num_disks = disks
@moves = 0
@new_move = { start: 0, finish: 0 }
@stacks = [[], [], []]
disks.downto(1) { |disk| @stacks[0].push(disk) }
end
def render
puts "\nAfter #{@moves} moves: "
@num_disks.downto(0) do |num|
@stacks.length.times do... | true |
ddb7a25fbff1179b63c4aa0d7b80369b1b5d22e1 | Ruby | MarkCurtiss/NethackBot | /lib/game.rb | UTF-8 | 886 | 3.03125 | 3 | [] | no_license | class Game
attr_accessor :url
def initialize(url)
@url = url
end
def ==(other_game)
@url.eql?(other_game.url)
end
def eql?(other_game)
self == other_game && self.class == other_game.class
end
def hash
@url.hash
end
def death_metadata
death_text = self.contents
death_meta... | true |
2711547b99eceecb9ab92445c526bbde3bc93db3 | Ruby | ryo27-jp/ruby_practice | /chapter11.rb | UTF-8 | 2,127 | 3.859375 | 4 | [] | no_license | # puts "金額を入力してください"
# bill = gets.to_i
# puts "割り勘する人数を選んでください"
# number = gets.to_i
# begin
# warikan = bill / number
# puts "一人あたり#{warikan}円です"
# rescue ZeroDivisionError
# puts "割り勘できません"
# end
# def warikan(bill, number)
# warikan = bill / number
# puts "一人あたり#{warikan}円です"
# rescue ZeroDivisionError
... | true |
0bf9255824034cef1078e020e7230c387059d270 | Ruby | Adzz/battle | /spec/features/attack_spec.rb | UTF-8 | 484 | 2.734375 | 3 | [] | no_license | # As Player 1,
# So I can win a game of Battle,
# I want to attack Player 2, and I want to get a confirmation
feature 'Attack player 2 and confirm attack' do
scenario "Attacks player 2, and confirm" do
sign_in_and_play
click_link("Attack!")
expect(page).to have_content "Michael was attacked!"
end
sc... | true |
84764ee216548ca9c69a9059b01f53b9dc02a728 | Ruby | Laner12/ruby-exercises | /command-query/santa.rb | UTF-8 | 199 | 2.703125 | 3 | [
"MIT"
] | permissive | class Santa
def initialize
@fits = true
@count = 0
end
def fits?
if @count > 2
@fits = false
else
@fits
end
end
def eats_cookies
@count += 1
end
end
| true |
1ef117ac2332d02aea426c99cdc11746a8a8ae54 | Ruby | samstephen/07-17-photobomb | /models/tasks.rb | UTF-8 | 1,431 | 2.765625 | 3 | [] | no_license | require 'bcrypt'
# require_relative "../database_class_methods.rb"
# require_relative "../database_instance_methods.rb"
class User < ActiveRecord::Base
include BCrypt
# extend DatabaseClassMethods
# include DatabaseInstanceMethods
#
# attr_accessor :id, :email
# attr_reader :password
#
# def initi... | true |
0b8620f64f940a0998ce638652f237922771155c | Ruby | msmirnoff/db_helper | /lib/db_helper/command.rb | UTF-8 | 179 | 2.75 | 3 | [
"MIT"
] | permissive | module Command
def command(command_text)
puts "#{command_text}"
res = `#{command_text}`
raise "Command Failed: #{command_text}" unless $?.success?
res
end
end
| true |
7d85ca7f627c4db3c40c9651c0e686a9cbe2a05b | Ruby | buddylove954/practice-problems | /bubble.rb | UTF-8 | 347 | 3.96875 | 4 | [] | no_license |
def bubble_sort(array)
n = array.length
loop do
swapped = false
(n-1).times do |i|
if array[i].downcase > array[i+1].downcase
array[i], array[i+1] = array[i+1], array[i]
swapped = true
end
end
break if not swapped
end
array
end
name = ["he", "we", "apple", "sa... | true |
3152f6be29ffb4ac6dddcc45dfcce75bdffe7284 | Ruby | Iliyan-Y/CharlieHR-tech-test | /spec/user_spec.rb | UTF-8 | 1,559 | 3.28125 | 3 | [] | no_license | require 'user'
describe User do
it "creates user with name and date of bird" do
date_of_birth = Date.new(1991,1,1)
user = User.new("George", date_of_birth)
expect(user.name).to eq "George"
expect(user.date_of_birth).to eq date_of_birth
end
describe "#age" do
it "returns the current a... | true |
362386c8b1ab043925549d1f06c3cc78db394114 | Ruby | AdaGold/inspiration-board-api | /test/controllers/boards_controller_test.rb | UTF-8 | 2,906 | 2.546875 | 3 | [] | no_license | require "test_helper"
describe BoardsController do
it 'has a root route' do
get root_path
must_respond_with :success
end
describe "index" do
before do
# Act
get boards_path
end
it "should get index" do
# Assert
expect(response).must_be :successful?
expect(respo... | true |
34c805083efb034a1792210b672b84497e3a780a | Ruby | AlexCline/vadar | /lib/models/ad.rb | UTF-8 | 2,535 | 2.8125 | 3 | [] | no_license | require 'net/ldap'
require 'configuration'
require 'logging'
class Ad
include Logging
attr_writer :configuration, :ldap
def configuration
@configuration ||= Configuration.new
end
def initialize
@ldap = Net::LDAP.new
@ldap.host = configuration.config['ad']['host']
@ldap.port = configuratio... | true |
e8b2730e8400c6454d3c7bba25d9d6cb2300f9d5 | Ruby | tperes92/exos_ruby | /exo_13.rb | UTF-8 | 277 | 3.546875 | 4 | [] | no_license | # demande son année de naissance à l'utilisateur, puis qui va
# ressortir chaque année depuis son année de naissance jusqu'aujourd'hui.
puts "quel est ton année de naissance ?"
birth_year = gets.chomp.to_i
birth_year.upto(2020) do |total_year| puts "#{total_year}"
end | true |
71b1c958e00124e2f8c5af26ab3e7cc9deb25677 | Ruby | kevlabs/math_game | /round.rb | UTF-8 | 616 | 3.5625 | 4 | [] | no_license | require './helpers'
class Round
attr_reader :num1, :num2, :answer, :success
def initialize(player)
@player = player
@success = false
run
end
def run
ask
validate
if !@success then @player.remove_life end
end
def ask
@num1 = Round.generate_num
@num2 = Round.generate_num... | true |
7c99f534c9263dc728e14647a77db38aa0f67451 | Ruby | misucchi/raspirec | /src/model/Tuner.rb | UTF-8 | 9,715 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/local/bin/ruby
# -*- coding: utf-8 -*-
#
# チューナーの割当
#
class Tuner
def assign( flag, t, tuner )
if flag == :set
1.upto(99) do |n|
if tuner[ t[:band2]][n] == nil
tuner[ t[:band2]][n] = true
return n
end
end
else
tuner[ t[:band2] ][ t[:tunerNum] ] ... | true |
bf56caa158fd4eba9d57eb55c80cad2b2d89aa2d | Ruby | jepetko/postit-application | /app/controllers/sessions_controller.rb | UTF-8 | 1,515 | 2.53125 | 3 | [] | no_license | class SessionsController < ApplicationController
def new
end
def create
# 1. get the user obj
# 2. see if password matches
# 3. if so, log in
# 4. if not, error message
user = User.find_by username: params[:username]
if user && user.authenticate(params[:password])
# to grant or den... | true |
db460aafaaf15a9e3d359edc4701f8eed2c95709 | Ruby | divout/previews | /test/tc_array.rb | UTF-8 | 2,710 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'tc_helper'
class TestArray < Test::Unit::TestCase
def setup
@reviews = [{"origin"=>"ubuntu",
"rating"=>5,
"hide"=>false,
"app_name"=>"VLC media player",
"language"=>"en",
"reviewer_username"=>"p8KFRbG",
"usefulness_total"=>3,
"usefulness_favorable"=>2,
"re... | true |
8aece0c2faf9af0d03fa0076c2ed4d89ef2e13d6 | Ruby | seodo/cyrus-challenge | /test_rspec.rb | UTF-8 | 3,288 | 3.15625 | 3 | [] | no_license | require_relative "reader.rb"
describe FileParser do
context "manipulate file contents" do
before(:each) do
@file_parser = FileParser.new
@file1 = "nope.txt"
@file2 = "comma.txt"
@line = "Abercrombie, Neil, Male, Tan, 2/13/1943\n"
end
it 'does not read non-matching fil... | true |
eebcf17d9469111f1dcd60fb3a28ec0e8ec96b6d | Ruby | savvasavushkin/labss3 | /LR9/app/models/factorial_algo.rb | UTF-8 | 471 | 3.03125 | 3 | [] | no_license | class FactorialAlgo < ActiveRecord::Base
def self.check_simon_theory(max_n = 20)
result = []
id = 0
# n! = m * (m + 1) * (m + 2) (m in [1; n^(1/3)])
(0..max_n).each do |n|
fact = get_factorial(n)
(2..(fact ** (1.0/3)).round).each do |k|
if (k - 1) * k * (k + 1) == fact
r... | true |
b7d4509d46495abb9444246592d021ffaeeaa202 | Ruby | oeloeloel/tweetcarts | /colour-swirl/readable.rb | UTF-8 | 1,617 | 3 | 3 | [
"MIT"
] | permissive | def tick args
# do the things that only need to happen once
if args.tick_count.zero?
# make a rectangle using a render target
# this allows us to make rectangular sprites
# that can rotate, without using any external
# resources
# The rectangle is painted white so we can
# re-colour it ... | true |
1ce7ddd7ed0023cb5c1cda7bae861c21ddbb9287 | Ruby | usctcr/intro-to-programming | /Methods/multiply.rb | UTF-8 | 53 | 3.25 | 3 | [] | no_license | def multiply(a,b)
puts (a * b)
end
multiply(10,12) | true |
2b5d916ad615bc89e33349306cb41ed853c1455c | Ruby | jibarra/advent-of-code | /2019/day1/solution.rb | UTF-8 | 439 | 3.328125 | 3 | [
"MIT"
] | permissive | lines = File.readlines('./input.txt')
# Part 1
total_fuel = 0
lines.each do |mass|
fuel = (mass.to_i / 3).floor - 2
total_fuel += fuel
end
puts total_fuel
# Part 2
total_fuel = 0
lines.each do |mass|
fuel = (mass.to_i / 3).floor - 2
component_fuel = fuel
while ((component_fuel / 3).floor - 2) > 0
comp... | true |
e8d4a26b26a386137e21dbd8879371ebb12cefcf | Ruby | Fabian-tapia7/ruby_rails | /objetos/presencial/desafios_lunes/7.rb | UTF-8 | 613 | 3.3125 | 3 | [] | no_license | class Product
attr_accessor :name, :sizes
def initialize(name, *sizes)
@name = name
@sizes = sizes.map(&:to_i)
end
def catalog
#que muestre la informacion que queremos mostrar en un string:
return "#{self.name}, #{self.sizes[0..self.sizes.size-2].join(', ') }"
end
end
products_list = []
data =... | true |
49fa5a3025a067a340e3220a3daa910130249d89 | Ruby | OberbonzePipapo/ruby_basic | /aufgabe03/tests/test_mass_conversion.rb | UTF-8 | 611 | 3.09375 | 3 | [] | no_license | # Description
# Author:: Elina Eickstaedt
require 'test/unit'
require_relative '../mass_conversion'
class TestMassConversion < Test::Unit::TestCase
def test_conversion
# test if conversion into suitable units works
assert_equal(0.05, MassConversion.new("g", 50).convert("kg"))
assert_equal(13779, MassCon... | true |
3c9d081bd124f6542d14e7aa8154cf63f85fde37 | Ruby | stevenb-nz/AdventOfCode2018 | /day04a.rb | UTF-8 | 787 | 3.0625 | 3 | [] | no_license | def day04(input)
input = input.split(/\n/).sort
minutes = Hash.new
input.each_with_index do |line,i|
if line[19,5] == "Guard" then
guardnum = line[26..-13].to_i
if !minutes.has_key?(guardnum) then
minutes[guardnum] = Array.new(60,0)
end
j = i+1
if j < input.count then
... | true |
af88f11ceccbebd1a8f1a2732fdf305402ab783f | Ruby | seikin123/Ruby_practice | /omikuji.rb | UTF-8 | 358 | 3.734375 | 4 | [] | no_license | # おみくじプログラムを作る
#比較演算子 ==> < >== >= <= !=
# 大吉 中吉 小吉 凶 大凶
omikuji = rand(1..10)
#puts omikuji
if omikuji == 1
puts "大吉"
elsif omikuji == 2
puts "中吉"
elsif omikuji <= 4 #3,4
puts "小吉"
elsif omikuji <= 7 # 5,6,7
puts "凶"
else
puts "大凶" #8,9,10
end
| true |
81b8adf3184a7c8b2ff506b7c7ef7ef182ff42df | Ruby | davidpera/prueba | /saluda.rb | UTF-8 | 127 | 2.953125 | 3 | [] | no_license | print "Como te llamas campeon?"
nombre=gets.chomp
puts "hola #{nombre} estoy deseabdo que te vallas"
puts "igualmente, colega"
| true |
eb129499a940530fc54d4fae23568a02489e75b4 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/b75d10a68df5453ebcc616f359c17dab.rb | UTF-8 | 550 | 3.453125 | 3 | [] | no_license | class Raindrops
def self.convert(number)
array = []
current_number = number
return_string = ''
while current_number >= 1
if number%(current_number) == 0
array.push current_number
end
current_number -= 1
end
if array.include?(3)
return_string += "Pling"
end
... | true |
e577cbeed5ebf1108e4ab4bd896f3dfd2c4ab410 | Ruby | riazmohamed/101_109_small_problems | /easy_6/remove_vowels.rb | UTF-8 | 616 | 3.984375 | 4 | [] | no_license | # remove_vowels.rb
def remove_vowels(arr)
arr.map! do |word|
word.chars.select { |letter| %w(a e i o u).include?(letter.downcase) == false }
end
arr.map {|word| word.join}
end
p remove_vowels(%w(abcdefghijklmnopqrstuvwxyz))
p remove_vowels(%w(green YELLOW black white))
p remove_vowels(%w(ABC AEIOU XYZ))
p... | true |
22c3685ed1d01dcecb439b7f538385b87a1f2e3e | Ruby | itggot-eric-jigrup/standard-biblioteket | /lib/isempty.rb | UTF-8 | 231 | 3.515625 | 4 | [] | no_license | # string - The string to define.
#
# Examples
#
# isempty("grillkorv")
# # => false
#
# Returns boolean value.
def isempty(string)
if string.length < 1
i = true
else
i = false
end
return i
end | true |
4e090a8e62372aa2c70cc7c5b179a558fe4dbbb8 | Ruby | smoriwaki/better_enum | /spec/models/employee_spec.rb | UTF-8 | 1,700 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
RSpec.describe Employee, type: :model do
describe 'about singleton methods' do
describe '.genders' do
it { expect(Employee.genders).to eq('male' => 0, 'female' => 1, 'other' => 2) }
end
describe '.gender_text' do
it('with male') { expect(Employee.gender_label(:male)).to... | true |
25a23e23e8f0f62d4d332c004cc190429dae4400 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/ed339562ef5b450590892b7ae49616aa.rb | UTF-8 | 366 | 3.640625 | 4 | [] | no_license | class Hamming
def self.compute(strand_a, strand_b)
self.new(strand_a).distance_to(strand_b)
end
attr_reader :strand
def initialize(strand)
@strand = strand
end
def distance_to(strand)
pairs = bases.zip(strand.chars)
pairs.take(strand.length).count do |a, b|
a != b
end
end
pr... | true |
f0173231ab762a17f2e7f797f5c3f295f68f0f8d | Ruby | joochanshin/JavaScript-practice | /CC/main.rb | UTF-8 | 131 | 3.28125 | 3 | [] | no_license | array = [1,2,3,-5,-6,-7,4]
def filt(arr)
result = arr.select do |elem|
elem >= 0 && elem % 2 == 1
end
end
print filt(array) | true |
7be46f4dec37727ef43ea50897f3be12539f5d83 | Ruby | krisleech/detachment | /lib/detachment/store.rb | UTF-8 | 534 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'singleton'
module Detachment
class Store
include Singleton
def initialize
@data = {}
end
def add(event, klass, method_map = {})
@data[event] ||= Set.new
@data[event] << Subscription.new(klass, method_map)
end
def find(event)
@data[event]
end
def de... | true |
19d82bdf75fd93dbc9c1b55458adc702bbaa7adb | Ruby | denio-rus/thinknetica-ruby | /lesson4/route.rb | UTF-8 | 1,058 | 3.15625 | 3 | [] | no_license | class Route
include InstanceCounter
attr_reader :stations, :id
ROUTE_ID_FORMAT = /^[0-9A-Z]/i
@@routes = {}
def initialize(id, departure_point, destination_point)
@id = id
validation!
@stations = [departure_point, destination_point]
register_instance
@@routes[id] = self
end
def se... | true |
84de898a98af4f7561382360711c0b5e7bb9b7be | Ruby | Jmenke514/ruby_challenge | /car_rspec.rb | UTF-8 | 5,017 | 3.328125 | 3 | [] | no_license | require 'rspec'
require_relative 'car'
describe Vehicle do
it "can be created" do
expect{Vehicle.new(2016)}.to_not raise_error
end
it "always has a model year" do
my_vehicle = Vehicle.new(2016)
expect(my_vehicle.year).to be_a Numeric
end
it "has lights that start in the off position" do
m... | true |
7c31972fc7d916ea2cfefe6538d443a1060ea368 | Ruby | jonathanhefner/cs101__ruby | /lib/hashtable.rb | UTF-8 | 684 | 2.984375 | 3 | [] | no_license | class Hashtable
class KeyVal < Struct.new(:key, :val); end
def initialize(bucket_count = 16)
@bucket_count = bucket_count
@buckets = bucket_count.times.inject([]){|bs, i| bs << [] }
end
def set(key, val)
bucket = @buckets[key.hash % @bucket_count]
kv = bucket.find{|e| e.key == key }
if kv... | true |
ed80dfe34eea2c75eefb79b275035a56b985abd9 | Ruby | shushushu1x/DraftGame | /rspec_test/lib/AWS/myapp.rb | UTF-8 | 4,714 | 2.640625 | 3 | [] | no_license | require 'sinatra'
require 'rubygems'
require 'bundler'
require 'mysql2'
require 'sinatra/reloader'
# Encoding.default_external = 'utf-8'
client = Mysql2::Client.new(host: "localhost", username: "root", password: '', database: 'bcup')
class Player
attr_accessor :name
attr_accessor :position
attr_accessor :birthd... | true |
76fbcea0ffd41f5c8249fa8642af6b8dacf4b423 | Ruby | daniel-walters/chess-viewer | /src/spec/file_reader_spec.rb | UTF-8 | 612 | 2.84375 | 3 | [] | no_license | require_relative "../file_reader"
describe "File_Reader" do
before(:each) do
@reader = FileReader.new("spec/test-input/FischerVsThomason.pgn")
end
it "should grab data from the file and turn into a Hash on initialization" do
expect(@reader.data).to be_a Hash
end
describe ".get_... | true |
db5ceef7dd0efb3666481434408902ea1f448c13 | Ruby | hiracky16/design_pattern_ruby | /prototype/main.rb | UTF-8 | 486 | 2.59375 | 3 | [] | no_license | require_relative './framework/manager'
require './message_box'
require './under_line_pen'
manager = Manager.new
upen = UnderLinePen.new('~')
mbox = MessageBox.new('*')
sbox = MessageBox.new('/')
manager.register('strong message', upen)
manager.register('warning box', mbox)
manager.register('slash box', sbox)
p1 = m... | true |
99e8aae6e351413d03e8c5227f7bc05e9f47ce75 | Ruby | fujicho/AtCoder-pra | /beginner/ABC049C-白昼夢.rb | UTF-8 | 1,079 | 3.390625 | 3 | [] | no_license | s = gets.strip
words = "dream", "dreamer", "erase", "eraser"
words.sort!.reverse!
# dream + erase(r)だと前方からサーチするとプレフィックスになってしまう。
# だがeraserからサーチした場合はdreamにかからない。ので、wordsの配列操作でこれを回避することができる。
# つまり
# words = "eraser", "erase", "dreamer", "dream"
# としてもACが出てしまうw
words.each do |word|
s.gsub!(word, "")
end
if s == ""
p... | true |
ac321831b49353b780107de206dac0ed3905d515 | Ruby | learningearnings/Mayhem | /test/unit/importers/le/classrooms_importer_test.rb | UTF-8 | 2,594 | 2.578125 | 3 | [] | no_license | require_relative '../../../test_helper'
require_relative '../../../../app/models/importers/le/classrooms_importer'
class School; end
class Classroom; end
class Person; end
describe Importers::Le::ClassroomsImporter do
let(:file_path){ File.expand_path("../../../../support/files/le/classrooms.csv", __FILE__) }
let... | true |
9e591fe5406671c01f268aebdca22a986fec9f2b | Ruby | learn-co-students/seattle-web-060120 | /15-hogwarts/models/cli.rb | UTF-8 | 495 | 3.359375 | 3 | [] | no_license | class CLI
attr_accessor :student
# @student = ""
def main_menu
puts "Welcome to Hogwarts. Please give us your name: "
username = gets.chomp
@student = Student.find_by(name: username)
if @student
puts "Thank you #{student.name}!! Let's get you sorted. "
else
@student = Student.cre... | true |
1169e0490fe73d514528d6d96d5894177da43e33 | Ruby | wolfmasa/train-ticket-rails | /app/models/ticket.rb | UTF-8 | 597 | 2.65625 | 3 | [
"MIT"
] | permissive | class Ticket < ApplicationRecord
belongs_to :entered_gate, class_name: 'Gate', foreign_key: 'entered_gate_id'
belongs_to :exited_gate, class_name: 'Gate', foreign_key: 'exited_gate_id', required: false
validates :fare, presence: true, inclusion: Gate::FARES
validates :entered_gate_id, presence: true
validate... | true |
ce738d9bf6563fc06287b6c33e894f7cde28cb94 | Ruby | callea2/slow_food | /features/step_definitions/dish_display_steps.rb | UTF-8 | 398 | 2.53125 | 3 | [
"MIT"
] | permissive | Given(/^that the following dishes exist in the system$/) do |table|
table.hashes.each do |dish|
Dish.create(name: dish[:name], price: dish[:price])
end
end
Given(/^I am on the home page$/) do
visit '/'
end
Then(/^I will see "([^"]*)"$/) do |text|
expect(page).to have_text text
end
Given(/^there are no di... | true |
ae2df6007bf3a952b1b7a0e1a8eb8aeff81f6951 | Ruby | dayana-alonso/roadmap_ruby | /ruby_exercises/integer.rb | UTF-8 | 494 | 4.15625 | 4 | [] | no_license | # number = 1
# puts number
# a = 1
# puts a
# large_number = 1
# puts large_number
# apples = 1
# puts apples
# ===============
# number = 4
# number = number * 3
# puts number + 2
# Same as
# puts 4 * 3 + 2
# ================
# # Things on the right goes first
# Ruby will first look at the expression 2 + 3 * 4,... | true |
530bb913cdc31bced15aaa12ef10b8548c0287ac | Ruby | xor-freenet/Freenet-stats | /version_distribution/generate_gnuplot.rb | UTF-8 | 947 | 3 | 3 | [] | no_license | require 'set'
#open the file
data = File.open("version_history.txt", "r")
#select the data from the past week
past_time = Time.now - (60*60*24*3)
#generate gnuplot for that data (you'd have to make a legenda of the different versions)
peers = Hash.new
versions = Set.new
data.each_line do |line|
split = line.chomp.s... | true |
831116f8d5302f0d4568dd59036d65120bc85a68 | Ruby | Lukabaramishvili/my-select-dumbo-web-career-040119 | /lib/my_select.rb | UTF-8 | 71 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_select(collection)
collection.select { |num| num.even? }
end
| true |
fa1391835378d4a3946515f40c616f41cb71a4c3 | Ruby | dmeeuwis/advent-of-code | /2019-ruby/day4/day4_p2.rb | UTF-8 | 193 | 2.640625 | 3 | [] | no_license | ans = 0
for s in range(235741, 706948 + 1):
x = str(s)
if any(d*2 in x and d*3 not in x for d in '0123456789') and all(l<=r for l,r in zip(x[::], x[1::])):
ans += 1
print(ans)
| true |
8b81dcf37cec2a081238e203b3eb8c88ff7e2062 | Ruby | Yuni-Q/blog | /TIL/Ruby/Ruby_opentutorials/Container_Loop/containerAndRepeat.rb | UTF-8 | 119 | 2.671875 | 3 | [
"MIT"
] | permissive | members = ['egoing', 'leezche', 'graphittie']
i = 0
while i < members.length do
puts(members[i])
i = i + 1
end
| true |
c09a5ad9fb79fd7f5f342a687c1b135fe4639807 | Ruby | enowmbi/algorithms | /fibonacci_recursion.rb | UTF-8 | 100 | 3.265625 | 3 | [] | no_license | def fibonacci(n)
return 0 if n <= 1
return 1 if n == 2
fibonacci(n-2) + fibonacci(n-1)
end
| true |
c45428d7326b367b1b35bdb71305231e97ae047a | Ruby | IainDK/RPS | /app/models/computer.rb | UTF-8 | 198 | 3.03125 | 3 | [] | no_license | class Computer
attr_reader :name, :weapon
def initialize(name = "The Computer")
@name = name
@weapon = computer_weapon
end
def computer_weapon
Game::CHOICES.sample
end
end
| true |
541f8d1061d03a1e4e89bc707a71a62ce2845463 | Ruby | gangeli/corenlp-server-recipes | /corenlp.rb | UTF-8 | 491 | 2.78125 | 3 | [] | no_license | require 'net/http'
require 'json'
uri = URI('https://corenlp.ai/')
Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https') do |http|
# Create the request
request = Net::HTTP::Post.new(uri.request_uri)
request.body = 'the fox jumped over the lazy dog'
request.basic_auth 'api_key', 'api_s... | true |
b691e456c3288355612df0bdfc331d743c21cab2 | Ruby | apoc64/company-audit | /lib/company.rb | UTF-8 | 1,409 | 3.34375 | 3 | [] | no_license | require 'csv'
class Company
attr_reader :employees,
:projects,
:timesheets
def initialize
@employees = []
@projects = []
@timesheets = []
end
def load_employees(filename)
records = CSV.read(filename)
return failure if !check_validity(records, 5)
records.eac... | true |
998f6d58239a1b79bbc0be505278a3556cd142c2 | Ruby | Bennimaru/activerecord-validations-lab-dumbo-web-121018 | /app/models/post.rb | UTF-8 | 470 | 2.765625 | 3 | [] | no_license | class Post < ActiveRecord::Base
validates :title, presence: true
validates :content, length: {minimum: 250}
validates :summary, length: {maximum:250}
validates :category, inclusion: {in:["Fiction","Non-Fiction"]}
validate :is_clickbait?
CLICKBAITY_TITLE = [/Won't Believe/i, /Secret/i, /Top
[0-9]*/i, /Gue... | true |
da7be2f2637cafe805700c037de1a74d7345075f | Ruby | arp1t/hackerrank | /gemstones.rb | UTF-8 | 175 | 2.953125 | 3 | [] | no_license | # Enter your code here. Read input from STDIN. Print output to STDOUT
n = gets.strip.to_i
test=[]
n.times do
test<<gets.strip.chars.uniq
end
puts test.inject(&:&).size
| true |
ff3a1087186e4e78066dd6d5a53160587ecfe82e | Ruby | Joz84/rails-stupid-coaching | /app/controllers/coaching_controller.rb | UTF-8 | 675 | 3.203125 | 3 | [] | no_license | class CoachingController < ApplicationController
def answer
@query = params[:query]
phrase = coach_answer(@query)
if @query == @query.upcase
if phrase == ""
@stupid_answer = ""
else
@stupid_answer = "I can feel your motivation! " + phrase
end
else
@stupid_answer... | true |
1d37dbb2d96929583e8cd54a839787fca8f77e5b | Ruby | melmar12/MIS-ruby-practice-problems | /names-dob.rb | UTF-8 | 348 | 3.25 | 3 | [] | no_license | puts "Hello, what is your name?"
name = gets.chomp
puts "What is your DOB?"
dob = gets.chomp
if File.exist?('directory.txt')
File.open('directory.txt', 'a') do |f|
f << "name: " + name + " dob: " + dob + "\n"
f.close
end
else
File.open('directory.txt', 'w') do |f|
f << "name: " + name + " dob: " + dob ... | true |
ef52bca3921d8ef73c91b712b840c473e4e35edc | Ruby | JohnAllen117/sinatra-lunar-kitchen | /models/recipe.rb | UTF-8 | 1,458 | 3.40625 | 3 | [] | no_license | # Creates a recipe for the webpage to latch onto
class Recipe
attr_reader :id, :name, :description, :instructions, :ingredients
def initialize(recipe)
@id = recipe['id']
@name = recipe['name']
@instructions = get_initial_instructions(recipe['instructions'])
@description = get_initial_description(rec... | true |
ce085d9974b93574f88a98bbedb05830ec079b3d | Ruby | sparklemotion/mechanize | /examples/wikipedia_links_to_philosophy.rb | UTF-8 | 3,117 | 3.515625 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'mechanize'
require 'tsort'
##
# This example implements the alt-text of http://xkcd.com/903/ which states:
#
# Wikipedia trivia: if you take any article, click on the first link in the
# article text not in parentheses or italics, and then repeat, you will
# eventually end up at "Philosophy".
class Wikipedia... | true |
c7ee7cdd8d930e7db6b064c741fe897fd0daf9ef | Ruby | AScodersWH/watir | /lib/watirspec/implementation.rb | UTF-8 | 1,280 | 2.515625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module WatirSpec
class Implementation
attr_writer :name, :guard_proc, :browser_class
attr_accessor :browser_args
def initialize
@guard_proc = nil
end
def initialize_copy(orig)
super
# Backward compatibility < Ruby 2.4
@browser_args = browser_args.map { |arg| arg.is_a?(Sym... | true |
e945fb57fc01023f50c5dce7224e2b5444bdcbc0 | Ruby | moissoliveira/books_app | /app.rb | UTF-8 | 3,782 | 2.71875 | 3 | [] | no_license | #require 'benchmark'
#require 'sinatra/cross_origin'
require 'json'
#require 'fuzzystringmatch'
require 'string/similarity'
class App < Sinatra::Base
get '/home' do
redirect '/home?page=1' unless @params["page"]
redirect "/home?page=#{@params["page"]}" if @params["query"] == ""
pagina = @params["page"].t... | true |
01085cc89003ae1e68f922421d7ca9df19c93a5b | Ruby | jayramrout/learning | /languages/cookbook/tour/ruby.rb | UTF-8 | 874 | 4.5 | 4 | [] | no_license | # Outputting a string
puts "Hello World!"
# Assigning a value to a variable
my_variable = 5
# Defining a class with an instance method
class MyClass
def my_method
"my_method was invoked"
end
end
# Instantiating an object from a class
my_object = MyClass.new
# Checking what class an object is
puts "Hello, Wo... | true |
1c71ffa992b95c6f99540e4ac529ec077a3898eb | Ruby | YoyoCodes/boris-bikes | /spec/docking_station_spec.rb | UTF-8 | 1,416 | 3.078125 | 3 | [] | no_license | require "docking_station"
describe DockingStation do
describe "docking station" do
it "responds to release_bike" do
expect(subject).to respond_to :release_bike
end
it { is_expected.to respond_to(:dock).with(1).argument} #should be done for every method that has arguments
it {is_expected.to r... | true |
884a41e5e8f635eb02dc3be5da08773c6fbc1639 | Ruby | sansuaza/RubyUdemy | /section17/Start_End_With_Methods.rb | UTF-8 | 111 | 3.109375 | 3 | [] | no_license | frase = "Ruby es un lenguaje muy intuitivo"
p frase.start_with?("Ruby") # True
p frase.end_with?("ivo") # True | true |
f09d50fe1cc735a4d41b2f3746a1fda7513ee8c6 | Ruby | alexandreaquiles/7in7 | /languages/ruby/a_quick_history.rb | UTF-8 | 342 | 3.390625 | 3 | [] | no_license | properties = ['object oriented' , 'duck typed' , 'productive' , 'fun' ]
# => ["object oriented", "duck typed", "productive", "fun"]
properties.each {|property| puts "Ruby is #{property}." }
# Ruby is object oriented.
# Ruby is duck typed.
# Ruby is productive.
# Ruby is fun.
# => ["object oriented", "duck typed", "... | true |
5d6577ba67425940389a7672223d836ba19ca1c0 | Ruby | ucam-campos/Teste_e_Qualidade_de_Software | /#52 refactoring_condicional/2019-2/anderson_spec.rb | UTF-8 | 522 | 2.625 | 3 | [] | no_license | require 'anderson'
describe Aviao do
context 'Polimorfismo para altitude de cruzeiro' do
it 'Retorna altitude de Concorde' do
concorde = Concorde.new('Concorde')
expect(concorde.altitude_de_cruzeiro).to eq(750)
end
it 'Retorna altitude de Airbus' do
airbus = Airbus.new('Airbus')
... | true |
fe09d3ae5c0d3ab857de7868d8d21c4fc293859d | Ruby | Lawrenccee/w2d1 | /chess/sliding_piece.rb | UTF-8 | 1,205 | 3.421875 | 3 | [] | no_license | module SlidingPiece
DIAGS = [[1,1], [1,-1], [-1,-1], [-1,1]]
LINES = [[-1,0], [1,0], [0,-1], [0,1]]
def SlidingPiece.moves(curr_pos, directions, board)
possible_moves = []
if directions.include?(:diags)
possible_moves += get_moves(curr_pos, board, DIAGS)
end
if directions.include?(:lines... | true |
2ef8b8f33dbbf558e6234213d42114cbc08e58b8 | Ruby | ot-brett-bim/Sapphire | /lib/sapphire/DSL/Comparisons/ContainsComparison.rb | UTF-8 | 364 | 2.734375 | 3 | [
"MIT"
] | permissive | module Sapphire
module DSL
class ContainsComparison < Comparison
def Compare(left, right)
return @comparator.Compare((right.include? left), true) if @comparator != nil
right.include? left
end
def Text
return @comparator.Text + " to contain" if @comparator != nil
... | true |
c740c039c0651ffa94fc24cfac30d61b1349a2a6 | Ruby | fishermanswharff/wdi_2_ruby_quiz_string_manipulation | /spec/quiz_spec.rb | UTF-8 | 1,308 | 3.796875 | 4 | [] | no_license | require 'spec_helper'
require_relative '../quiz'
# The first question's tests are written.
# run rspec quiz_spec.rb
describe "#sleep_in?" do
it "returns true if the current day is Saturday or Sunday" do
# assuming you're answering this on a weekday!
expect(sleep_in?).to be(false)
end
it "takes an options... | true |
d0f9d29a20fdcb606b577c9e493fef31865b7f75 | Ruby | juliema/taxonworks | /spec/models/collection_object/biological_collection_object_spec.rb | UTF-8 | 4,086 | 2.546875 | 3 | [] | no_license | require 'spec_helper'
describe CollectionObject::BiologicalCollectionObject do
let(:biological_collection_object) { CollectionObject::BiologicalCollectionObject.new }
describe "instance methods" do
# TODO: true?
it "should have a verbatim_determination_label"
# it seems as though these method t... | true |
8751abd62e82d8fdf35d33be75a78616b701b9a8 | Ruby | RobertoBarros/batch_513_cookbook_day_one | /lib/controller.rb | UTF-8 | 813 | 3.15625 | 3 | [] | no_license | require_relative 'view'
class Controller
def initialize(cookbook)
@cookbook = cookbook
@view = View.new
end
def list
# Pegar todas as receitas do cookbook
recipes = @cookbook.all
# Mandar para a view exibir
@view.display(recipes)
end
def create
# Perguntar o nome da receita
... | true |
787cd3cb9c8afb5d22ed5445a4e696a997892217 | Ruby | Smithe941/pocket_owel | /run.rb | UTF-8 | 387 | 2.828125 | 3 | [] | no_license |
require 'after_do'
load 'tamagotchi.rb'
owl = Owel.new
command = 0
p 'named your owel'
owl.name = gets.chomp
# k = gets.chomp
loop do
p 'Enter command'
break if (command = gets.chomp.downcase) == 'exit' || owl.alive == true
if owl.respond_to? command.to_sym
owl.send command.to_sym
else
p 'unknown c... | true |
ec1b42d6df5979636685c24e94c96aaa85a4aec6 | Ruby | direct-democracy-berlin/direct-democracy-opinion | /app/models/vote.rb | UTF-8 | 1,137 | 2.53125 | 3 | [
"MIT"
] | permissive | # == Schema Information
#
# Table name: votes
#
# id :bigint not null, primary key
# vote :string not null
# created_at :datetime not null
# updated_at :datetime not null
# thesis_id :bigint not null
# user_id :bigint not null
#
# Indexes
#... | true |
10f59dc1d3c8cecfbb5ba71bdf60a0104b583ee5 | Ruby | cwkarwisch/RB101 | /small_problems/easy_8/exer_03.rb | UTF-8 | 1,049 | 4.3125 | 4 | [] | no_license | =begin
Input: String
Output: Array of Strings
Explicit Req's
Return list of all substrings, starting from beginning of string
Arranged from shortest to longest
Implicit Reqs
Emptry string return empty array?
Validate for non-string types?
Return a new array object?
Don't stop if string includes spaces?
Starting wit... | true |
6f0f55d44f2a417d2203ce5f0ebee1653a8e0c8e | Ruby | EnigmaticGale/Hwrk-w2d2 | /river.rb | UTF-8 | 233 | 3.46875 | 3 | [] | no_license | class River
attr_reader :name, :fish_array
def initialize(name)
@name = name
@fish_array = []
end
def fill_river(newfish)
@fish_array << newfish
end
def fish_count
return @fish_array.length
end
end
| true |
a423994a2fc64be95b552e6408f9903fd25ad9cd | Ruby | Itggot-gabriel-takolander/count_with_step | /test/test_count_with_step.rb | UTF-8 | 1,150 | 2.828125 | 3 | [] | no_license | require 'minitest'
require 'minitest/autorun'
require 'minitest/reporters'
require_relative '../lib/count_with_step'
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
describe 'count' do
it 'takes take start and stop and step as arguments' do
proc { count_with_step() }.must_raise ArgumentEr... | true |
235548be3410e11fe4ecaa5079f5c4c1f2c15817 | Ruby | mmua/sensu-plugins-sms | /bin/handler-smsc.rb | UTF-8 | 1,914 | 2.921875 | 3 | [
"MIT"
] | permissive | #! /usr/bin/env ruby
#
# handler-smsc.rb
#
# DESCRIPTION:
# Sensu handler for sending SMS messages through a SMSC gateway.
#
# OUTPUT:
# None unless there is an error
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
# gem: sensu-handler
# gem: smsc
#
# USAGE:
#
# Configure your SMSC user, and secret here:
# s... | true |
8962cb031e566dfd6c92eda3fb97136c23ed366a | Ruby | yuta-ushijima/zoom_script | /get_meeting_room.rb | UTF-8 | 440 | 2.75 | 3 | [] | no_license | require 'net/https'
require 'net/http'
require 'uri'
require 'json'
require 'pry'
token = "Your token"
url = URI.parse("https://api.zoom.us/v2/users")
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer #{token}"
req_options = {
use_ssl: url.scheme == "https",
}
response = Net::HTTP.start(url.hos... | true |
2d25fd9958cbfbe713d4eeb4929ff209b1400acf | Ruby | 404pnf/iyc_novel2csv | /test_remove_line_feed_in_paragraph.rb | UTF-8 | 871 | 2.6875 | 3 | [] | no_license | require 'minitest/autorun'
require_relative 'remove_linefeed_in_paragraph.rb'
# tests
UNFORMATED = "111111\n111111\n\n\n 22222\n 22222\n\n\n\n111111\n111111"
FORMATED = "111111 111111\n\n 22222\n 22222\n\n111111 111111"
class TestSanitize < MiniTest::Unit::TestCase
def test_remove_line_feed
assert_equa... | true |
94786dc9c15be9054c6b42efb01e6dd537fc551b | Ruby | ks2355244/parsing-data-1 | /serialization.rb | UTF-8 | 3,297 | 3.65625 | 4 | [] | no_license | require 'csv'
require 'date'
class Person
attr_reader :id, :first_name, :last_name, :email, :phone, :created_at
def initialize(components = {})
@id = components[:id]
@first_name = components[:first_name]
@last_name = components[:last_name]
@email = components[:email]
@phone = components[:phon... | true |
7e570dafac04e92af68eead4f98fa1c3961bc62b | Ruby | yuichi-1208/ReaDo | /spec/models/summary_spec.rb | UTF-8 | 3,717 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
describe '要約モデル機能', type: :model do
describe 'バリデーションのテスト' do
before do
@user1 = FactoryBot.create(:user)
@book1 = FactoryBot.create(:book)
end
context '要約のカテゴリーが空の場合' do
it 'バリデーションにひっかかる' do
summary = Summary.new( category: '', content: '嫌われる勇気の要約', user... | true |
8a775937de4f925d598684f6cbd363439e412c20 | Ruby | bchutchison/Project_Spending_Tracker | /models/merchant.rb | UTF-8 | 1,437 | 2.984375 | 3 | [] | no_license | require_relative('../db/sql_runner')
class Merchant
attr_reader :id
attr_accessor :name
def initialize(options)
@id = options['id'].to_i if options['id']
@name = options['name']
end
def save()
sql = "INSERT INTO merchants
(name)
VALUES
($1)
RETURNING id"
values = [@name]
... | true |
28679e4fc61b2a9063b73980f004a617e45492fc | Ruby | iandstanley/reckon | /lib/reckon/csv_parser.rb | UTF-8 | 7,955 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #coding: utf-8
module Reckon
class CSVParser
attr_accessor :options, :csv_data, :money_column_indices, :date_column_index, :description_column_indices, :money_column, :date_column
def initialize(options = {})
self.options = options
self.options[:currency] ||= '$'
@csv_data = parse(options[... | true |
52d4606ee0efd2686281c36afea72d2a7745523f | Ruby | marlitas/ArtspirationFE | /app/poros/artwork.rb | UTF-8 | 429 | 2.703125 | 3 | [] | no_license | class Artwork
attr_reader :id,:user_id, :url, :title, :artist, :artist_url, :liked
def initialize(artwork)
@id = artwork[:id]
@user_id = artwork[:attributes][:user_id]
@url = artwork[:attributes][:image]
@title = artwork[:attributes][:title]
@artist = artwork[:attributes][:artist]
@artist_u... | true |
cd340a0aaf4094044dbb15b6bdbd3d7805717eb5 | Ruby | bwatson78/cartoon-collections-v-000 | /cartoon_collections.rb | UTF-8 | 546 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def roll_call_dwarves(dwarves)
dwarves.each_with_index do |name, index|
puts "#{index + 1} #{name}"
end
end
def summon_captain_planet(calls)
summons = []
calls.collect do |planeteer|
summons << "#{planeteer.capitalize}!"
end
summons
end
def long_planeteer_calls(calls)
calls.any? { |words| words.... | true |
4cfb0698a2cbe8fc540c98eca3fa86a4f897aab8 | Ruby | Lykos/SquirrelDB | /lib/ast/rel_alg_operators/projection.rb | UTF-8 | 706 | 2.765625 | 3 | [] | no_license | require 'ast/rel_alg_operators/rel_alg_operator'
module SquirrelDB
module AST
class Projection < RelAlgOperator
def initialize(columns, inner)
@columns = columns
@inner = inner
end
attr_reader :columns, :inner
def to_s
"Projection_{" + @columns.collect { |r| r... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.