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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ab2b0c36cc8bf7f916532b2e95697e91c9c46530 | Ruby | abdulkalam7/kalam | /ex3.rb | UTF-8 | 419 | 3.484375 | 3 | [] | no_license | #ex3 badsic math opration calculation applies pemdas method
puts 'i\'ll count the totall numbers of chickens'
puts "hens = #{100-30*2}"
puts "roasters = #{100-25*3%4}"
puts "now i\'ii count the eggs"
puts 3+10.0-3/2*4%2
puts "is that true"
#finding true or false
puts 3+5>3-5
puts "what is 100-87. the ans... | true |
5c4f9251865e849e8eadcd29fffec5bbdbe0ac2b | Ruby | RichardGregoryHamilton/Conversions | /spec/temperature_spec.rb | UTF-8 | 534 | 3 | 3 | [] | no_license | require 'spec_helper'
describe Temperature do
before :each do
@temperature = Temperature.new(56)
end
describe "#new" do
it "should create a new temperature object" do
expect(@temperature.instance_of?(Temperature)).to be(true)
end
end
describe "#to_farenheit" do
it "should convert to ... | true |
a60d25e339652de27a3a877f8b4ab5404f93cec8 | Ruby | jastack/projects | /board.rb | UTF-8 | 1,430 | 3.71875 | 4 | [] | no_license | require_relative 'piece'
require_relative 'null_piece'
class Board
attr_reader :grid
def initialize
set_grid
end
def set_grid
end_rows = Array.new(2) { Array.new(8) { Piece.new } }
mid_rows = Array.new(4) { Array.new(8) { NullPiece.new } }
other_rows = Array.new(2) { Array.new(8) { Piece.new ... | true |
32d5e9c65ffa2d4008bc724eba6989d57f324169 | Ruby | EARoa/IronYard-Day3 | /homework.rb | UTF-8 | 1,631 | 4.03125 | 4 | [] | no_license | # Just like yesterday's homework
# This time as much as possible do not look back at previous examples.
# Be sure to use git to add your homework changes to your repo on github.
# BONUS + Highly recommened, use comments to describe what is happening with each step
# PART 1
# 1. Make an array of your classmate's names
... | true |
8fecd5f9f16f1521c408349453b7b8b84ebb615f | Ruby | jokale/pokemon-scraper-online-web-ft-120919 | /lib/pokemon.rb | UTF-8 | 628 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Pokemon
attr_accessor :id, :name, :type, :db
def initialize(id:1, name: "Pikachu", type: "electric", db: @db)
@id=id
@name=name
@type=type
@db =db
end
def self.save(name, type, db)
db.execute("INSERT INTO pokemon (name, type)
VALUES (?,?)", [name, type])
@id = db.ex... | true |
36496d6dcaefde1285f1f7da09ddb9d83b8ce48f | Ruby | travisstyleup/travis-core | /lib/core_ext/module/async.rb | UTF-8 | 1,096 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'thread'
require 'singleton'
require 'delegate'
require 'monitor'
class Async
include Singleton
def initialize
@queue = Queue.new
Thread.new { loop { work } }
end
def work
block = @queue.pop
block.call if block
rescue Exception => e
puts e.message, e.backtrace
end
def run(&... | true |
9eaaedfdbcfbc44b278f5d17f69a8b9d1e93d0ec | Ruby | jordannadroj/cookbook | /lib/controller.rb | UTF-8 | 1,891 | 3.1875 | 3 | [] | no_license | # controller
# require the model
require_relative 'recipe'
# require the view
require_relative 'view'
require_relative 'parsing'
require 'nokogiri'
require 'open-uri'
require "pry-byebug"
class Controller
attr_accessor :cookbook
def initialize(cookbook)
@cookbook = cookbook
@view = View.new
end
def ... | true |
a97724918f6c5939ffd8f758f9e7825eb91ea560 | Ruby | vijendra/mars-rovers | /lib/rover.rb | UTF-8 | 685 | 3.359375 | 3 | [
"MIT"
] | permissive | class Rover
attr_accessor :position
def initialize(params, plateau)
@position = Position.new(params, plateau)
end
def process_instructions(instruction)
instruction.each_char do |command|
case command
when 'M' then move_forward
when 'L' then turn_left
when 'R' then turn_righ... | true |
73bf7f34e7e16a9dab709d65fb3be6e0070fb924 | Ruby | yuichiro19/mahjong-score | /app/controllers/scores_controller.rb | UTF-8 | 3,389 | 2.546875 | 3 | [] | no_license | class ScoresController < ApplicationController
before_action :set_game
before_action :set_scores, only: [:index, :show]
before_action :authenticate_user!
def index
@score = Score.new
end
def create
point_calc
@score = Score.create(score_params)
if @score.save
redirect_to game_scores_... | true |
20b1fafd1b6304b6a6dcf1411d94e9aaa53c4447 | Ruby | karen1130/CalculatorChallenge- | /CalcProject.rb | UTF-8 | 529 | 4.21875 | 4 | [] | no_license |
puts "What does x equal?"
x = gets.strip.to_f
puts "What does y equal?"
y = gets.strip.to_f
puts "What is your equation? Choose multiply, add, subtract, divide, exponent."
equation = gets.strip
if equation == "multiply"
puts "Your answer is #{x * y}"
elsif equation == "add"
puts "Your answer is #{x... | true |
e2bc44722d687e8254fdc48bb1e92c809e2bbb01 | Ruby | coyled/hdfshealth | /lib/hdfshealth/plugins/load_nn_jmx.rb | UTF-8 | 1,703 | 2.546875 | 3 | [
"MIT"
] | permissive | #
# load namenode /jmx output for use by other plugins
#
class LoadNNJMX < HDFSHealth::Plugin
require 'uri'
require 'net/http'
require 'json'
@jmx = {}
def self.jmx(namenode)
unless @jmx[namenode]
self.fetch_jmx(namenode)
end
@jmx[namenode]
end
def se... | true |
4a4c158eecd04084541e18ea3c71962a894ede28 | Ruby | Arielle919/linked_list_cohort3 | /lib/linked_list.rb | UTF-8 | 1,450 | 3.40625 | 3 | [] | no_license | class LinkedList
attr_accessor :payload, :head_item
def initialize(*payload)
@last_node = nil
@count = 0
payload.each do |item|
add_item(item)
end
end
def add_item payload
if @head_node.nil?
@head_node = LinkedListItem.new(payload)
@count += 1
@last_node = @head_nod... | true |
a4c31f14810a3cc3b88db2ec721a82f39543e30d | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/fc2dba92c923475e8c7ff72fd922ce53.rb | UTF-8 | 536 | 3.390625 | 3 | [] | no_license | class Hamming
def self.compute(dna_strand_1, dna_strand_2)
dna_strand_1_array = dna_strand_1.split(//)
dna_strand_2_array = dna_strand_2.split(//)
length_shortest_strand = dna_strand_1.length
length_shortest_strand = dna_strand_2.length if dna_strand_2.length < dna_strand_1.length
i=0
hammin... | true |
143a947537a376a9b53337bdb793b9f1d543d044 | Ruby | Zequez/mapa-de-transporte | /lib/my_encryptor.rb | UTF-8 | 343 | 2.875 | 3 | [
"MIT"
] | permissive | require 'base64'
class MyEncryptor
def self.encode(data)
Base64.encode64(data).strip.gsub(/\n|=/, "").reverse
end
def self.decode(data)
Base64.decode64(data.reverse + ("=" * (data.size % 4)))
end
def self.domain_validator(domain)
sum = 0
domain.each_codepoint {|l|sum += l*l}
... | true |
d91dd578c4006517d2988d554104061bb0b9615d | Ruby | nskillen/aoc2018 | /mkday.rb | UTF-8 | 415 | 3.078125 | 3 | [] | no_license | require 'fileutils'
day = lambda do |d|
<<~EOF
require_relative 'day'
require 'io/console'
class #{d.upcase} < Day
def wait
puts "Press any key to continue..."
STDIN.getch
end
def part_one
end
def part_two
end
end
EOF
end
d = "d#{ARGV[0]}"
d = d[1..-1] if d.start_with?("dd")... | true |
b3143ff764e82ad3dcb965881879ceae80a8a29c | Ruby | Hamzaoutdoors/School_Library_Ruby | /library/rentals/main.rb | UTF-8 | 1,406 | 3.734375 | 4 | [] | no_license | require './library/rentals/rental'
class RentalIntializer
def initialize
@rentals = []
end
def create_rental(books, people)
if people.empty? && books.empty?
puts 'Your Library is empty add books and people'
return
end
puts 'Select a book from the following list by number'
books.e... | true |
8e9ecfbf23b71580dfe68bbb2acab46ca55ec932 | Ruby | ggerdsen/Web_Scraper_Ruby | /lib/scraper.rb | UTF-8 | 1,017 | 2.859375 | 3 | [
"MIT"
] | permissive | require_relative 'output.rb'
class Scraper
include Output
attr_accessor :page
def initialize(page)
@page = page.read_html
end
def jobs_list
jobs = []
job_offers = @page.css('div.jobsearch-SerpJobCard')
job_offers.each do |entry|
job = job(entry)
jobs << job
end
jobs
end... | true |
b40225aa2f20603980f85daa53e81d323801bd98 | Ruby | vendetta546/codewars | /Ruby/6KYU/StringRotate.rb | UTF-8 | 999 | 4 | 4 | [] | no_license | =begin
Write a function that receives two strings and returns n, where n is equal to
the number of characters we should shift the first string forward to match the
second.
For instance, take the strings "fatigue" and "tiguefa". In this case, the first
string has been rotated 5 characters forward to produce the second... | true |
3662b5a63b90f1b0385a9a7013abf1ec0a8aa89f | Ruby | WojciechKo/ruby-playground | /spec/instance_method_spec.rb | UTF-8 | 981 | 2.53125 | 3 | [] | no_license | RSpec.describe 'Module#instance_method' do
let(:arrays) { [['a', 'b'], ['c'], ['d', 'e']] }
let(:hashs) { [{ 'a' => 1 }, { 'b' => 2, 'c' => 3 }, { 'd' => 4, 'e' => 5 }] }
specify do
expect(arrays[0].zip(*arrays[1..]))
.to match_array([['a', 'c', 'd'], ['b', nil, 'e']])
expect(Array.instance_method... | true |
c534d83583721f392608d6036c191e13e2fa929d | Ruby | honorwoolong/launch_school | /RB101/Lesson_6/tictactoe_bonus_adv.rb | UTF-8 | 4,668 | 3.90625 | 4 | [] | no_license | require 'pry'
require 'pry-byebug'
# ask if player wants to go first or not
# 1 display the board
# 2 player place the piece
# 3 computer place the piece
# if player has 2 squares marked, computer must pick the 3rd square
# else put square randomly
# 4 continue until someone won 5 games
# display score
# restart the ga... | true |
3870e3fdb5dd0834dba3c0efdc88c9a81310c6db | Ruby | serg-kovalev/url_shortener | /config.ru | UTF-8 | 531 | 2.5625 | 3 | [] | no_license | require 'rack'
require_relative 'url_shortener.rb'
class Application
def self.call(env)
req = Rack::Request.new(env)
res = Rack::Response.new
if req.path_info.match /\/get_short_url\/.+/
long_url = req.path_info.sub('/get_short_url/', '')
short_url = UrlShortener.new.get_short_url(long_url)
... | true |
27e4eddeddff0960ab0eae2ba99deb61d6a10075 | Ruby | TimCummings/launch_school | /101-programming_foundations/ruby_basics/variable_scope.rb | UTF-8 | 2,556 | 4.21875 | 4 | [] | no_license | # variable_scope.rb
# What's My Value? (Part 1)
7
# Once the my_value method is exited, a remains 7 since it was modified only in the scope of the method, my_value; also, += does not mutate the caller for integers.
# What's My Value? (Part 2)
7
# The a outside the my_value method and the a inside the my_value metho... | true |
434f65d97ab32cda1fa6c82c648d73d25cb3c58e | Ruby | minling/ruby-oo-assessment-web-0615-public | /lib/array_list.rb | UTF-8 | 517 | 4.46875 | 4 | [] | no_license | # Create a method on array called `list` that iterates over the array it is
# called on and appends a number, a period, and a space to each element.
# e.g ["ich", "ni", "san"].make_list #=> ["1. ich", "2. ni", "3. san"]
class Array
# def list
# @array
# end
def make_list
self.map.with_index do |it... | true |
ee51570258bc2b7bfecb617c8316aa07de837b75 | Ruby | doryberthold1987/rollavg | /rollavg | UTF-8 | 8,133 | 3.3125 | 3 | [] | no_license | #!/usr/bin/env ruby
### rollavg --- Utility for calculating a simple rolling average.
## Copyright 2006 by Dave Pearson <davep@davep.org>
## $Revision: 1.8 $
##
## rollavg is free software distributed under the terms of the GNU General
## Public Licence, version 2. For details see the file COPYING.
###################... | true |
1f151e25c9868b3e67b22e9802de808725cbb1e1 | Ruby | scottefein/youve_got_mail | /youve_got_mail.rb | UTF-8 | 1,554 | 2.765625 | 3 | [] | no_license | require 'sinatra'
require 'uri'
require 'twilio-ruby'
require 'puma'
class YouveGotMail < Sinatra::Base
configure do
set :notify_numbers, ENV['NOTIFY_NUMBERS'].split(',')
set :twilio_number, ENV['TWILIO_NUMBER']
set :twilio_sid, ENV['TWILIO_SID']
set :twilio_token, ENV['TWILIO_TOKEN']
end
def twilio_au... | true |
c02f0824f93978fd67203bb3057aad292ca5c3fc | Ruby | cyberkov/puppetdb-dokuwiki | /gendoc.rb | UTF-8 | 2,355 | 2.609375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/http'
require 'uri'
require 'pp'
require 'erb'
require 'pry'
class Wikipage
attr_accessor :error
include ERB::Util
def initialize(options = {})
unless options["error"]
@vars = {}
@error = false
options["facts"].each do |k... | true |
724dd1a19ba109d55c8464feca709b73abec5d12 | Ruby | eminisrafil/ShoutRoulette-Rails-Backend | /app/models/room.rb | UTF-8 | 2,972 | 2.5625 | 3 | [] | no_license | # == Schema Information
#
# Table name: rooms
#
# id :integer not null, primary key
# session_id :string(255)
# topic_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# agree :boolean
# disagree :boolean
#
class Room < ActiveRecord::Base
bel... | true |
478e7176ad351184c9435237b8f7788ae3c08dea | Ruby | TomJamesDuffy/Boris | /spec/van_spec.rb | UTF-8 | 1,233 | 2.75 | 3 | [] | no_license | require 'van'
describe Van do
let(:dummy_bike_working) { double :dummy_bike_working, working: true }
let(:dummy_bike_not_working) { double :dummy_bike_working, working: false }
describe ':get_instructions' do
it 'raises an error if input is not in an appropriate format' do
expect{ subject.get_instruction... | true |
9bf64d33fe39a1a757536896f697178122b9fdcf | Ruby | bryouf22/magic | /app/models/deck.rb | UTF-8 | 2,878 | 2.515625 | 3 | [] | no_license | # == Schema Information
#
# Table name: decks
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# name :string
# colors :integer is an Array
# format_ids :integer ... | true |
ea78284301948414ea7999ce6564080755d4af6d | Ruby | shouya/revo-old | /lib/revo/value.rb | UTF-8 | 820 | 2.734375 | 3 | [] | no_license |
module Revo
class Value
def atom?
true
end
def list?
!atom?
end
alias_method :pair?, :list?
def is_true?
true
end
def is_false?
!is_true?
end
def code?
false
end
def data?
!code?
end
def null?
false
end
def ... | true |
1602a5c96e0ef7e5c532bf2343275c395f22bb71 | Ruby | xaop/xmpp_bot | /lib/XMPP.rb | UTF-8 | 11,262 | 2.671875 | 3 | [] | no_license | require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/roster'
require 'xmpp4r/vcard'
require 'drb'
require 'yaml'
require 'mutex_m'
class Jabber::JID
##
# Convenience method to generate node@domain
def to_short_s
s = []
s << "#@node@" if @node
s << @domain
return s.to_s
end
end
module XMPPB... | true |
37a9b7a70804f113ba1ece2ae32ac034c67b49dc | Ruby | michaeljohnsargent/complete_ror_developer | /S2/section2_19_working_with_numbers.rb | UTF-8 | 696 | 4.34375 | 4 | [] | no_license | # puts 1 + 2
# x = 5
# y = 10
# puts y / x
# puts "I am a line"
# puts "-"*20
# puts "I am a different line"
# 20.times { print "-" }
# #20.times { puts "hi" }
# #20.times { puts rand(10) }
# x = "5".to_i
# p x
# p x.to_f
# p "10".to_f
puts "Simple calculator"
25.times { print "-" }
puts "\nEnter the first num... | true |
6b233297e4c52c9ef6a2fef68d03569d4b738ec1 | Ruby | leerivera/oo-relationships-practice | /app/models/dessert.rb | UTF-8 | 544 | 3.1875 | 3 | [] | no_license | class Dessert
attr_accessor :name, :bakery
####when its says "belongs to" put a attr to ref
#the class it belongs too. the attr reader on dessert
### is the sticker that states it's relationship
### dessert does not need ingredients because ingredients belong to it
### and my sticker is on ingredi
@@all = []
... | true |
256593d419001f7631ba175527fb5ac21248de76 | Ruby | sanjsanj/ruby-shop | /lib/models/shop.rb | UTF-8 | 587 | 2.84375 | 3 | [] | no_license | require 'json'
require_relative 'cart'
require_relative 'products'
class Shop
attr_accessor :cart, :products
def initialize(cart: Cart.new, products: Products.new)
@products = products
@cart = cart
end
def shop_products
products.data
end
def add_to_cart(id:)
cart.add_item(item: item(id... | true |
a79ac925ec81b44eb8a057066579d6dd583aab42 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/anagram/e1cd91b665c74ef7a22f16a6bd25bbfc.rb | UTF-8 | 366 | 3.84375 | 4 | [] | no_license | class Anagram
attr_reader :word_to_match
def initialize(word_to_match)
@word_to_match = word_to_match.downcase
end
def match(words)
words.select { |word| anagram?(word) }
end
private
def anagram?(word)
word_to_match.chars.sort == word.chars.sort unless identical?(word)
end
def identic... | true |
760ce81f12d7abd6cc29993cb505cac9c8696ff3 | Ruby | kingsleyh/redfighter | /app/models/fight_bar.rb | UTF-8 | 269 | 2.65625 | 3 | [] | no_license | class FightBar < ActiveRecord::Base
belongs_to :player
def slots
[slot_1,slot_2,slot_3,slot_4,slot_5].map{|i| item(i)}
end
private
def item(slot)
a = FightItem.where(:id => slot)
a.empty? ? OpenStruct.new(:name => 'empty') : a.first
end
end
| true |
e29fb35dd8015d5b9630d07f9db25b1c5f263588 | Ruby | dmagro/activerecord-import-example | /lib/tasks/import_records.rake | UTF-8 | 1,779 | 3 | 3 | [] | no_license | require "benchmark"
namespace :import do
BOOKS_PATH = "#{Rails.public_path}/books/"
def read_books
books = []
Dir.foreach(BOOKS_PATH) do |item|
next if item == '.' or item == '..'
puts "Reading #{item}...".green
books << read_book(item)
end
books
end
def read_book(file_name)... | true |
1c51e52fc07c5eeb74a7b49b578fd9db213add5e | Ruby | Earth35/basic_ruby_projects | /stock_picker.rb | UTF-8 | 720 | 4.0625 | 4 | [] | no_license | def stock_picker (input)
max_income = 0
buying_day = nil
selling_day = nil
0.upto(input.length-2) do |i|
current_price = input[i]
(i+1).upto(input.length-1) do |j|
profit = input[j] - input[i]
if (profit > max_income)
buying_day = i
selling_day = j
max_income = profit
end
end
end
ret... | true |
6da77cf03ca891bd030564151826736306003dc5 | Ruby | nozpheratu/tournament_sandbox | /test.rb | UTF-8 | 120 | 3.046875 | 3 | [] | no_license | h1 = {:stuff => [1,2,3]}
h2 = h1.dup
h2[:stuff].delete_at(0)
puts h1 #=> {:stuff=>[2, 3]}
puts h2 #=> {:stuff=>[2, 3]}
| true |
bcbc8a8b3fc6562b4123d01f0642d9b9ec43dcd0 | Ruby | Hollyberries/deli-counter-onl01-seng-pt-050420 | /deli_counter.rb | UTF-8 | 616 | 3.765625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | katz_deli = []
def line(line_array)
if line_array.length == 0
puts "The line is currently empty."
else
line_prompt = "The line is currently: "
line_array.each.with_index(1) do |person, line_number|
line_prompt += "#{line_number}. #{person} "
end
puts line_prompt.strip
end
end
def take_a_... | true |
27d7471f9575582b1af00034411a5682983d71d9 | Ruby | urzp/TicTacToe | /main body.rb | UTF-8 | 347 | 2.71875 | 3 | [] | no_license | include TicTacToe
game=Game_place.new
a_man=Human.new
comp=Computer.new
puts "********************************"
coin_toss(a_man, comp, game)
game.draw_board
puts "********************************"
while !game.stop do
current_player = game.who_turn?
player_chose = current_player.turn(game.board)
game.turn(player_... | true |
2cb4533d6e21b214b2103cd1512a4749df0476a3 | Ruby | bharatagarwal/launch-school | /100_back-end_prep/intro-to-programming/10_exercises/10.rb | UTF-8 | 90 | 2.96875 | 3 | [] | no_license | hash = {e: [1,2], b: [2,3]}
p hash[:b]
array = [{a: 1, b: 2}, {c: 3, d:4}]
p array[0][:b] | true |
c00abcb7ff0321a2f7a15abac9c555d029e22af6 | Ruby | jennli/quiz1_jan_25 | /question_2_stack_queue.rb | UTF-8 | 930 | 4.40625 | 4 | [] | no_license | # Stacks & Queues: Explain the difference between a stack and a queue. Write a Ruby class called Stack and another Ruby class called Queue. Each class should have two instance methods `add` and `remove` to add an element to the stack or queue or to remove an element from the stack or queue. Make sure that each class be... | true |
4278bb91b1cc96e7061be6815bba675cd7312145 | Ruby | sivanpatel/battle_ships-1 | /lib/board.rb | UTF-8 | 255 | 2.75 | 3 | [] | no_license | # require_relative 'battle_ship'
require_relative 'grid'
class Board
attr_accessor :placed_ships
def initialize
@placed_ships = []
end
# def total_ships -- use for getting locations
# @placed_ships.map { |ship| ship.size }
# end
end
| true |
0459f1817759dae0ce0b4e33bef8f2760da293b6 | Ruby | ghas-results/hammerspace | /spec/support/write_concurrency_test.rb | UTF-8 | 1,189 | 2.859375 | 3 | [
"MIT"
] | permissive | module WriteConcurrencyTest
# Initialize n hashes (of joyful nonsense), fork one process for each. Have
# them madly write their hash, and flush (repeat many, many times). While
# this is happening, read from the hammerspace. It should contain one of the
# n original hashes. Though which one I shall never tell... | true |
773f16c75a15e8f819cc4817f197a64213026701 | Ruby | chad-tung/week2_day3_snakes_ladders | /specs/dice_spec.rb | UTF-8 | 280 | 2.6875 | 3 | [] | no_license | require "minitest/autorun"
require "minitest/rg"
require_relative "../dice"
class TestDice < MiniTest::Test
def setup()
@dice = Dice.new(6)
end
def test_roll_dice()
result = (1..6).include?(@dice.roll())
assert_equal(true, result)
end
end
| true |
1cf4b9b550ef2d889e73f6bc19aaa814fa896406 | Ruby | tomerovadia/Battleship | /player.rb | UTF-8 | 6,446 | 3.65625 | 4 | [] | no_license | require_relative 'improved_board.rb'
require_relative 'improved_ship.rb'
require 'byebug'
require 'colorize'
class Player
attr_reader :board
attr_accessor :name, :ships, :game
def initialize(board = Board.new)
@board = board
@ships = []
end
def update_ships
@ships = @s... | true |
086fa7caae305323b3b85602e4a0d42c943c6844 | Ruby | chocopowwwa/ssbe-wsdl | /vendor/gems/resourceful-0.3.1/spec/resourceful/header_spec.rb | UTF-8 | 982 | 2.75 | 3 | [
"MIT"
] | permissive | require 'pathname'
require Pathname(__FILE__).dirname + '../spec_helper'
require 'resourceful/header'
describe Resourceful::Header do
it "should capitalize on all accesses" do
h = Resourceful::Header.new("foo" => "bar")
h["foo"].should == "bar"
h["Foo"].should == "bar"
h["FOO"].should == "bar"
... | true |
5c1783a176f3c3f149a6ea4477f86e1084d1af62 | Ruby | dcolebatch/pacer | /lib/pacer/pipe/group_pipe.rb | UTF-8 | 2,391 | 2.765625 | 3 | [
"BSD-3-Clause"
] | permissive | module Pacer::Pipes
class GroupPipe < RubyPipe
def initialize
super()
@next_key = nil
@key_pipes = []
@values_pipes = []
@current_keys = []
@current_values = nil
end
def setUnique(bool)
@unique = unique
@groups = {}
end
def addKeyPipe(from_pipe, to... | true |
b2560494a73be6697832380e36867d2b0a2052ea | Ruby | Sheval/algos | /ruby/dijkstra.rb | UTF-8 | 1,423 | 3.484375 | 3 | [] | no_license | #!/usr/bin/env ruby
# dijkstra algo sandbox
require "pry"
require_relative "stackless"
def wrap_time message
t1 = Time.now
res = yield
t2 = Time.now
puts "#{message} - Elapsed time #{t2-t1}s"
res
end
def read_from_file file_name
File.open(file_name, 'r').each_line do |line|
line_array = line.split
... | true |
460f9bd90aaa5fcff942a6897453964a128ccdb8 | Ruby | sanjsanj/mystuff | /ex08.rb | UTF-8 | 962 | 4.0625 | 4 | [] | no_license | # Define var formatter with %vars to use the same format with multiple values
formatter = "%{first} %{second} %{third} %{fourth}"
# put string of var formatter with integers defined within the hash array
puts formatter % {first: 1, second: 2, third: 3, fourth: 4}
# put string of var formatter with strings defined with... | true |
cd606a2d4cf89c2df4ae0b826f8c93cdd535bb90 | Ruby | skanev/evans | /lib/temp_dir.rb | UTF-8 | 353 | 2.6875 | 3 | [] | no_license | module TempDir
extend self
def for(files)
Dir.mktmpdir do |dir|
dir_path = Pathname(dir)
files.each do |name, contents|
file_path = dir_path.join(name)
FileUtils.mkdir_p(file_path.dirname)
open(file_path, 'w') { |file| file.write contents.encode('utf-8') }
end
... | true |
a26aacd0ba9ba5210dd9203fc4bfe649ca5183bd | Ruby | yourpromotioncode/Numbers | /Day9_2.rb | UTF-8 | 531 | 3.1875 | 3 | [] | no_license | # ids = ['mc11' , 'dt2002']
# for id in ids do
# if id == input_id
# puts("** " + id + "!! Welcome to ITW database hub")
# exit
# end
# end
#
# puts("** Invalid ID **")
puts("[Please enter your ID] \n")
input_id = gets.chomp()
def login(id)
members = ['mc11' , 'dt2002']
for member in memb... | true |
d5e9f3685a91f17a45b143dc94d2f25a8cc3ba8a | Ruby | MislavGunawardena/Back-End-Lesson01 | /excercises/problem_solving/advanced/7.rb | UTF-8 | 1,720 | 4.21875 | 4 | [] | no_license | # Method: merge
# Arguments: 2 arrays. Both containing sorted numbers.
# Side effects: None. Specifically, argument arrays should not be mutated.
# Return: A new array. Should contain all the elements of the argument arrays
# while maintaining the sorted order.
# Edge cases:
# merge([], [1, 4, 5]) == [1, 4, 5... | true |
05a6cb082e4878fea6c658e5d57a249f8f898545 | Ruby | AnguillaJaponica/Ruby_Library_For_Contests | /ABC/ABC083/C.rb | UTF-8 | 88 | 3.015625 | 3 | [] | no_license | x, y = gets.split.map(&:to_i)
res = 1
while 2 * x <= y
res += 1
x *= 2
end
puts res | true |
93271a179080a7a6007d16ccf4795187025ee37d | Ruby | yiyi1026/projecteuler_ruby | /p1-p50/p46.rb | UTF-8 | 392 | 2.984375 | 3 | [] | no_license | #P46
require 'prime'
#a=Time.now
def p46_single(n)
return nil if n%2 == 0 || Prime.prime?(n)
k=Prime.each(n-2).to_a.reverse
k.pop
for i in k
return i if (n-i)%2==0 && 2*(Math.sqrt((n-i)/2).to_i)**2==n-i
end
return false
end
def p46_multi(n)
i=9
while i<=n
l=p46_single(i)
return i if l==fal... | true |
c982a18b7729e6f846f042b29a2a5c44cbf12e85 | Ruby | wozane/57-exercises | /making_decisions/car_problems_2.rb | UTF-8 | 1,975 | 3.21875 | 3 | [] | no_license | is_car_silent = 'Is the car silent when you turn the key?'
is_battery_corroded = 'Are the battery terminals corroded?'
battery_corroded = 'Clean terminals and try starting again.'
battery_not_corroded = 'Replace cables and try again.'
is_making_clicking_noice = 'Does the car make a clicking noise?'
making_clicking_noi... | true |
2649de78b5ab87c942dd78084270b190d4916cd0 | Ruby | philjdelong/pets_and_customers | /lib/groomer.rb | UTF-8 | 640 | 3.46875 | 3 | [] | no_license | class Groomer
attr_reader :name, :customers
def initialize(groomer_info)
@name = groomer_info[:name]
@customers = []
end
def add_customer(customer_info)
@customers << customer_info
end
def customers_with_balance
with_balance = @customers.find_all do |customer|
customer.outstanding_b... | true |
b9bbfe4f35af4e0132a7b6cb3d108d3a6470e07e | Ruby | ekemi/cartoon-collections-onl01-seng-ft-012120 | /cartoon_collections.rb | UTF-8 | 644 | 3.53125 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves (array)# code an argument here
# Your code here
array.each_with_index{ |name,position| puts"#{position + 1}. #{name}"}
end
def summon_captain_planet (planeteer)# code an argument here
# Your code here
planeteer.map{|cap| (cap << "!").capitalize }
end
def long_planeteer_calls (array)... | true |
69722c21af8a96eb18ec25166ca8c3d99d2416f3 | Ruby | Ian-n2/homework_wk2_day1 | /homework_part_c.rb | UTF-8 | 387 | 2.890625 | 3 | [] | no_license | class Library
attr_accessor :title, :rental_details,
:student_name, :date
def initialize(input_book)
@Book = input_book
# [{
# title: = input_book,
# rental_details: = {
# student_name: = input_student,
# date: = input_date
# }
# }]
end
def book_into
if book_title =... | true |
7da20b95e79823c7cf456af174445e9952e0c92f | Ruby | fontcuberta/Ironhack-Week-1 | /Day-2/Exercises/Blog.rb | UTF-8 | 2,605 | 3.84375 | 4 | [] | no_license | require "date"
require "io/console"
class Blog
def initialize
@posts = []
@total_pages = @posts.size / 3
@page = 1
end
def add_post post
@posts << post
@total_pages = @posts.size / 3
end
def publish_front_page
posts_to_show = create_front_page
posts_to_show.each do |post|
... | true |
ff22d9b7b778cab4446d11cceccc292207946143 | Ruby | imhimanshuk/Training | /ruby/Program/sumoddno.rb | UTF-8 | 207 | 3.484375 | 3 | [] | no_license | class Sum
def sum()
puts "Enter the number"
@no = gets.to_i
@sum = 0
while(@no!=0)
@a=@no%10
if(@a%2!=0)
@sum=@sum+@a
end
@no=@no/10
end
puts " Sum of odd numbers is #{@sum}"
end
end
obj=Sum.new
obj.sum()
| true |
30003c3118f235108ca22718aa16d4e8e390dad4 | Ruby | johnisom/ruby-challenge-problems | /medium_1/grade_school.rb | UTF-8 | 303 | 3.53125 | 4 | [] | no_license | # frozen_string_literal: true
# school class
class School
def initialize
@roster = Hash.new { |hash, key| hash[key] = [] }
end
def add(name, grade)
@roster[grade] << name
end
def to_h
@roster.sort.to_h.transform_values(&:sort)
end
def grade(num)
@roster[num]
end
end
| true |
6df79931ce07203ea5d598c3006b2dce2dc17213 | Ruby | SuzHarrison/TaskListRails | /app/controllers/tasks_controller.rb | UTF-8 | 1,857 | 2.5625 | 3 | [] | no_license | class TasksController < ApplicationController
def index
@tasks = Task.order(id: :asc)
end
def show
@task = Task.find(params[:id])
render :show
end
def new
@task = Task.new
@all_people = Person.all
end
def create #COMMON PATTERN FOR CREATE
# check_hash = task_create_params[:task]... | true |
46d8285f16b295669cb69d08361738b1f0d9a354 | Ruby | jcramm/recordstore-inventory-manager | /lib/search.rb | UTF-8 | 2,231 | 3.015625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require './lib/models/album'
require './lib/models/artist'
class Search
VALID_TERMS_MAPPING = {
'artist' => {
'class' => Models::Artist,
'attribute' => 'name',
'sort_by' => 'artist_name',
'asc' => 1
},
'album' => {
'class' => Models::Album,
... | true |
e11b78db68887909d60fa6c228e4b661755fcc16 | Ruby | DouglasAllen/code-Metaprogramming_Ruby | /raw-code/PART_II_Metaprogramming_in_Rails/gems/actionpack-4.0.0/lib/action_view/helpers/tags/check_box.rb | UTF-8 | 2,277 | 2.640625 | 3 | [
"MIT"
] | permissive | #---
# Excerpted from "Metaprogramming Ruby",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http:/... | true |
ef0591509b832cc1095e5885014bfb4565db4fd6 | Ruby | LongTran415/phase-0-tracks | /ruby/santa.rb | UTF-8 | 3,380 | 3.828125 | 4 | [] | no_license |
class Santa
attr_reader :name, :ice_cream
attr_accessor :name, :ice_cream
def initialize (gender, ethnicity, hair_color, age, ice_cream, name)
puts "Initializing Santa instance ..."
@gender = gender
@ethnicity = ethnicity
@hair_color = hair_color
@age = age
@ice_cream = ice_cream
... | true |
b6a34d5cf6974d7f7e53333b9bf7eaa8c086ca87 | Ruby | portugol/decode | /Algoritmos Traduzidos/Ruby/Algoritmos_Filipe_Farinha/01.rb | UTF-8 | 109 | 3 | 3 | [] | no_license | #programa que imprime um triangulo no ecra
for i in 1..5
for j in 1..i
print "*"
end
print "\n"
end | true |
7b97c3a74be54a48f0a7a60b55d696604986b651 | Ruby | iheartkode/LearningRubyCode | /Hashes.rb | UTF-8 | 699 | 3.875 | 4 | [] | no_license | # Practicing hashes, temporary solution storing key, values.
# Mark Howard 07/17/2014
#Learning Ruby
# Method that does the work.
def insert_record
# Empty hash to store passwords in.
passwords = {}
# Loop to keep asking for sites and passwords.
while true
# Ask user for info.
puts "Enter the site name... | true |
09fd3bc6f8907a50d2e8a7cd030feacf02068c59 | Ruby | redfolgersGA/code_gym | /u3/d04/rails/u3_skully_rulez/config/routes.rb | UTF-8 | 1,864 | 2.875 | 3 | [] | no_license | Rails.application.routes.draw do
# root to: is like doing app.get("/") in Javascript
root to: "articles#index"
# we can do everything down there with JUST ONE, yes one! line of code
# this is an expression not a method that creates these routes
# :article :dogs are symbols and the only: is a hash
resources :article... | true |
130cd61d0a35873bf640ab2546562e5ccc633bc9 | Ruby | hone/parallel_specs | /lib/parallel_tests.rb | UTF-8 | 3,235 | 2.734375 | 3 | [
"LicenseRef-scancode-public-domain"
] | permissive | require 'parallel'
class ParallelTests
# parallel:spec[2,controller] <-> parallel:spec[controller]
def self.parse_test_args(args)
num_processes = Parallel.processor_count
if args[:count].to_s =~ /^\d*$/ # number or empty
num_processes = args[:count] unless args[:count].to_s.empty?
prefix = args... | true |
71e333b5ee34324e2f6441dc9bc6c8ce4ffdc900 | Ruby | Jbern16/trend_font | /app/services/google_font_service.rb | UTF-8 | 614 | 2.640625 | 3 | [] | no_license | class GoogleFontService
def initialize
@connection = Faraday.new(url: "https://www.googleapis.com")
end
def get_fonts(sort_param)
@connection.get do |req|
req.url '/webfonts/v1/webfonts'
req.params['key'] = ENV['GOOGLE_FONT_KEY']
req.params['sort'] = sort_param
end
end
def tre... | true |
29f7264afe49c92adf39284c4ed79a55e26dfcaf | Ruby | ben-amor/hangman | /lib/game_status_calculator.rb | UTF-8 | 310 | 2.921875 | 3 | [] | no_license |
class GameStatusCalculator
def calculate_game_status(game_state)
case
when game_state.lives_remaining == 0
GameState::LOST
when (game_state.current_word.chars - game_state.characters_guessed).empty?
GameState::WON
else
GameState::IN_PROGRESS
end
end
end | true |
d0f31474ce856d35a5e5f204bb4faf0c24e4619b | Ruby | jonathongardner/slots-jwt | /test/dummy/test/models/generic_user_test.rb | UTF-8 | 4,289 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'slots_test'
class GenericUserTest < SlotsTest
test "should find user for authentication" do
user = generic_users(:some_great_generic_user)
assert_equal user, GenericUser.find_for_authentication(user.email), 'Should find_for_authentication user with correct email'
as... | true |
1dc8595421f454aa7b05cc393108f8a4d34914c9 | Ruby | grzegorzl1/przerwa_tygodniowa | /samogloski.rb | UTF-8 | 99 | 3.5625 | 4 | [] | no_license | def vowel_count(string)
string.count'aeiouy'
end
vow = vowel_count("baaaak, baaoiuyr")
puts vow
| true |
55818faeadd7f62394d5158b8de3b0dc72e7a6ff | Ruby | CepCap/intern | /work/redefarr/redefarr.rb | UTF-8 | 1,758 | 3.78125 | 4 | [] | no_license | class MyArray
attr_accessor :init_arr
def initialize(init_array)
@init_arr = init_array
end
def my_length
init_arr.each do |el|
@count = 0 unless @count
@count += 1
end
@count
end
def my_count(value)
counting = 0
init_arr.each do |el|
counting += 1 if el == value... | true |
3d00286b83a24c3740e43ddc4a68519f64cf6e01 | Ruby | rhivent/ruby_code_N_book | /book-of-ruby/ch17/threads1.rb | UTF-8 | 514 | 3.75 | 4 | [] | no_license | # The Book of Ruby - http://www.sapphiresteel.com
# This is a simple threading example which, however,
# doesn't work as anticipated!
words = ["hello", "world", "goodbye", "mars" ]
numbers = [1,2,3,4,5,6,7,8,9,10]
startTime = Time.new
puts( "Start: %10.9f" % startTime )
Thread.new{
words.each{ |word| puts( word )... | true |
dedda01f7c99e11fe1fbdea825307da113849b32 | Ruby | posgarou/whatsfordinner | /server/lib/extensions/float.rb | UTF-8 | 177 | 3.015625 | 3 | [] | no_license | class Float
# E.g., 2.5 => 2.5 and 1.0 => 1
#
# From the venerable Yehuda Katz: http://stackoverflow.com/a/1077648
def prettify
to_i == self ? to_i : self
end
end
| true |
e7f64b912a0a61ed2aef0446bc39c4cb4c16f0c6 | Ruby | helenaalinder/baxapplikation | /app/models/product.rb | UTF-8 | 562 | 2.59375 | 3 | [] | no_license | class Product < ApplicationRecord
validates :name, presence: true
has_many :purchases
has_many :orders, through: :order_items
has_many :order_items, inverse_of: :product
def product_price
if (OrderItem.where(product: self).sum(:quantity) > 0)
OrderItem.where(product: self).sum(:price) / OrderItem.... | true |
6cebab5e5e06efa8cccd28ee2a7c14bd13215555 | Ruby | sh1okoh/competitive_prog | /ABC/ABC166/problemA.rb | UTF-8 | 98 | 3.265625 | 3 | [] | no_license | def solve
s = gets.chomp
if s == 'ABC'
print 'ARC'
else
print 'ABC'
end
end
solve
| true |
6d12d46c52069261dd5c1069083e72fe9cc62774 | Ruby | Pwako11/operators-online-web-prework | /lib/operations.rb | UTF-8 | 476 | 3.03125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def unsafe?(speed)
#if speed is greater than 60
if Speed % > 60
returns "true" (FAILED - 1)
end
#if speed is less than 60
if Speed % < 40
returns "true"
end
if Speed % >=40 or <= 60
Returns "false"
end
end
Def not_safe?(speed)
#if speed is greater than 60
Speed = 60
Speed > 5... | true |
cbe4ebaeda8be1e40bbf0b05e0176d1bbf00fa47 | Ruby | pombredanne/ruby-sslyze | /lib/sslyze/certificate/extensions/x509v3_basic_constraints.rb | UTF-8 | 1,328 | 2.75 | 3 | [
"MIT"
] | permissive | require 'sslyze/certificate/extensions/extension'
module SSLyze
class Certificate
class Extensions
#
# Represents the `<X509v3BasicConstraints>` XML element.
#
class X509v3BasicConstraints < Extension
#
# Specifies whether the `critical` constraint was specified.
... | true |
825bfc9ed5fd4c5c45b40c0e5bc74cc4e373877e | Ruby | Sammyfrw/Metis-Bootcamp | /Week-6/Week 6 Friday Notes.rb | UTF-8 | 1,657 | 3.140625 | 3 | [] | no_license | # # Rack is used by Rails, Sinatra, etc, it is also used in many gems such as Monban, authentication based gems and documentation, etc.
# # What does it do? It handles incoming HTTP requests.
# HTTP: Asks a server to return resource(GET), create(POST) or others (PATCH,PUT, DELETE, etc).
# Requests are sent to ... | true |
235c68b5b68867d8f860d1138ff87f289c73f628 | Ruby | verg/forecast | /lib/forecast.rb | UTF-8 | 1,625 | 3.1875 | 3 | [] | no_license | require_relative 'forecast/forecast_client'
require_relative 'forecast/forecast_result'
require_relative 'forecast/minutely_result'
require_relative 'forecast/location'
require_relative 'forecast/time_range'
require 'yaml'
module Forecast
class Forecast
CONFIG = YAML.load_file('config.yml')
Lat = CONFIG['la... | true |
249522a412160fb78419b7419af231d744786cb4 | Ruby | hdgarrood/tank-game | /lib/tankgame/game_objects/barrel.rb | UTF-8 | 1,729 | 2.890625 | 3 | [] | no_license | require 'tankgame/geometry/angle'
module TankGame
module GameObjects
# to be included in Player
module Barrel
include Geometry
def initialize_barrel
@barrel_angle = Angle.new(0)
@barrel_sprite = {
:left => Resources.sprites[:barrel_left],
:right => Resources.s... | true |
b7d4f2b0a5910c68307f698fcc31c1fda466e6ea | Ruby | jralorro93/emoticon-translator-prework | /lib/translator.rb | UTF-8 | 812 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "yaml"
require 'pry'
def load_library(path)
emoticons = YAML.load_file(path)
new_hash = {}
emoticons.each do |emotion, array|
new_hash["get_meaning"] ||= {}
new_hash["get_emoticon"] ||= {}
new_hash["get_meaning"][array.last] ||= emotion
new_hash["get_emoticon"][array.first] ||= array.l... | true |
9b95298577e87c52eadc8648d3ba07d0e2f1dc3b | Ruby | quetzalsa/sample_app3 | /example_user.rb | UTF-8 | 379 | 3.25 | 3 | [] | no_license | class User
attr_accessor :firstn, :lastn, :email
def initialize(attributes = {})
@firstn = attributes[:firstn]
@lastn = attributes[:lastn]
@email = attributes[:email]
end
def full_name
puts @firstn + " " + @lastn + @email
end
def formatted_email
full_name(@firstn, @lastn)
end
de... | true |
a734c7072e16347b020a0f45f4b7e6f45a155b04 | Ruby | LALOPSB/Exercise-PrimeFactors-Ruby | /lib/primeFactorsCalculator.rb | UTF-8 | 310 | 3.515625 | 4 | [] | no_license | class PrimeFactorsCalculator
def calculate_prime_factors (number)
prime_array = []
p = 2
if number < 2
return prime_array
end
while p <= number
if number % p == 0
prime_array.push(p)
number/=p
end
p +=1
end
return prime_array
end
end
| true |
30e36bcedbd3e0d36cc5f05dda994cce5df303ac | Ruby | olliefw/nbody | /Planets.rb | UTF-8 | 1,286 | 3.234375 | 3 | [] | no_license | require "gosu"
class Planets
attr_reader :x_pos, :y_pos, :x_vel, :y_vel, :mass, :force_x, :force_y
def initialize (x_pos, y_pos, x_vel, y_vel, mass, planet_image, sizeu)
@x_pos = x_pos
@y_pos = y_pos
@x_vel = x_vel
@y_vel = y_vel
@mass = mass
@planet_image = planet_image
@force_x = 0
... | true |
b6ab5f757e267d68eb3c81c7299b5ddd0441137d | Ruby | eddpeterson/RSpecDemo | /implicit_spec.rb | UTF-8 | 446 | 2.671875 | 3 | [] | no_license | describe 42 do
it { should be_even }
it { should_not be_zero }
end
describe Array do
it { should be_empty }
it { should have(0).items }
end
describe [1, 2, 3, 3] do
its(:size) { should == 4 }
its("uniq.size") { should == 3 }
end
# Explicit subject
describe "An array containint 1, 2, 3, 3" do
subject ... | true |
cfbf846b1b1dc8ca5b8b99a764dd13a40e2d2bff | Ruby | briant1/world-time-too | /app/services/country_service.rb | UTF-8 | 1,019 | 2.75 | 3 | [] | no_license | require 'wikipedia'
class CountryService
def initialize
end
def get_or_create_country(data)
country = Country.find_by_name(data[:country_code])
if !country
wikipedia_url = Wikipedia.find(data[:country_code]).fullurl
country = Country.create(name: data[:country_code], wikipedia_url: wikipedia_u... | true |
5f98a15ec361f85416c3014d23a15ed380ed7ffb | Ruby | hnpbqy/LAB | /ruby/practic/1/helloworld.rb | UTF-8 | 68 | 2.53125 | 3 | [] | no_license | # Ruby Sample program from www.sapphiresteel.com
puts 'Hello world' | true |
a79e46c2a40f4309117c886d3e942aa8e99a600d | Ruby | synmal/wallet | /app/models/debit.rb | UTF-8 | 643 | 2.515625 | 3 | [] | no_license | class Debit < WalletTransaction
validate :only_from_debiter_wallet, :sufficient_balance
before_validation :debit_to_owner
after_create :deduct_from_wallet
private
def only_from_debiter_wallet
debiter = transact_to
unless transact_from.is_a?(Wallet) && transact_from.owner.id == debiter.id
error... | true |
02b3b820e2a54517dfc14ba8f99f05dfb6284896 | Ruby | jimivyas/learn_ruby | /08_timer/timer.rb | UTF-8 | 808 | 3.3125 | 3 | [] | no_license | class Timer
attr_accessor :seconds
def initialize(seconds=0)
@seconds = seconds
end
def time_string
hours = (@seconds / (60 * 60)).to_i
minutes = ((@seconds - hours * 60 * 60) / 60).to_i
seconds = (@seconds - hours * 60 * 60 - minutes * 60)
'%02d:%02d:%02d' % [hours, minutes, seconds]
end... | true |
78732acc3dc4a0702fea2c45b2ed46673b20ab23 | Ruby | hatsu38/atcoder-ruby | /abc303/b.rb | UTF-8 | 1,632 | 3.515625 | 4 | [] | no_license | # frozen_string_literal: true
### 例
# 1,2,…,N と番号づけられた
# N 人が
# M 回、一列に並んで集合写真を撮りました。
# i 番目の撮影で左から
# j 番目に並んだ人の番号は
# a
# i,j
#
# です。
# ある二人組は
# M 回の撮影で一度も連続して並ばなかった場合、不仲である可能性があります。
# 不仲である可能性がある二人組の個数を求めてください。なお、人
# x と人
# y からなる二人組と人
# y と人
# x からなる二人組は区別しません。
# input
# RNBQKBNR
# output
# Yes
# 長さ
# 8 の文字... | true |
5e4d6d872c50bef437d1a6b3507579c1b22f5139 | Ruby | mihaibaboi/tournaments | /app.rb | UTF-8 | 7,841 | 2.515625 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader' if development?
require 'json'
require 'data_mapper'
require File.dirname(__FILE__) + '/models/model.rb'
STATUS_SUCCESS = 'success'
STATUS_FAILED = 'failed'
STATUS_CREATED = 'created'
before do
if request.post? || request.put?
request.body.rewind
@request_payload = ... | true |
7bc3a42d8e18b38bd598dfed76b8eb19d7fa6287 | Ruby | Temceo/udemy | /section-18/parse_data.rb | UTF-8 | 786 | 2.890625 | 3 | [] | no_license | system 'cls'
require 'rubygems'
require 'httparty'
class ApiGetter
include HTTParty
base_uri 'https://udemy-api.herokuapp.com'
def rails_users
self.class.get('/users.json')
end
end
data = ApiGetter.new()
data.rails_users.each do |user|
raw_time = "#{user['created_at']} "
parse_t... | true |
0ea10b021c7a48b0e737ca71388e10cc94665ac2 | Ruby | morinoko/well-grounded-rubyist | /ch5-self-scope/class-variables-1.rb | UTF-8 | 1,086 | 4 | 4 | [] | no_license | # A simple way to use class variables, BUT should be used with caution,
# they are class-hierarchy scoped (no new scope when inherited)
class Car
@@makes = []
@@cars = {}
@@total_count = 0
attr_reader :make
def self.total_count
@@total_count
end
def self.add_make(make)
un... | true |
0810a32313906372b0a1861ce523a4e6d7361e59 | Ruby | leospaula/evotto-test | /lib/csv_parser.rb | UTF-8 | 330 | 3 | 3 | [] | no_license | require 'csv'
class CSVParser
attr_reader :data
def initialize(source)
@data = []
call(source)
self
end
def call(source)
CSV.read(source, { header_converters: :symbol, headers: true }).each do |row|
@data.push({name: row[0], age: row[1].to_i, project_count: row[2].to_i, total_value: row[3].to_i})
en... | true |
4fffeeb71c735a3285396bb9f947de653d1b390d | Ruby | pstivers3/rubylearn | /pippen/1_arrays_and_hashes/1_duplicate_collections/1_validates_constructor_arguments.rb | UTF-8 | 667 | 3.546875 | 4 | [] | no_license | #!/usr/bin/env ruby
class ValidatesConstructorArguments
def initialize(potentially_invalid_array)
@potentially_invalid_array = potentially_invalid_array.dup
raise ArgumentError.new("The passed array is invalid") unless array_valid?
end
def transform
potentially_invalid_array.map { |x| x.upcase }.joi... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.