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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
bd768b705bbf0a3095ba22e85b52811164d35484 | Ruby | dmitrinesterenko/fast_fibonacci_c_extension | /calculate_fibonacci.rb | UTF-8 | 445 | 3.40625 | 3 | [
"MIT"
] | permissive | require_relative 'lib/mymath_fast_fibonacci'
sequence = 40
start_time = Time.now
0.upto(sequence) do |i|
n = MyMath::FastFibonacci.compute i
end
end_time = Time.now
puts "C extension #{end_time-start_time}"
def fibonacci(n)
#puts n
if n == 0
0
elsif n==1
1
else
fibonacci(n-1)+fibonacci(n-2)
end
end
sta... | true |
64083db32d745701fe3cdc6ebb9d2eb4852805c2 | Ruby | ntl/mudrat-projector | /test/integrations/mortgage_test.rb | UTF-8 | 2,753 | 2.65625 | 3 | [] | no_license | require 'test_helper'
class MortgageTest < Minitest::Test
def setup
@loan_amount = 200_000
@home_value = 250_000
@down_payment = @home_value - @loan_amount
@interest_rate = 5.0.to_d
@property_tax_rate = 1.25.to_d
@loan_term = 30
@start_date = jan_1_20... | true |
529fdf3ce8087c51ff8f784656b08e4cfe748be3 | Ruby | sam2500/codesignal-my-solutions | /ruby/Arcade/Intro-52-longestWord/longestWord.rb | UTF-8 | 357 | 3.40625 | 3 | [] | no_license | def longestWord(text)
arr = text.split('')
valid = 'abcdefghijklmnopqrstuvwxyz '
newtext = ''
for i in (0...arr.size)
if valid.include? arr[i].downcase
newtext += arr[i]
else
newtext += ' '
end
end
arr = newtext.split(' ')
maxWord = ''
for i in (0...arr.size)
maxWord = arr[i] if maxWord.length < a... | true |
7da1d4157c6121de26547a30cca0fdf77162c78e | Ruby | pedroteixeira/ruote-transition | /lib/openwfe/trans/compiler.rb | UTF-8 | 5,646 | 2.578125 | 3 | [
"BSD-3-Clause"
] | permissive | #
#--
# Copyright (c) 2008, John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# . Redistributions of source code must retain the above copyright notice, this
# list of... | true |
27ef91d62d34a24b991bc0ad00db849758b183d6 | Ruby | kzfm1024/misc | /books/computationbook/the_meaning_of_programs/denotational/number.rb | UTF-8 | 220 | 2.71875 | 3 | [
"CC0-1.0"
] | permissive | #require 'execjs/json'
require_relative '../syntax/number'
class Number
def to_ruby
"-> e { #{value.inspect} }"
end
# def to_javascript
# "function (e) { return #{ExecJS::JSON.encode(value)}; }"
# end
end
| true |
9d65c410ae3a3528cca61dae027e2cce9515867d | Ruby | stmichael/bodyguard | /spec/postcondition_spec.rb | UTF-8 | 594 | 2.84375 | 3 | [] | no_license | describe "Contractor" do
describe "postconditioned methods" do
before do
@object = Contractor::Calculator.new
end
it "has a postconditioned method" do
@object.has_postcondition(:sqrt).should be_true
end
it "succeeds if the postcondition is valid" do
expect{@object.square(5)}.to_n... | true |
bdb3f22a6556579d8953e23642487d1adf6e0e88 | Ruby | Froks15/ruby-telegram-bot | /app/helpers/emoji_helper.rb | UTF-8 | 807 | 3.03125 | 3 | [] | no_license | module EmojiHelper
def create_flag_emoji(country_code: nil)
begin
country_code = country_code.upcase
flagOffset = 0x1F1E6
asciiOffset = 0x41
firstChar = country_code[0].ord - asciiOffset + flagOffset
secondChar = country_code[1].ord - asciiOffset +... | true |
37a2580f2e1a80f6d063fb0a33670df63e367a42 | Ruby | simonluppescu/algorithms | /ruby/knapsack.rb | UTF-8 | 1,240 | 4.125 | 4 | [] | no_license |
class Packer
def initialize(values, weights)
@values = values
@weights = weights
raise 'dumb' if @values.size != @weights.size
@memos = {}
end
def knapsack(capacity)
pack_bag(@values.size - 1, capacity)
end
private
def pack_bag(index, capacity)
return 0 if index < 0 || capacit... | true |
f07b574de75570f597afeb75b6633ec82fd84386 | Ruby | Rumisbern/MakeJapaneseChars | /csv_reader.rb | UTF-8 | 1,515 | 3.1875 | 3 | [
"MIT"
] | permissive | # coding: utf-8
require 'csv'
CSV_FILES_DIR = File.expand_path("../csv",__FILE__)
# csvディレクトリから全てのファイル名とパスを取得
def all_file_path_hash
return Hash[*(Dir.glob("#{CSV_FILES_DIR}/*.csv").map{|file_path|
[ File.basename(file_path,".*"), file_path ]
}.flatten)]
end
# ファイル名の配列からcsvディレクトリに... | true |
946450fc2ea460b5d3ec3276d1856a1056e9d73d | Ruby | ameet01/W2D2 | /Chess/player.rb | UTF-8 | 752 | 3.4375 | 3 | [] | no_license | require_relative "cursor"
require_relative "display"
class Player
def initialize(name, color, display)
@name = name
@color = color
@display = display
end
def play_turn
@display.render
puts "Pick the piece you want to move"
first_pos = @display.cursor.get_input
system("clear")
unt... | true |
35d6f67cdbc724502f0fd7c4fd4b2c2968ab46d3 | Ruby | 3t8U/library_hell | /lib/author.rb | UTF-8 | 2,124 | 2.90625 | 3 | [
"MIT"
] | permissive | class Author
attr_reader :id, :name
def initialize(attributes)
@name = attributes.fetch(:name)
@id = attributes.fetch(:id)
end
def ==(author_to_compare)
@id == author_to_compare.id && @name == author_to_compare.name
end
def self.clean(string)
(string.include?("'")) ? string.gsub("'", "''... | true |
5856f4ea2109ff3c61483e99484f6fed2dbe6fc9 | Ruby | gsQuizMoku/programmer-brain | /20161221/q2-kanpou0108-ruby.rb | UTF-8 | 497 | 3.40625 | 3 | [] | no_license | # OPER = ["+", "-", "*", "/", ""]
OPER = ["*", ""]
i = 1000
while i < 10000
c = i.to_s
2.times do |j|
2.times do |k|
2.times do |l|
val = c[3] + OPER[j] + c[2] + OPER[k] + c[1] + OPER[l] + c[0]
if (val.length > 4)
val.tr!("08","8")
val.tr!("09","9")
begin
... | true |
cb1a6aeef72b030707cee26bf656d22b791488c6 | Ruby | hmistry/petmatch | /app/controllers/imports_controller.rb | UTF-8 | 1,035 | 2.65625 | 3 | [] | no_license | class ImportsController < ApplicationController
def index
@import = Import.new
end
def create
zip = Import.new(import_params)
if zip.valid?
flash[:notice] = import_shelters_and_pets
else
flash[:error] = "Invalid Zipcode"
end
redirect_to imports_path
end
private
def ... | true |
2041b973f7049d6a7f140b59961385ff51c48653 | Ruby | darthschmoo/fun_with_files | /lib/fun_with/files/file_path.rb | UTF-8 | 22,470 | 2.9375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module FunWith
module Files
class FilePath < Pathname
SUCC_DIGIT_COUNT = 6
def initialize( *args, &block )
super( File.join( *(args.map(&:to_s) ) ) )
_yield_and_return( self, &block )
end
attr_accessor :path
# If block given, temporary directory is deleted at... | true |
b33cd2e6dd43114f25b08d7492082e5e3e8bba20 | Ruby | underhilllabs/project-euler-in-lisp | /product_grid.rb | UTF-8 | 2,688 | 3.265625 | 3 | [] | no_license | class ProductGrid
MAX = 20
def initialize
@grid = read_in_grid("11.txt")
@max_prod = 1
end
def read_in_grid(fname)
grid = Array.new(20) { Array.new(20, 0) }
File.open(fname, "r") do |f|
0.upto(MAX-1).each do |r|
f.readline.split(" ").each_with_index do |num, col|
grid[r]... | true |
c2f00a81aa437e2df1c8142739a12585e6961d79 | Ruby | ghounakey/School | /cs214/labs/04/script.ruby | UTF-8 | 1,912 | 3.484375 | 3 | [] | no_license | Script started on Thu 21 Feb 2019 04:27:22 PM EST
ajs244@gold27:~/cs214/labs/04$ cat logTable.rb
#! /usr/bin/ruby
# logTable.rb displays a table of logarithms
#
# Begun by: Prof. Adams, for CS 214 at Calvin College.
# Completed by: Advait Scaria
# Date; 02/21/2019
#
# Input: The start, stop and increment value... | true |
0932243f810a1c77e4e41519580dc3e2e6a07f66 | Ruby | SusanSorensen/kuality-coeus | /features/step_definitions/users.rb | UTF-8 | 1,538 | 3.28125 | 3 | [] | no_license | # Note the difference between the following three
# step definitions...
# This step definition
# 1) Assumes that the user already exists in the system
# 2) Assumes the user object does not exist, so it creates it, sticking it into
# a class instance variable based on the username
# 3) Logs that user in (if they're ... | true |
775c841a977fcf5af960f1849a2754c51c2fef09 | Ruby | thperchi/THP_Morpion | /lib/game.rb | UTF-8 | 1,541 | 3.578125 | 4 | [] | no_license | require_relative 'game'
require_relative 'player'
require_relative 'show'
require_relative 'board'
require_relative 'boardcase'
class Game
attr_accessor :status, :board, :arr_player, :curr_board, :p1, :p2
def initialize
print "Joueur 1, quel est votre pseudo ?\n> "
@p1 = Player.new(gets.chomp, "X")
... | true |
62990b28dfb7075f0f49e1e5a73f1db12cfcecd9 | Ruby | CodeOfficer/presentation-materials | /2008-04-18-design-patterns/1st presentation/factory/factory_4_defunkt.rb | UTF-8 | 1,063 | 3.21875 | 3 | [] | no_license | # example provided by Josh Goebel (defunkt) on irc.freenode.net
# number 58 in the who's who list of the working wth rails website
# creator of Pastie and Beast (co-written with Russ Olsen, author of DPR)
# woot!
class Characters
attr_accessor :value
def self.matcher(regexp = nil)
@matcher ||= regexp
end
... | true |
ad7d63899f88d1d1fcb385ead5af6f14b719f577 | Ruby | stormbrew/channel9 | /environments/ruby/environment/kernel/delta/time.rb | UTF-8 | 626 | 2.9375 | 3 | [
"MIT"
] | permissive | class Time
include Comparable
def initialize(ts)
@ts = ts
end
def self.at(ts)
i = allocate
i.initialize(ts)
i
end
def self.new
i = allocate
i.initialize($__c9_ffi_time_now.call(nil))
i
end
def self.now
new
end
def to_i
@ts.to_i
end
def to_f
@ts.to_f
... | true |
d99a8a5779cd163bd099ec2da727d7079d549279 | Ruby | Victorcorcos/Algoritmos-e-Grafos | /ApagandoEGanhando/erasing_and_winning.rb | UTF-8 | 2,836 | 3.875 | 4 | [] | no_license | require 'scanf'
# Solves the Silvio Santos problem :D
class EraseAndWin
def initialize(total_digits, digits_to_erase, entry)
@total_digits = total_digits
@digits_to_erase = digits_to_erase
@entry = entry.to_s
@top = -1
@position = 0
@output = ''
end
def calculate
while @digits_to_era... | true |
1eeb63f36c78b1985b6201e4e36010e9f51cf596 | Ruby | mjm/pressy | /lib/pressy/action/push.rb | UTF-8 | 820 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'pressy/changeset'
class Pressy::Action::Push
def initialize(params)
@local_posts = params.fetch(:local)
@server_posts = params.fetch(:server)
end
def has_changes?
changeset.has_changes?
end
def changeset
@changeset ||= build_changeset
end
private
def build_changeset
cha... | true |
ede8e79207997e9f867d25927f8befaab403bec3 | Ruby | thimios/supermarket-challenge | /app/item.rb | UTF-8 | 193 | 2.890625 | 3 | [] | no_license | # encoding: utf-8
class Item
attr_accessor :name, :unit_price, :unit
def initialize(name, unit_price, unit=:unity)
@name = name
@unit_price = unit_price
@unit = unit
end
end | true |
f15f529b7ad7a22b3bc744f17960a163607d8904 | Ruby | nu7hatch/grapcha | /lib/grapcha/gravatar.rb | UTF-8 | 644 | 2.578125 | 3 | [] | no_license | module Grapcha
class Gravatar
def self.service_url
"http://gravatar.com"
end
def self.http
Faraday.new(service_url) do |f|
f.request :url_encoded
f.adapter :net_http
end
end
def self.hash(email)
Digest::MD5.hexdigest(email)
end
def self.find(email... | true |
4c54046df17906450e2fad0f040ed13cb26065c2 | Ruby | realityforge/knife-cookbook-doc | /fixture/resources/default.rb | UTF-8 | 302 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | #<
# This resource is awesome.
#
# @action stuff Does awesome things.
#>
default_action :stuff
#<> @attribute my_attribute This is an attribute.
attribute :my_attribute, default: 'a default value'
#<> @property my_property This is a property.
property :my_property, default: 'another default value'
| true |
8af747a88105be51c3ece20a991418f074584b49 | Ruby | maxlinc/stillmaintained | /lib/github_importer.rb | UTF-8 | 794 | 2.53125 | 3 | [] | no_license | require 'gh'
class GithubImporter
def initialize user
@github = GH::DefaultStack.build token: user.token
@user = user
end
def update_user_and_projects
projects = update_repos @github['user/repos']
organizations = @github['user/orgs'].map{|organization| organization['login'] }
organizations... | true |
c10d58b4888f829588742adcc6cdefcfa68a989b | Ruby | MaleehaBhuiyan/ruby-oo-relationships-practice-gym-membership-exercise-nyc01-seng-ft-060120 | /lib/lifter.rb | UTF-8 | 704 | 3.15625 | 3 | [] | no_license | class Lifter
attr_reader :name, :lift_total
@@all = []
def initialize(name, lift_total)
@name = name
@lift_total = lift_total
@@all << self
end
def self.all
@@all
end
def memberships
Membership.all.select {|membership| membership == self}
end
def gyms
membership.selec... | true |
3020b187c1532f493406bf321bf982bf769e1f2b | Ruby | mpazcarvacho/Prueba_twitter | /app/models/tweet.rb | UTF-8 | 4,166 | 2.765625 | 3 | [] | no_license | class Tweet < ApplicationRecord
# after_save :hashtags no puede ser after_save para que se pase a la db
before_save :hashtags
validates :content, presence: true
belongs_to :user
has_many :likes, dependent: :destroy
has_many :retweets, dependent: :destroy
has_many :users_liked, :through => :likes, :source... | true |
bfbb76a2a76270aa2d9f572c5ef0f89fd66a9340 | Ruby | fikeda17/object_oriented_programming | /mars_rover.rb | UTF-8 | 1,241 | 4.03125 | 4 | [] | no_license | class Rover
attr_reader :x, :y, :direction
DIRECTION_VECTORS = {
N: [0,1],
W: [-1,0],
S: [0,-1],
E: [1,0]
}
def initialize(x, y, direction, width=5, height=5)
@x = x
@y = y
@direction = direction
@width, @height = width, height
end
def move
case @direction
when "N"
@y += 1
when "S"
... | true |
cfdbb8a325af00d4543ec8f9bbacd30a0cf926d3 | Ruby | mnmallea/tp-tadp-2c18 | /ruby/scripts/sumador.rb | UTF-8 | 728 | 3.546875 | 4 | [] | no_license | require_relative '../lib/metamodelo'
class Sumador
attr_accessor :numero
def initialize(un_numero = 0)
self.numero = un_numero
end
def aumentar_segun(x)
matches? x do
with(type(Integer), :numero) {aumentar_cantidad numero}
with(type(String), :string) {aumentar_cantidad(string.size)}
... | true |
ff79365588640622fac790cbcd852e583d05239e | Ruby | alu0100966589/tdd | /lib/TDD/sort.rb | UTF-8 | 891 | 3.40625 | 3 | [
"MIT"
] | permissive | # Open the Array class
class Array
# Returns the array sorted
# @return [Array] the array sorted
def sort_for
# Deep copy
r = Marshal.load(Marshal.dump(self))
for i in (0...r.length)
for j in (0...(r.length-i-1))
r[j], r[j+1] = r[j+1], r[j... | true |
aa590d398b3105cf4821467075103074c75cf9f6 | Ruby | pieflicker/CRM_app | /database.rb | UTF-8 | 332 | 2.6875 | 3 | [] | no_license |
require './contact'
class Database
@contacts = []
@id = 1000
def self.add_contact(contact)
contact.id = @id#1000 atm
@contacts << contact
@id += 1
end
def self.contacts
@contacts
end
end
contact = Contact.new("john", "smith", "stuff", "string4")
Database.add_contact(contact)
Database.co... | true |
b90e9bd618de943e2b378a689e576d1618a8fcf0 | Ruby | Wodnyan/Kogu | /backend/app/auth/authorize_api_request.rb | UTF-8 | 987 | 2.5625 | 3 | [] | no_license | class AuthorizeApiRequest
def initialize(headers = {})
@headers = headers
end
def call
{
user: user
}
end
private
def user
@user ||= User.where('id = ?', decoded_auth_token[:user_id]).select(select).first if decoded_auth_token
rescue ActiveRecord::RecordNotFound => e
raise(
... | true |
c0070f34e1881161ba44b79f722f096a410499e5 | Ruby | UncleMussels/Launch-School | /Exercises/101-109 - Small Problems/Easy 1/list_of_digits.rb | UTF-8 | 658 | 4.53125 | 5 | [] | no_license | # Write a method that takes one argument, a positive integer, and returns
# a list of the digits in the number.
# inputs: one positive integer
# outputs: returns list of each digit in the number
# conditions:
# questions: have to be in array form? or each char on a new line?
# examples:
# puts digit_list(12345) == [... | true |
501d1c1a8a8fd6f1aaddcb8a78479bbc7a94f936 | Ruby | cultureamp/cepa-health | /lib/cepa-health.rb | UTF-8 | 2,316 | 2.59375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # encoding: utf-8
# Copyright © 2013 Jon Williams. See LICENSE.txt for details.
require "cepa-health/engine"
module CepaHealth
attr_accessor :success
# Container that holds the result of the probe execution
class Result
attr_reader :records
def execute(block)
v = instance_exec(&block)
Arra... | true |
1f1db41ecce578ba2c4f3cb31f4e12993a5f4cc4 | Ruby | felixclack/teaching-vacancies | /spec/helpers/dates_helper_spec.rb | UTF-8 | 1,311 | 2.5625 | 3 | [
"MIT"
] | permissive | require "rails_helper"
RSpec.describe DatesHelper do
describe "#format_date" do
it "returns the date in the default format" do
expect(helper.format_date(Date.new(2017, 10, 7))).to eq "7 October 2017"
end
it "returns the date in the correct format, if one given" do
expect(helper.format_date(D... | true |
f8ccfc7b5eeecb7d06f358d7746845d64673b033 | Ruby | AgileInstitute/samples-ruby-rspec | /SuperSet/my_set_spec.rb | UTF-8 | 1,472 | 3.109375 | 3 | [] | no_license | require 'rspec'
require_relative 'my_set'
describe MySet do
before :each do
@set = MySet.new
end
it "should be instantiable" do
@set.should_not be_nil
end
it "should be empty by default" do
@set.should be_empty
end
it "should allow the addition of elements" do
@set.add 'a'
@set.sh... | true |
e35d31ccf18a0370eada755058e13c888ae93676 | Ruby | tyauvil/euler | /ruby/p73.rb | UTF-8 | 291 | 3.015625 | 3 | [] | no_license | #euler
#71
sum = 0
up_lim = {}
low_lim = {}
limit = 12_000
a = Time.now
1.upto (limit - 1) do |n|
(n + 1).upto limit do |d|
if n * 2 >= d or n * 3 <= d
next
end
if (n.gcd d) != 1
next
else
sum += 1
end
end
end
b = Time.now
puts b - a
puts sum
| true |
5b73cc5fff01301237d93f52855281c4ad9d5ed8 | Ruby | lulalala/email_domain_validator | /lib/email_domain_validator/whitelist.rb | UTF-8 | 245 | 2.765625 | 3 | [
"MIT"
] | permissive | class EmailDomainValidator::Whitelist
def initialize(app, whitelist = [])
@app = app
@whitelist = whitelist
end
def valid?(domain)
if @whitelist.include?(domain)
true
else
@app.valid?(domain)
end
end
end
| true |
ac7e412f45b5192365cafdd19f13487a91756332 | Ruby | indentlabs/dactyl | /app/services/metric_services/sentiment_service.rb | UTF-8 | 1,164 | 2.890625 | 3 | [] | no_license | class SentimentService
extend Service
def self.positive_words corpus
load_sentiment_defaults
corpus.unique_words.select { |word| @sentiment_analyzer.score(word) > 0.5 }.sort
end
def self.negative_words corpus
load_sentiment_defaults
corpus.unique_words.select { |word| @sentiment_analyzer.score... | true |
0d1d1a38be7476c82303da3719c7f58ed8b95053 | Ruby | aleks2414/perfil | /app/models/test.rb | UTF-8 | 2,102 | 2.65625 | 3 | [] | no_license | class Test < ActiveRecord::Base
before_save do
self.l1total = self.l11+self.l12+self.l13+self.l14
self.l1total = self.l1total.round(2)
self.l2total = self.l21+self.l22+self.l23+self.l24+self.l25+self.l26
self.l2total = self.l2total.round(2)
self.l3total = self.l31+self.l32+self.l33+self.l34
... | true |
234ce39d503b5ea30ec6fd1a9b0c1efa8ba83164 | Ruby | osbornebrook/MailChunk | /mailchunk.rb | UTF-8 | 4,879 | 2.625 | 3 | [] | no_license | #!/usr/bin/ruby
require 'socket'
require 'gserver'
require 'optparse'
require 'yaml'
args = {:smtp => {}}
optparse = OptionParser.new do|opts|
# Set a banner, displayed at the top
# of the help screen.
opts.banner = "Usage: mailchunk [CONF] recipient"
opts.on('-c', '--config FILE', 'Configuration file') d... | true |
7d63aee3179b48d60fd90dcf5c77e93bb3c68fde | Ruby | vikgilmuc/kata_potter | /my_first_kata_test.rb | UTF-8 | 858 | 2.953125 | 3 | [] | no_license | require "test/unit"
require_relative "./my_first_kata"
class TestPotter < Test::Unit::TestCase
def test_single_book_cost_8_eur
assert_equal 8, basket([1])
end
def test_two_books_5_per_cent_discount
assert_equal 15.2, basket([1,2])
end
def test_three_books_10_per_cent_discount
assert_equal 21.... | true |
344afd1f7d448e9e3b92a723af7ce4758f04aa70 | Ruby | malexander15/ruby_homework | /quiz/theodinprojectruby/learn_ruby_coursework/numbers/hours_in_year.rb | UTF-8 | 125 | 3.640625 | 4 | [] | no_license | # How many hours are in a year?
year_days = 365
day_hours = 24
print "There are ", year_days * day_hours, " hours in a year!" | true |
813c7a05c4e85563fa92d3015b44d996a0c94c35 | Ruby | jaymep/phase-0-tracks | /ruby/hamsters.rb | UTF-8 | 630 | 3.8125 | 4 | [] | no_license | puts("Name of hamster?")
hname = gets.chomp
puts("Volume level? (1-10)")
hvolume = gets.chomp
hvolume = hvolume.to_i
puts("Fur color?")
hcolor = gets.chomp
puts("Good for adoption? (Y/N)")
hadoption = gets.chomp
if hadoption == 'Y'
hadoption = TRUE
elsif hadoption == 'N'
hadoption = FALSE
else
ha... | true |
5807b042dfcb0cf021baf8d5dbed949219d47e06 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/space-age/dab0a6e3707a4c41993b0276eb3a0dc2.rb | UTF-8 | 653 | 3.5625 | 4 | [] | no_license | class SpaceAge
def initialize seconds
@seconds = seconds
end
def seconds
@seconds
end
def age_on_earth
(@seconds / 31_557_600.0)
end
def on_earth
age_on_earth.round(2)
end
def on_mercury
(age_on_earth / 0.2408467).round(2)
end
def on_venus
(age_on_earth / 0.61519726).r... | true |
ad9f8ae2c247acb8c66b174d7acdacacdabb1227 | Ruby | anthonymjimenez/ruby-enumerables-hash-practice-nyc-pigeon-organizer-lab-nyc01-seng-ft-091420 | /nyc_pigeon_organizer.rb | UTF-8 | 516 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def nyc_pigeon_organizer(data)
pigeons_by_name = {}
data.each do |key, value|
value.each do |nKey, nValue|
nKey = nKey.to_s
nValue.map { |e|
if !pigeons_by_name[e]
pigeons_by_name[e] = {key => [nKey]}
elsif pigeons_by_name[e][key]
pigeons_by_name[e] = {key => pige... | true |
cb46580c6d10489946963a1dbc8b757eb1bc546c | Ruby | silvaelton/boleto_bancario | /spec/boleto_bancario/core/real_spec.rb | UTF-8 | 3,177 | 2.5625 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'spec_helper'
module BoletoBancario
module Core
describe Real do
it_should_behave_like 'boleto bancario'
describe "on validations" do
it { should have_valid(:agencia).when('1', '12', '123', '1234') }
it { should_not have_valid(:agencia).when('12345', '123456... | true |
2e6b00ee0063aa8e3c3f21f86852fbf7f7d88729 | Ruby | uu59/jinro-public | /app/models/rule.rb | UTF-8 | 178 | 2.515625 | 3 | [] | no_license | class Rule
attr_reader :room
def initialize(room)
@room = room
end
def even_game_for_avoid_votes_count
room.options[:even_game_for_avoid_votes_count]
end
end
| true |
e6f71210b91ac175af4a6c3f5adfa02398ac074b | Ruby | RubyCamp/rc2017su_g6 | /lib/base/cp_static_box.rb | UTF-8 | 809 | 2.859375 | 3 | [] | no_license | class CPStaticBox < CPBase
def initialize(x, y, w, h, opt = {})
@x, @y = x, y
@width, @height = w, h
# 静的Bodyオブジェクト生成(重力の影響を受けないオブジェクト)
@body = CP::StaticBody.new
@body.p = CP::Vec2.new(0, 0)
# 頂点計算
verts = [
CP::Vec2.new(x, y), # 第1頂点(左上)
CP::Vec2.new(x, y + h), ... | true |
fcb51d9e207901f50d7e1a59abb4ee4247b55460 | Ruby | dpneumo/simplestate2 | /lib/simplestate/null_state.rb | UTF-8 | 750 | 2.8125 | 3 | [
"MIT"
] | permissive | class NullState
# Simplifies call via super to SimpleDelegator during StateHolder#new
# Avoid chicken and egg problem by mimicing rather than inheriting from State
attr_reader :master, :holder
def initialize(master: nil, holder: nil, opts: {})
@master = master
@holder = holder
if @master && @master... | true |
02c6a8852dcfe78524baaf951ff77abfa7528f92 | Ruby | kenoir/alchemy-concept-extractor | /lib/models/extractor.rb | UTF-8 | 903 | 2.6875 | 3 | [] | no_license | module AlchemyConceptExtractor
class Extractor
require 'rest_client'
attr :rest_client, true
attr :api_key, true
def initialize(api_key,rest_client)
@rest_client = rest_client
@api_key = api_key
end
def get_concepts(uri)
@rest_client.proxy = ENV['HTTP_PROXY']
acce... | true |
0ffcbdc543d12cea36f404cb9c70f84e932f81ea | Ruby | ayaksic/ruby | /substrings.rb | UTF-8 | 709 | 3.609375 | 4 | [] | no_license | def substrings word, dictionary
word_hash = Hash[dictionary.collect { |item| [item, 0] } ]
letters = word.downcase.scan(/\w/)
word_hash.each do |key,value|
letters_to_check_for = key.downcase.scan(/\w/)
for i in (0...letters.length)
if letters[i...i+letters_to_check_for.length]==letters_to_check_for
valu... | true |
74d46624a5bdeadbd94651a7c257b3dd814c1fc1 | Ruby | tahnok/advent | /day_12/part2.rb | UTF-8 | 359 | 3.40625 | 3 | [] | no_license | require 'json'
require 'pry'
def sum(obj)
case obj
when Fixnum
obj
when String
0
when Array
obj.map{|x| sum(x)}.inject(&:+)
when Hash
if obj.values.any?{|x| x == "red"}
0
else
obj.map{|x| sum(x)}.inject(&:+)
end
else
fail "wtf #{obj}"
end
end
thang = JSON.parse(Fi... | true |
dfb32569cca440f6332f47feaee1a0f7f030bd80 | Ruby | jimszalew/black_thursday | /test/invoice_item_test.rb | UTF-8 | 2,185 | 2.8125 | 3 | [] | no_license | require_relative 'test_helper'
require_relative '../lib/invoice_item'
require_relative '../lib/sales_engine'
class InvoiceItemTest < Minitest::Test
attr_reader :invoice_item
def setup
csv_paths = {
:items => "./test/data/small_item_set.csv",
:merchants => "... | true |
bd1f62a5418fa534185a34ff8ee08813acbbb6c4 | Ruby | bishwahang/advent2020 | /day07/day07.rb | UTF-8 | 2,414 | 3.625 | 4 | [] | no_license | #!/usr/bin/env ruby
class Bag
attr_reader :contains, :color
def initialize(color, contains = [])
@color = color
@contains = contains
end
def contains?(other_bag)
return true if self == other_bag
return false if contains.empty?
return true if contains.include?(other_bag)
contains.uniq... | true |
8d901d4c249840d6c83ec4fac67dfa61fc76179c | Ruby | jiko/yoshibot | /yoshi.rb | UTF-8 | 454 | 2.6875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'rubygems'
require 'chatterbot/dsl'
# here's a list of users to ignore
#blacklist "abc", "def"
def yoshi(max)
rand(max).times.map{"YOSHI"}.join(" ")
end
# here's a list of things to exclude from searches
# exclude "haha", "thank", "thanks", "stop", "lol"
#search "yoshi", opts={:count ... | true |
477e67beaf9fb3cd366341ef18fbc8a17ba9494b | Ruby | bendeloyola/ruby_activity | /lesson_1/control_flow_activity.rb | UTF-8 | 60 | 2.859375 | 3 | [] | no_license | arr = [1,3,5,7,9,11]
number = 3
p arr.include? number
| true |
7d8d01410a4e3c0d3f7e24e2f2d79280f7639ba0 | Ruby | akexinad/topics | /16-advanced/searching/binary_search.rb | UTF-8 | 226 | 3.359375 | 3 | [] | no_license | a = Array.new(100) { rand(1..1000) }
def binary_search(haystack, needle)
# return the index of needle within the haystack array
# or null id needle not found
# your code goes here.
end
puts binary_search(a, 15)
| true |
6f5604833cbb0aa5ff61ddeff57a071ad6cad0ce | Ruby | craigbowditch/week02_day01_classes_homework | /specs/students_spec.rb | UTF-8 | 793 | 3 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative ('../students.rb')
class StudentTest < MiniTest::Test
def setup
@student = Student.new("Craig", "G7")
end
def test_student_name()
assert_equal("Craig", @student.name())
end
def test_student_cohort()
assert_equal("G7", @studen... | true |
52e037679b86546a0e9fa062a661c347baf1ed3c | Ruby | Carsano/thp_s3_j4_morpion | /lib/app/board.rb | UTF-8 | 3,204 | 3.0625 | 3 | [] | no_license | class Board
attr_reader :cases, :nb_coups_joues, :aborted
def initialize
# Ici on initialise un plateau
# On crée les boardcases
a1=BoardCase.new(1)
a2=BoardCase.new(2)
a3=BoardCase.new(3)
b1=BoardCase.new(4)
b2=BoardCase.new(5)
b3=BoardCase.new(6)
c1=BoardCase.new(7)
... | true |
24d625155889dea2f02fde4f217d8906ee120356 | Ruby | drransom/chess | /lib/errors.rb | UTF-8 | 570 | 3.234375 | 3 | [] | no_license | class InputError < ArgumentError
def message
"Please enter your move in this format: a1 a2 (rows a-h, columns 1-8)"
end
end
class PieceNotOwnedError < StandardError
def message
"You do not own a piece at that square."
end
end
class CheckError <StandardError
def message
"That move would leave you... | true |
fa8e1a0def15076557e347ad3e16695222516279 | Ruby | revence27/fcs | /princescale.rb | UTF-8 | 489 | 2.90625 | 3 | [] | no_license | #! /usr/bin/env ruby
def pmain args
perc = false
max = 0
$stdin.each_line do |ligne|
$stdout.puts ligne
$stdout.flush
gots = ligne.strip
goti = gots.to_i
msg = ''
perc = true if goti < max
if perc then
msg = '%d%%' % [(goti.to_f / max.to_f).round(2)]
else
max ... | true |
747320c781d6787ae087ff7c240da3fa69fea946 | Ruby | lelilia/job-prep | /leetCode/maximum-subarray.rb | UTF-8 | 1,853 | 3.953125 | 4 | [] | no_license | # https://leetcode.com/problems/maximum-subarray/
# @param {Integer[]} nums
# @return {Integer}
# naive solution that was not fast enough for very long tests
# def max_sub_array(nums)
# maxtotal = nums[0]
# (0..nums.length - 1).each do |i|
# maxi = nums[i]
# new_sum = maxi
# (i+1..nums.length-1).e... | true |
66aea8e50470b9d8aa1fda81191351c97e71c2bb | Ruby | Arlissonjaques/estudos-ruby | /operadores.rb | UTF-8 | 136 | 3.484375 | 3 | [] | no_license |
# Adicao +
puts 10 + 10
# Subtracao -
puts 10 - 5
# Divisao
puts 10 / 2
# Multiplicacao
puts 2 * 5
# Resto da divisao
puts 10 % 2
| true |
b697ac547f003d2059fa78a386eddff09ee3e232 | Ruby | dderocher/Pragcourse_RubyProgram | /studio_game/die.rb | UTF-8 | 128 | 3.171875 | 3 | [] | no_license | class Die
attr_reader :number
def initialize
roll
end
def roll
@number = rand(1...6)
@number
end
end | true |
1f16eb91bc32988040f1f011149e11ce7e0d2c29 | Ruby | sub2u/ruby_problems_with_rspec_coverage | /prime_table/test/test_prime_table.rb | UTF-8 | 698 | 2.96875 | 3 | [] | no_license | $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require 'prime_table'
describe PrimeTable, "#process" do
it "should give 4X4 array" do
bowling = PrimeTable.new(3)
bowling.process.size.should eq(4)
end
it "should give all able as array of " do
bowling = PrimeTable.new(3)
bowling.proce... | true |
1ad97705ec556d7876be55dc0b063958a47de180 | Ruby | daniel-schroeder-dev/tts-ruby | /w1/activity_today.rb | UTF-8 | 443 | 3.890625 | 4 | [] | no_license | def pick_activity
puts "What is todays temperature?"
temp = gets.chomp.to_i
if (temp > 110) || (temp < 20)
puts "#{temp} degrees seems a little ridiculous for New Orleans!"
pick_activity
elsif temp >= 80
puts "#{temp} degrees is perfect for swimming!"
elsif temp > 50
puts "#{temp} degrees so... | true |
ab891b50fc11f65200aee1c0e5a0a2b5fc2fdd14 | Ruby | ramiror/personal-dev-learning | /ruby/deep_test/simple_test/tests/yela_test.rb | UTF-8 | 157 | 2.671875 | 3 | [] | no_license | require "tests/hello"
class GreekHello < Hello
def hello
"Yela"
end
def goodbye
"Avtio"
end
def lang
"gr"
end
end
GreekHello.new
| true |
b23ead68125ca85d97bffcb8015cd2dc359c68fd | Ruby | ShaunMackie/Ruby_Small_Problems | /Easy_1/Easy1_2_again.rb | UTF-8 | 1,138 | 4.53125 | 5 | [] | no_license | =begin
#problem: write a method that takes an integer as an argument, and returns 'true' if the number's absolute value is odd
input: an integer
output: a boolean
example:
puts is_odd?(2) # => false
puts is_odd?(5) # => true
puts is_odd?(-17) # => true
puts is_odd?(-8) # => false
puts is_odd?(0... | true |
962c1ea8066e59e2dd25c2b6a699ed01f78dd671 | Ruby | nblaze2/news-aggregator | /server.rb | UTF-8 | 1,142 | 2.6875 | 3 | [] | no_license | require 'sinatra'
require 'pry'
require 'csv'
require 'uri'
set :bind, '0.0.0.0' # bind to all interfaces
get '/articles' do
@articles = CSV.readlines('articles.csv')
erb :index
end
get '/articles/new' do
erb :new
end
post '/articles' do
@error = {}
@title = params['title']
if @title.empty?
@error[... | true |
382567d2e4529f84cf4ca3544b4de7fabaeb172e | Ruby | nicolasleger/anystyle | /spec/anystyle/feature/number_spec.rb | UTF-8 | 1,122 | 2.625 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference",
"BSD-2-Clause"
] | permissive | module AnyStyle
describe "Number Feature" do
let(:f) { Feature::Number.new }
%w{ (1992) 1992. 2011, 1776; 1970/71 (2000 2001) (2014). }.each do |num|
it "observes :year in #{num.inspect}" do
expect(f.observe(num)).to eq(:year)
end
end
%w{ (1) (12) (123) }.each do |num|
it "... | true |
3802ab981e92e2908881c8c5fd185ca73ceb4ab4 | Ruby | mariogmarq/pdoo | /practicas/practica3_rb/lib/ShieldBooster.rb | UTF-8 | 913 | 3.046875 | 3 | [] | no_license | #encoding: utf-8
#Clase que representa a los potenciadores de escudo que pueden tener las estaciones espaciales
require_relative 'ShieldToUI'
module Deepspace
class ShieldBooster
#Constructor con parámetros de la clase
def initialize(name, boost, uses)
@name = name
@boost = boost
@uses ... | true |
4f45ffcb6096e0bf45fc80d9f29926b7f88c40b3 | Ruby | jacobhlyon/book_club | /app/controllers/meetings_controller.rb | UTF-8 | 2,512 | 2.53125 | 3 | [] | no_license | require 'byebug'
class MeetingsController < ApplicationController
def index
@meetings = Meeting.all
@user = current_user
end
def new
# if @user.meetings_attended >= 2
@meeting = Meeting.new
@user = current_user
# else, flash[:message] = "You need to read more books first."
end
def create
@meetin... | true |
87370e7c14c1699366792bd30ffe7be40dd8f21a | Ruby | baijianwei827/weibo | /app/helpers/application_helper.rb | UTF-8 | 390 | 2.59375 | 3 | [] | no_license | module ApplicationHelper
#根据所在的页面返回完整的标题
def full_title(page_title = '鲁克微博') #定义方法,参数可选
base_title = '鲁克微博' #变量赋值
if page_title.empty? #布尔测试
base_title #隐式返回值
# return base_title 可省略return
else
page_title + ' - ' + base_title #字符串拼接
end
end
end
| true |
4be614bfb47a6add089845dfd67d8c364dc5fd2f | Ruby | TopDev130/ReactNative-PFC | /fastlane/Fastfile | UTF-8 | 8,099 | 2.8125 | 3 | [] | no_license | fastlane_version "1.10.0"
project_file = "./platforms/ios/este.xcodeproj"
workspace_file = "./platforms/ios/este.xcworkspace"
project_folder = "./platforms/ios";
plist_file = "#{project_folder}/Info.plist"
default_platform :ios
# Private: Generates random build number
#
# Example:
#
# random_build_number
# # =... | true |
c551fc8a242a661ef9226c6e201e0efbd06c2591 | Ruby | creitter/product_catalog | /db/seeds.rb | UTF-8 | 1,643 | 2.6875 | 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 |
23aab6ec2a3c7572d41e09d315d9ab1b4d68cfd1 | Ruby | NickTerrafranca/rhizo | /app/models/quantity.rb | UTF-8 | 655 | 2.75 | 3 | [] | no_license | class Quantity < ApplicationRecord
has_many :recipe_line_items
has_many :recipes, through: :recipe_line_items
ALLOWED_UNITS = ['ml','ltr', 'mg', 'gram', 'gal', 'tsp', 'tbsp', 'cup', 'lb', 'qt', 'pt']
before_validation :strip_whitespace
before_save :downcase_unit
validates :unit, presence: true, format: { ... | true |
3a94bc84c138fe9be3799a35e9d1c25dcfe10665 | Ruby | sergi0aguirre/Ruby-Challenges | /challenges/bit_positions.rb | UTF-8 | 458 | 3.375 | 3 | [] | no_license | class Bit
attr_accessor :file
def initialize(file)
@file=file
end
def load_file
file = File.new(self.file, "r")
self.check_line(file)
file.close
end
def check_line(file)
while (line = file.gets)
settings=line.split(',')
str=settings[0].to_i.to_s(2)
puts self.check_positions(str, set... | true |
dd5797a0cd11d0f5fadc4cd28fedb951407d3aaf | Ruby | jdegrand/AdventOfCode | /2020/Day1/1.rb | UTF-8 | 610 | 3.546875 | 4 | [] | no_license | require 'set'
file = "input.txt"
input = File.read(file)
$nums = input.split("\n").map(&:to_i)
def day1_1
s = Set.new
$nums.each do |n|
if s.include?(2020 - n)
puts n * (2020 - n)
return
end
s << n
end
end
def day1_2
(0...$nums.length).each do |i|
... | true |
89a115482290d04742ef0746ade3253e52e0c213 | Ruby | grant-mc/LaunchSchool-RB101-Programming-Foundations | /Exercises/Easy_1/ReverseItPt2.rb | UTF-8 | 332 | 3.390625 | 3 | [] | no_license | def reverse_words(word)
words = []
word.split.each do |w|
w.reverse! if w.size >= 5
words << w
end
words.join(' ')
end
puts reverse_words('Professional') # => lanoisseforP
puts reverse_words('Walk around the block') # => Walk dnuora the kcolb
puts reverse_words('Launch School') # => hc... | true |
78caaa38cba351e0cc5c64bccf3fa8f2706469fc | Ruby | jamaga/temp_exercise | /sroda_data.rb | UTF-8 | 708 | 3.125 | 3 | [] | no_license | require 'date'
class DateCompare
def initialize(date2, date1)
@date2 = date2
@date1 = date1
end
def diff_days
Date.parse(@date1).mjd - Date.parse(@date2).mjd
end
end
=begin
class DateTest < Test::Unit::TestCase
def test_compare_two_dates
dc = DateCompare.new('2015-04-25', '2015-04-28')
... | true |
954c6548b54511cc3219afc7bbc18f7b09fae184 | Ruby | dtrann/dailyprogrammer | /challenges/2016-05-02-Challenge-265-Easy-Permutations-and-combinations-part-1/perms_and_combs_p1.rb | UTF-8 | 721 | 3.828125 | 4 | [] | no_license | =begin
Ruby practice
COMMENTS WITH LINKS FOR FUTURE REFERENCE
'puts' used to print out solution to console
.permutation http://ruby-doc.org/core-2.2.0/Array.html#method-i-permutation
.combination http://ruby-doc.org/core-2.2.0/Array.html#method-i-combination
.to_a http://ruby-doc.org/core-2.2.0/Array.html#method-i... | true |
71ea3a7b2ba44e6391a9f542e9af698037893699 | Ruby | Dieblax/ruby-tests | /03_simon_says/simon_says.rb | UTF-8 | 512 | 3.890625 | 4 | [] | no_license | def echo(s)
return s
end
def shout(s)
return s.upcase
end
def repeat(s, times=2)
return (s + " ") * (times-1) + s
end
def start_of_word(s, num)
string = ""
(0...num).each do |i|
string += s[i]
end
return string
end
def first_word(s)
str = s.split(" ")
return str[0]
end
def titleize(s)
str = s.split(" "... | true |
4c553c980188d8751fee09df288e3c33a2a1db9f | Ruby | uddystyle/perfect_ruby_sample | /nested_const.rb | UTF-8 | 222 | 2.8125 | 3 | [] | no_license | VALUE = 'toplevel'
class Foo
VALUE = 'in Foo class'
class Bar
def self.value
VALUE
end
end
class Foo::Baz
def self.value
VALUE
end
end
end
puts Foo::Bar.value
puts Foo::Baz.value
| true |
431c586f0062437f2204b78d0dcbae3f61c2bff0 | Ruby | amfazlani/phase-1 | /week-4/variables-methods.rb | UTF-8 | 1,679 | 3.96875 | 4 | [
"MIT"
] | permissive | # Full Name Greeting
puts "What is your first name?"
first-name = gets.chomp
puts "What is your middle name?"
middle-name = gets.chomp
puts "What is your last name?"
last-name = gets.chomp
puts "Hello #{first-name} #{middle-name} #{last-name}!"
#bigger, better, favorite number
puts "What is your favorite number?"
f... | true |
9d6e7bd48658067bd1fcf405012272eedf104563 | Ruby | ItsAnkit/DSA | /ruby-programs/misc/pythagorean_triplet.rb | UTF-8 | 333 | 3.84375 | 4 | [] | no_license | class PythagoreanTriplet
def call(limit)
m = 2
a, b, c = 0, 0, 0
while c < limit do
n = 1
while n < m do
a = m*m - n*n
b = 2*m*n
c = m*m + n*n
break if c > limit
print [a, b, c]
n += 1
end
m += 1
end
end
end
PythagoreanTriplet... | true |
c615f79103b28e545a55a2bd80f9e8decc2609dc | Ruby | nesaulov/surrealist | /spec/builder_spec.rb | UTF-8 | 2,485 | 2.90625 | 3 | [
"MIT",
"CC-BY-3.0"
] | permissive | # frozen_string_literal: true
class Table
include Surrealist
def foo
'A string'
end
def bar
[1, 2, 4]
end
def baz
{ key: :value }
end
def struct
Struct.new(:foo, :bar).new(42, [1])
end
def multi_struct
Struct.new(:foo, :bar).new(42, Struct.new(:baz).new([1]))
end
end
RSp... | true |
506ad187d057a31d4769afe95de8c32f25b02d84 | Ruby | macZombie/Ruby- | /genericFunctions.rb | UTF-8 | 2,920 | 2.796875 | 3 | [] | no_license | #!/usr/bin/ruby
# genericFunctions.rb
def parseArguments
variableName = ""
case(ARGV.size)
when ( 0 )
print "\nEnter input file name:- "
variableName = gets.chomp.strip
when ( 1 )
variableName = ARGV[0]
e... | true |
8d5679fcf0f323658f16ef5c8ab9056adc6617f4 | Ruby | cr8on2/creightoncode | /Ch12.HappyBirthday.97.rb | UTF-8 | 315 | 3.390625 | 3 | [] | no_license |
puts "What year were you born?"
year = gets.chomp
puts "What number month were you born?"
month = gets.chomp
puts "What number day were you born?"
day = gets.chomp
time = Time.local(year, month, day)
timenow = Time.new
# puts time
# puts timenow
puts ((timenow - time) / 60 / 60 / 24/ 365).to_i
| true |
c12251dbd6e37f06b087e40c42b2502a9e781ecf | Ruby | adeschene/ruby-blackjack | /players.rb | UTF-8 | 861 | 3.859375 | 4 | [] | no_license | class Player # A player in the game; has a hand consisting of cards
attr_accessor :hand # Allows us to get and set 'hand' outside of class
def initialize
@hand = [] # Create empty hand array
end
end
class Dealer < Player # Is a player; has the deck; deals cards
def initialize
super() # Requi... | true |
fd9de4d0ee5db2d1a862de01392ebf7caef8baea | Ruby | kmcgrevey/backend_module_0_capstone | /day_4/ex19.rb | UTF-8 | 2,360 | 4.46875 | 4 | [] | no_license | # define/name the method and assign a parameter/local variable
def cheese_and_crackers(cheese_count, boxes_of_crackers)
# mini-script routine
puts "You have #{cheese_count} cheeses!"
puts "You have #{boxes_of_crackers} boxes of crackers!"
puts "Man that's big enough for a party!"
puts "Get a blanket. \n"
# cl... | true |
2b2653e00b5a8de208d8d209900dafe1372e5400 | Ruby | danielpclark/b64challenge | /longb64-danielpclark.rb | UTF-8 | 1,811 | 3.21875 | 3 | [
"MIT"
] | permissive | class B64
def initialize(string, lngth=12)
@b64 = (
("A".."Z").to_a + ("a".."z").to_a + ("0".."9").to_a + ["+","/"]
).each_with_index.map {|x,i| {x=>i} }.inject(:update)
@string = string
@max = lngth.times.map { |i| @b64.invert[@b64.length-i-1] }.join("")
@start = lngth.times.map { |i| @b64.invert[i] }.jo... | true |
61af2c5a806e1e880297e506a4b927e433bd917b | Ruby | goodeggs/redis-copy | /spec/spec_helper.rb | UTF-8 | 955 | 2.78125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
REDIS_PORT = 6381
REDIS_OPTIONS = {
:port => REDIS_PORT,
:db => 14,
:timeout => Float(ENV["TIMEOUT"] || 0.1),
}
class RedisMultiplex < Struct.new(:source, :destination)
ResponseError = Class.new(RuntimeError)
def ensure_same!(&blk)
responses = {
source: capt... | true |
fce71d5fca2224112aa6d33de4b960961c6eb324 | Ruby | pedrohml/rmaze | /bin/rmaze | UTF-8 | 1,593 | 3.09375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require './lib/rmaze.rb'
require 'optparse'
options = {
:width => 10,
:height => 10,
:format => :ascii,
:algorithm => :backtrace
}
OptionParser.new do |opts|
opts.banner = "Usage: rmaze [options]"
opts.separator ""
opts.separator "Basic options:"
opts.on("-w", "--width width", "Specify th... | true |
286d1e72273c79ef5866a2d4cdc22a725477e541 | Ruby | ashbwinters/ruby-enumerables-cartoon-collections-lab-denver-web-033020 | /cartoon_collections.rb | UTF-8 | 565 | 3.5 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves(array)
index = 0
array.each_with_index{|item, index|
p "#{index + 1} #{item}"}
end
def summon_captain_planet(array)
planeteer = []
array.map{|call|
planeteer = "#{call.capitalize}!"}
end
def long_planeteer_calls(array)
array.any? {|word| word.length > 4}
end
def find_the_chee... | true |
0808d53988cfa2ca2deed9a6567a9ea95cb067ea | Ruby | seand08/ruby_practice | /until.rb | UTF-8 | 109 | 3.59375 | 4 | [] | no_license | puts "Give me a number between 1 and 10"
answer = gets.chomp.to_i
until answer >= 20
puts answer *= 2
end | true |
b5d2444202d895caefaef4a6ba6e807362f93b96 | Ruby | eregon/adventofcode | /2019/10a.rb | UTF-8 | 658 | 2.671875 | 3 | [] | no_license | input = File.read('10.txt')
asteroids = []
input.lines.each_with_index { |line,y|
line.chomp.chars.each_with_index { |c,x|
asteroids << x + y.i if c == '#'
}
}
asteroids.freeze
width = input.lines[0].chomp.size
height = input.lines.size
p asteroids.map { |candidate|
others = (asteroids - [candidate]).sort_... | true |
fd8648e03680062bcf8ab5a93ec16793080afbf5 | Ruby | bigxiang/leetcode | /49.group-anagrams/count.rb | UTF-8 | 484 | 3.296875 | 3 | [
"MIT"
] | permissive | #
# @lc app=leetcode id=49 lang=ruby
#
# [49] Group Anagrams
#
# @lc code=start
# @param {String[]} strs
# @return {String[][]}
def group_anagrams(strs)
a_ord = 'a'.ord
grouped_map = strs.each_with_object({}) do |str, memo|
char_count = Array.new(26, 0)
str.chars.each do |c|
char_count[c.ord - a_ord]... | true |
a6e937b1121d46d3e2abd0925711592ff39d49e2 | Ruby | mpugach/toy_robot | /lib/toy_robot/client.rb | UTF-8 | 327 | 2.828125 | 3 | [] | no_license | module ToyRobot
class Client
def self.start
robot = ToyRobot::Robot.new
while (input = gets)
command, *arguments = input.chomp.split(/[\s,]+/).map(&:downcase)
next unless ToyRobot::Robot::COMMANDS.include?(command)
robot.public_send(command, *arguments)
end
end
e... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.