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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ab0e662087eccf60aac2826d348e1203f424baca | Ruby | davidsiaw/tataru | /lib/tataru/instructions/value_rom_instruction.rb | UTF-8 | 533 | 2.671875 | 3 | [] | no_license | # frozen_string_literal: true
module Tataru
module Instructions
# sets a hash entry and resolves from rom what was set
class ValueRomInstruction < ImmediateModeInstruction
include RomReader
def run
return memory.error = 'No key set' unless memory.hash[:temp].key? :_key
key = mem... | true |
a4a6e7ca78cb81933b6641e9ca1e38164d3b5656 | Ruby | Aperta-project/Aperta | /lib/data_transformation/base.rb | UTF-8 | 3,917 | 2.78125 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2018 Public Library of Science
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, pub... | true |
f97a201a4022462dcb2c6162cb7c0a6fb417e8c3 | Ruby | kirangan/class_kolla | /latihan_hari5/loop_2.rb | UTF-8 | 268 | 3.734375 | 4 | [] | no_license | def format_phone_number(inp)
hasil = ""
i = 0
while i < inp.length
case i
when 0
hasil += "("
when 3
hasil += ")"
when 6
hasil += "-"
end
hasil += inp[i].to_s
i += 1
end
hasil
end
puts format_phone_number([1,2,3,4,5,6,7,8,9,0]) | true |
6906f3986799ef4a0f5e0da25eaa64a7829764d7 | Ruby | twhite96/minitest_playground | /test/filtering_test.rb | UTF-8 | 520 | 3.28125 | 3 | [] | no_license | require_relative 'test_helper'
# Run each of the three methods alone
# Then run red methods
# Then run blue methods
# Then run green methods
class FilteringTest < Minitest::Test
def color(str)
str.to_s
.gsub("red", "\e[31mred\e[39m")
.gsub("blue", "\e[34mblue\e[39m")
.gsub("green", "\e[3... | true |
1bf62859a6b4cb61475e8a7820c165bba5551afb | Ruby | ratamabahata/lesson_2 | /6_cart.rb | UTF-8 | 699 | 3.671875 | 4 | [] | no_license | # создаем пустой массив и сумму
cart = {}
total_cost = 0
puts "Введите название товара (или \"stop\"): "
loop do
name = gets.chomp.to_s
break if name == 'stop'
print 'цену товара: '
price = gets.chomp.to_f
print 'кол-во товара: '
count = gets.chomp.to_f
cart[name] = { p: price, c: cou... | true |
b4896779ef82da984d4601c42fffbf66b10782f5 | Ruby | ritabc/animal-shelter | /lib/customer.rb | UTF-8 | 1,812 | 3.125 | 3 | [
"MIT"
] | permissive | class Customer
attr_reader(:id, :name, :phone, :species_pref, :breed_pref)
def initialize(attr)
@id = attr.fetch(:id)
@name = attr.fetch(:name)
@phone = attr.fetch(:phone)
@species_pref = attr.fetch(:species_pref)
@breed_pref = attr.fetch(:breed_pref)
end
def self.all
returned_customer... | true |
1b2bc1f6dcf966d00875f657725e5bc5aac75cad | Ruby | walwoodr/regex-lab-v-000 | /lib/regex_lab.rb | UTF-8 | 398 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def starts_with_a_vowel?(word)
/\b[aeiouAEIOU]/ === word
end
def words_starting_with_un_and_ending_with_ing(text)
text.scan(/un\w+ing/)
end
def words_five_letters_long(text)
text.scan(/\b\w{5}\b/)
end
def first_word_capitalized_and_ends_with_punctuation?(text)
/\A[A-Z]/ === text && /[[:punct:]]\z/ === text
e... | true |
be9868126371a549f79762709ecaf2f54d5c509d | Ruby | lbvf50mobile/til | /20190122_Tuesday/20190122.rb | UTF-8 | 205 | 2.890625 | 3 | [] | no_license | #!/usr/bin/env ruby
# Ruby less elements each_cons => empty, each_slice => small sub array.
p "alias x='ruby 20190122_Tuesday/20190122.rb'"
p [1,2,3,4].each_cons(5).to_a
p [1,2,3,5].each_slice(5).to_a
| true |
32c832d0531c9433e9489ad9692929a2db16e1a5 | Ruby | minno/minno-ruby-sdk | /src/minno.rb | UTF-8 | 1,969 | 2.5625 | 3 | [] | no_license | #!/usr/bin/env ruby
#
# Copyright 2011 Minno, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or ... | true |
df97e450e1102c83e03c1c3644778a364d166b1e | Ruby | pacalabre/ruby-challenges | /ruby challenge 3.rb | UTF-8 | 868 | 3.875 | 4 | [] | no_license |
@balance
@withdraw
@deposit
def input
puts "what would you like to do? balance withdraw or deposit?"
answer = gets.chomp
if answer == "balance"
balance()
end
if answer == "withdraw"
current_balance = balance()
puts "how much would you like to withdraw?"
answer_wi... | true |
faef35e4b799f5c61f4885347f126aabbad6b5ee | Ruby | nschneble/grape-attack | /lib/grape/attack/limiter.rb | UTF-8 | 1,230 | 2.59375 | 3 | [
"MIT"
] | permissive | require "grape/attack/request"
require "grape/attack/counter"
module Grape
module Attack
class Limiter
attr_reader :request, :adapter, :counter
def initialize(env, adapter = ::Grape::Attack.config.adapter)
@request = ::Grape::Attack::Request.new(env)
@adapter = adapter
@count... | true |
8e51fe0794d8bc2b09bc9a2072a245fa0d8446c7 | Ruby | joey-vito/Day_Three | /hw31.rb | UTF-8 | 127 | 2.953125 | 3 | [] | no_license | class Animal
attr_accessor :color
attr_accessor :height
end
class Dog < Animal
def adding
puts "adding new dog"
end
end
| true |
bbe43506b92788c5985d447feb073dc6b204be6b | Ruby | sstelfox/object_patch | /lib/object_patch/operations/move.rb | UTF-8 | 2,047 | 2.90625 | 3 | [
"MIT"
] | permissive |
module ObjectPatch::Operations
# A representation of a JSON pointer move operation.
class Move
# Apply this operation to the provided document and return the updated
# document. Please note that the changes will be reflected not only in the
# returned value but the original document that was passed i... | true |
118552f02652f3e0cf897dc1cd50ec71fb2d85e5 | Ruby | fagunbhavsar/rspec-examples | /spec/array_spec.rb | UTF-8 | 310 | 2.578125 | 3 | [] | no_license | RSpec.describe Array do
it 'Should initiate empty array' do
expect(subject.length).to eq(0)
puts subject
puts subject.class
end
it 'Push will insert a value in array' do
subject.push('value')
expect(subject.length).to eq(1)
puts subject.length
puts subject.class
end
end
| true |
047177d0b6d5f42a9553b6a9217b49a8f256a429 | Ruby | CanusDomini/Conjugationer | /JapaneseConjugationerN1.rb | UTF-8 | 4,638 | 3.1875 | 3 | [] | no_license | require "CSV"
require_relative 'conjugationermodule'
$arr_of_arrs = CSV.read('jlptverbs100.csv')
def vocab_chooser
p "Would you like to choose specific words to play with?"
$vocab_chooser_option = gets.chomp
if $vocab_chooser_option == 'y' || $vocab_chooser_option == 'yes'
increment... | true |
2a8fc22d65f21fc206b02975f1aa12b70e0dc10a | Ruby | ryoma123/competitive-programming | /aoj/ALDS1/ALDS1_9_A.rb | UTF-8 | 373 | 3.296875 | 3 | [] | no_license | n = gets.to_i
a = gets.split.map(&:to_i)
def parent(i)
i / 2
end
def left(i)
2 * i
end
def right(i)
2 * i + 1
end
(1..n).each do |i|
s = "node #{i}: key = #{a[i - 1]}, "
s << "parent key = #{a[parent(i) - 1]}, " if parent(i) >= 1
s << "left key = #{a[left(i) - 1]}, " if left(i) <= n
s << "right key =... | true |
43802d500892accd0f16b405a0bfb8560b5649ef | Ruby | kanety/logical_query_parser | /lib/logical_query_parser/assoc_resolver.rb | UTF-8 | 1,117 | 2.515625 | 3 | [
"MIT"
] | permissive | require_relative 'assoc'
module LogicalQueryParser
class AssocResolver
def initialize(klass)
@klass = klass
end
def run(*args)
Assoc.new.tap do |assoc|
assoc.current = assoc.structure
resolve_assocs(@klass, args, assoc)
end
end
private
def wrap_array(optio... | true |
b3b62c42c0ffcab563063a38ae1805a0d5d62230 | Ruby | postmodern/deployml | /lib/deployml/cli.rb | UTF-8 | 6,892 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'deployml/project'
require 'thor'
require 'pathname'
module DeploYML
#
# The command-line interface to {DeploYML} using
# [Thor](http://github.com/wycats/thor#readme).
#
class CLI < Thor
namespace 'deploy'
desc 'exec', 'Runs a command on the deploy server'
method_option :environment, :... | true |
7371db5101a2772f8dfa86801885605810f2fce9 | Ruby | mthjones/SENG515 | /db/seeds.rb | UTF-8 | 4,578 | 2.59375 | 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 |
bc79bde3d431d4c4612982ed9d10067ed72c341f | Ruby | paulonegrao/treinocrud | /day_2/2010cafe.rb | UTF-8 | 568 | 4.34375 | 4 | [] | no_license | #Using case / when statements ask user to enter the coffee shop they want to order
# from and then print:
#"Grande Latte" if they enter Starbucks and "Double Double" if they enter "Tim Hortons" and
# "Medium Coffee" if they enter Blenz and "I don't know this shop" if the enter something else.
print "What's the coffee m... | true |
6bee10509d38399eed03a5ae99b56f1923d71221 | Ruby | bstiber/launch_school_exercises | /small_problems/easy2/2.rb | UTF-8 | 639 | 4.53125 | 5 | [] | no_license | # Build a program that asks a user for the length and width of a room in meters and then displays
# the area of the room in both square meters and square feet.
#
# The area of the room is 70.0 square meters (753.47 square feet).
SQ_METER = 10.7639
puts "Enter the length of your room in meters:"
length = gets.chomp.t... | true |
1f40e94e3338e74d2f8e28d50145348bab4430c0 | Ruby | mhasnat03/assignments | /homework1/problem1.rb | UTF-8 | 1,557 | 4.90625 | 5 | [] | no_license | def full_name(first_name, last_name, title) # We are defining a method called full_name and allowing it to take 3 arguments.
name = nil # we are creating a variable called name and setting its value to nil
if title && first_name && last_name #This is a conditional if statement where code checks if the 3 given... | true |
3e6785fa97689dee72e9a74784805521059d46e1 | Ruby | bartdn183/ninjabear | /fighter.rb | UTF-8 | 533 | 3.9375 | 4 | [] | no_license | class Fighter
attr_reader :name
attr_accessor :health, :power, :food
def initialize(name, health, power, food)
@name = name
@health = health
@power = power
@food = food
end
def attack(enemy)
enemy.lose_health(self.power)
end
def lose_health(power_attacker)
self.health -= power_attacker
end
end
... | true |
1028b43c4c7b4fad9de299078659b362fd30a532 | Ruby | pgarduque/code-portfolio | /ruby_code/number.rb | UTF-8 | 77 | 3.546875 | 4 | [] | no_license | puts "enter a number: "
num = gets.chomp
puts "you entered " + num
end | true |
5b9f3b7acbd7011fc443e5d1dca3d921fdf8e040 | Ruby | JamesAndresCM/ruby_scripting | /scripts/numero_mayor_menor_y_primos.rb | UTF-8 | 881 | 4 | 4 | [] | no_license | #!/usr/bin/env ruby
require 'mathn' #lib prime
numeros = [23,12,34,1,234,4,7,19,11]
puts "numeros : #{numeros}\n\n"
mayor = numeros[0]
menor = numeros[0]
numeros.each do |x|
mayor = x if x > mayor
menor = x if x < menor
end
puts "numero mayor #{mayor}"
puts "numero menor #{menor}"
#native ruby
puts "\nn... | true |
254cbbdc04b26afbc2202bc97db26ed91ea448da | Ruby | szabcsee/uk-number-formatter.rb | /spec/formatter/phone_number/uk_spec.rb | UTF-8 | 1,850 | 2.984375 | 3 | [] | no_license | require 'spec_helper'
require_relative '../../../lib/formatter/formatter.rb'
require_relative '../../../lib/formatter/phone_number/phone_number.rb'
require_relative '../../../lib/formatter/phone_number/uk.rb'
require_relative '../../../lib/formatter/exceptions/formatter_error.rb'
describe Formatter::PhoneNumber::UK do... | true |
ccb6d61cd12c1dfb1d63ea2fe2ca50511d93d06b | Ruby | ZABarton/project_euler | /007/007.rb | UTF-8 | 424 | 4.09375 | 4 | [] | no_license | # By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13,
# we can see that the 6th prime is 13.
# What is the 10 001st prime number?
require 'prime'
# it's built in:
test = Prime.first 10001
p test[-1]
#long-form
#create array of length 0
#count i from 2 upwards by 1
# => run prime_factor function on i
#... | true |
e4dbcb217e0bbb8780416ededbb7c4619f1ad7f3 | Ruby | gachapon/lobster-common | /spec/lib/lobster/abstract_attribute_spec.rb | UTF-8 | 843 | 2.59375 | 3 | [
"MIT"
] | permissive | require_relative '../../spec_helper'
RSpec.describe 'abstract' do
subject(:klass) do
klass = Class.new
klass.send(:abstract, :abstract_method)
klass
end
it 'is private' do
expect(Class.private_methods).to include(:abstract)
end
it 'creates a method' do
expect(klass.public_instance_metho... | true |
f86e3712d7f321b7c373df9b73a54173fbdcebae | Ruby | q45/tealeaf | /sort_array_refactor.rb | UTF-8 | 232 | 3.875 | 4 | [] | no_license | puts "Give me some words to sort. Hit enter twice when done"
words = []
while true
word = gets.chomp
break if word.empty?
words << word.downcase
end
puts "Please wait one millisecond while I sort these words"
puts words.sort
| true |
07f58ea8c39241287e21dc587c6ff8b1911ed6c1 | Ruby | zhon/street_address_ext | /test/street_address_ext_test.rb | UTF-8 | 2,989 | 3.0625 | 3 | [
"MIT"
] | permissive | require_relative 'helper'
require 'street_address_ext'
include StreetAddressExt
describe StreetAddressExt do
describe 'parse' do
it 'returns address' do
text = '1111 N 250 W, Harrisville, UT'
@parser.parse(text).class.must_equal StreetAddress::US::Address
end
it 'calls normalize' do
... | true |
6ccdda8ca4c75295b65b17824ae7a4e2a0f2c5b8 | Ruby | ssoonmi/aA-Homeworks | /W1D5/abstract_data_types.rb | UTF-8 | 1,396 | 3.875 | 4 | [] | no_license | class Stack
attr_accessor :arr
def initialize
# create ivar to store stack here!
@arr = []
end
def push(el)
# adds an element to the stack
self.arr.push(el)
end
def pop
# removes one element from the stack
self.arr.pop
end
def peek
# returns, but doesn't remove, the top e... | true |
315b15cd838733f0e54ee38b3425567778a0a057 | Ruby | olbrich/unknown | /bmi.rb | UTF-8 | 1,740 | 3.4375 | 3 | [
"MIT"
] | permissive | class Patient
attr_accessor :height
attr_accessor :weight
attr_accessor :name
def initialize(_name, _height, _weight)
@name = _name
@height = _height
@weight = _weight
# this might also raise an exception if height or weight were required
# fail ArgumentError, 'height is required' unless hei... | true |
1fcd0bed1d3ccfdf3db4e6c0268f0622a4a4bee6 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/rna-transcription/87c9b0a6e93c43b9892e5dcbb7dbf79b.rb | UTF-8 | 758 | 3.578125 | 4 | [] | no_license | class Complement
def self.of_dna (dna)
#Create empty array
rna = []
#Create mapping
com = {"G" => "C",
"C" => "G",
"T" => "A",
"A" => "U"}
#Loop over every character and apply mapping
dna.each_char do |c|
puts com[c]
rna << (com[c])
end
#Cr... | true |
59d7a6b976b3c4d84939c93ca02ffe0d1df50dfc | Ruby | luckylittle/ruby-tools | /5-GamesAndLearningTools/hangman.rb | UTF-8 | 1,241 | 3.78125 | 4 | [] | no_license | unless ARGV[0] and File.exists?(ARGV[0]) #can also use /usr/share/dict/words
puts "\n\nUsage: is hangman.rb <word.file>\n\n"
exit
end
words = File.readlines(ARGV[0])
mystery_word = words[rand(words.size)].chomp
solution = Array.new(mystery_word.length, "-")
guessed = []
steps = 6
#Start the ga... | true |
8af0fff2e4f814710b221e434734be948fe41ea2 | Ruby | jeffjiang8/sinatra-restful-routes-lab-nyc-web-091619 | /app/models/recipe.rb | UTF-8 | 407 | 2.71875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #Placeholder for a model
class Recipe < ActiveRecord::Base
# attr_accessor :name, :ingredients, :cook_time
# RECIPES = []
# def initialize(name, ingredients, cook_time)
# @name = params[:name]
# @ingredients = params[:inggredients]
# @cook_time = params[:cook_time]
# RECIPE... | true |
c24d73f3f74c33f019e434b00fffbe0e749adbb1 | Ruby | GauravBusinessOrg/TestRepo | /lib/guillotine/adapters/active_record_adapter.rb | UTF-8 | 2,269 | 2.75 | 3 | [
"MIT"
] | permissive | require 'active_record'
module Guillotine
class ActiveRecordAdapter < Adapter
class Url < ActiveRecord::Base; end
def initialize(config=nil)
Url.establish_connection config if config
end
# Public: Stores the shortened version of a URL.
#
# url - The String URL to shorten and store... | true |
29f2f19e40e17c1456b21faf5eb9263118a9c8b3 | Ruby | lotherk/rarma | /rarmalib/lib/rarmalib/sqf/object.rb | UTF-8 | 4,099 | 2.703125 | 3 | [
"MIT"
] | permissive | class Rarmalib::SQF::Object
attr_accessor :posATL, :posASL, :dir, :damage, :alive, :simulated,
:special, :group, :vehicle_var_name, :ammo, :pos
attr_reader :variables, :netid, :classname, :side, :this
# ====Arguments
# * +_classname+ - classname of the object
def initialize _classname=nil
@classname = ... | true |
a922c383dbc9234b5e49bfd1ffeb34d2fa06fa70 | Ruby | iPadrx/Exercice-Ruby | /exo_08.rb | UTF-8 | 93 | 3.109375 | 3 | [] | no_license | puts "Bonjour, c'est quoi ton prénom ?"
user_name = gets.chomp
puts "Bonjour #{user_name} " | true |
437f63f9349d9b9ac2a08818f547ba75ab78926a | Ruby | poloka/cerner_2-5_2020 | /find_me.rb | UTF-8 | 808 | 3.484375 | 3 | [] | no_license | # frozen_string_literal: true
# cerner_2^5_2020
#
# So you are stuck in a rut at home with needing to step away from your desk to refocus.
# Take a moment and see if you can you can find the number I have guessed. You can make this
# as exciting and challenging or just go with the default search between 1 and 100. ... | true |
753aa11144ec583e6f5b62db539e1da938a1e707 | Ruby | patsul12/TRAINS | /spec/train_spec.rb | UTF-8 | 1,524 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'rspec'
require 'train'
require 'city'
require 'pg'
require 'titleize'
TRAIN_DB = PG.connect({:dbname => 'train_test'})
RSpec.configure do |config|
config.after(:each) do
TRAIN_DB.exec("DELETE FROM city *;")
TRAIN_DB.exec("DELETE FROM train *;")
end
end
describe String do
describe "#titleize" d... | true |
5139c1a1635208aac13ba6db2e16af56a58a9a40 | Ruby | lukegit/sequel_model_generator | /lib/model_generator.rb | UTF-8 | 5,987 | 2.75 | 3 | [] | no_license | # Sequel Basic Scafolding Model Generator for MySQL
# Requires sequel-3.34.0 and above.
#
# This routine takes all the table of a database, en generates all Sequel models for Ramaze
# For each table model we put :
# - A header that reminds you the table structure
# - the plugin list you wrote in 'plugin_to_add' array
#... | true |
f3108679eb0d94d2e94233d2be39572fad6a3c81 | Ruby | SamaNaEz/ATM-project | /cash_dispenser.rb | UTF-8 | 419 | 3.0625 | 3 | [] | no_license | require_relative './screen'
class CashDispenser
def initialize
@message = Screen.new
end
def dispense_cash
@message.display_line_message("\n==================================")
@message.display_line_message("\nPlease take your money!")
@message.display_line_message("\n===========================... | true |
4bb6ef319672a557f8afe402a49b3a951e8bbeeb | Ruby | Caroline-B75/Ruby-Food_Deliveray_app-MVC | /app/controllers/orders_controller.rb | UTF-8 | 1,894 | 3.03125 | 3 | [] | no_license | require_relative "../views/meals_view"
require_relative "../views/customers_view"
require_relative "../views/sessions_view"
require_relative "../views/orders_view"
class OrdersController
def initialize(meal_repo, customer_repo, employee_repo, order_repo)
@meal_repo = meal_repo
@customer_repo = customer_repo
... | true |
84f09effe097148bca18d1aa507f70f1ab892c59 | Ruby | coDeguZo/ruby-oo-practice-has-many-through-template-dc-web-030920 | /app/models/Artist.rb | UTF-8 | 734 | 3.203125 | 3 | [] | no_license | #class for Model1 goes here
#Feel free to change the name of the class
class Artist
attr_reader :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def songs
song = Song.all.find_all do |song|
song.arti... | true |
10b9dad68527dd82f5e2424853359e86d07af543 | Ruby | jetsgit/card-deck | /lib/card.rb | UTF-8 | 242 | 3.21875 | 3 | [] | no_license | class Card
attr_accessor :rank, :suit
SUITS = %w(Spade Diamond Heart Club )
RANKS = %w(2 3 4 5 6 7 8 9 10 J Q K A)
def initialize(card)
self.rank = RANKS[card % 13]
self.suit = SUITS[card % 4]
end
end
| true |
550a1cb30de600bc8bc775d86094f633850a055d | Ruby | cmvandrevala/history_of_anansesem_city | /db/seeds/events/backstories/nola_macnamara.rb | UTF-8 | 4,531 | 2.59375 | 3 | [] | no_license | puts "===> Nola MacNamara's Backstory"
Event.create({
name: "The Little Irish Girl",
date: Date.new(1892,3,27),
description: "Nola McNamara is born to a poor but happy fishing family."
})
Event.last.characters << Character.where(name: "Nola MacNamara").take
Location.where(name: "Ireland").take.events << Event.la... | true |
ca484fdc4e8b67417427c9e5fbfcd23d3ddcdd2d | Ruby | A-work/Ruby_lessons | /lesson 2/zd_6.rb | UTF-8 | 2,005 | 3.515625 | 4 | [] | no_license | #
# Пользователь вводит поочередно название товара, цену за единицу и кол-во купленного товара (может быть нецелым числом).
# Пользователь может ввести произвольное кол-во товаров до тех пор, пока не введет "стоп" в качестве названия товара.
# На основе введенных данных требуетеся:
# -Заполнить и вывести на экран хеш,... | true |
9c533d7ec30bc5e4fb243650924dbb3a8bb301d8 | Ruby | jasminenoack/app-academy | /active-record-lite-master/lib/00_attr_accessor_object.rb | UTF-8 | 388 | 3.046875 | 3 | [] | no_license | class AttrAccessorObject
def self.my_attr_accessor(*names)
names.each do |name|
instance = "@" + name.to_s
getter = name.to_s
setter = name.to_s + "="
define_method(getter) do
self.instance_variable_get(instance)
end
define_method(setter) do |value|
self... | true |
30fcd515d8d0ad25f2c376bac0de672e01d1ddc9 | Ruby | ThomasCGreen/homework_assignments | /warmups/11/lib/crypt.rb | UTF-8 | 484 | 3.375 | 3 | [] | no_license | class Crypt
def self.encrypt(plain_text, key=rand(26))
convert_array = (("a".."z").to_a)
convert_array.push(" ")
encrypt_array = convert_array.rotate(key)
plain_array = plain_text.downcase.split("")
return((plain_array.map { |char| encrypt_array[convert_array.index(char)]}).join)
end
def self... | true |
fd3c26ba4f9d29091d7efc4f15da1934cb60aa04 | Ruby | dazpinto/sprite-converter | /Rakefile | UTF-8 | 2,314 | 2.609375 | 3 | [] | no_license | require './lib/base'
task :default => [:spritify]
desc "Make a css sprite from images in input folder"
task :spritify => [:has_imagemagick, :has_output_folder] do
files = FileList['input/*.png', 'input/*.jpg']
firstFile = file_name(files[0].split('/')[1])
outputname = "output/#{firstFile['name']}_output.#{firs... | true |
1ef5784e28df8296202832b5abaead4930e9a130 | Ruby | zaphod42/ruby-performance | /object_identity_compare.rb | UTF-8 | 451 | 3.0625 | 3 | [] | no_license | require 'benchmark'
iterations = 30_000_000
x = 'the value'
y = x
z = x.clone
Benchmark.bm(34) do |x|
x.report("x.object_id == y.object_id (true)") { iterations.times { x.object_id == y.object_id } }
x.report("x.object_id == z.object_id (false)") { iterations.times { x.object_id == z.object_id } }
x.report("x.e... | true |
75c328168de0e8c9d349e641960be86257b48c10 | Ruby | bendee48/tictactoe | /textable.rb | UTF-8 | 1,773 | 3.984375 | 4 | [] | no_license | module Textable
def introduction(valid_moves, game)
puts "Welcome to TictacToe."; sleepy
puts "The whirlwind extravaganza of...trying to put 3 things in a row."; sleepy
puts "If you would like to see how to play, enter 'R' or press Return to continue."
answer = gets.chomp.downcase
rules(va... | true |
687e913296f82161ebc57ee2ef254dbb5fb49186 | Ruby | Geebrok/tealeaf | /the_basics.rb | UTF-8 | 1,245 | 4.34375 | 4 | [] | no_license | # the_basics.rb
# exercise_1
puts "Grant " + "Brooks"
# exercise_2
"Enter a 4 digit number"
num = gets.chomp.to_i
num1 = num / 1000
puts "There are #{num1} thousands in #{num}"
num1 = num % 1000 / 100
puts "There are #{num1} hundreds in #{num}"
num1 = num % 1000 % 100 / 10
puts "There are #{num1} tens in #{num}"
n... | true |
e1fa92622fc96b53412938b3c33e09616b3d2dcc | Ruby | atzorvas/number_cruncher | /number_cruncher.rb | UTF-8 | 435 | 3.21875 | 3 | [] | no_license | require "sinatra"
require "json"
class Integer
def factors
square_root = self**0.5
(1..square_root).map{ |n| [n,self/n] if self/n*n == self }.compact.flatten.sort
end
def prime?
self.factors.size == 2 ? true : false
end
end
get '/:number' do
content_type :json
number = params[:number].to_i
... | true |
a7833dc0a732a3985abc33b816849fb6fb39e636 | Ruby | jbyrnesshay/launchschool_enrolled | /lesson_5/practice_problms2/test.rb | UTF-8 | 136 | 2.875 | 3 | [] | no_license | require 'pry'
array = [5,4,3,2]
test = array.reduce(0) do |total, num|
binding.pry
total + num if num < 4
binding.pry
end
p test | true |
200e864526b99e4bcd0c73514266619ef64a0eee | Ruby | valentinp72/picross | /src/UI/Frames/Game/Timers/TimerPenalty.rb | UTF-8 | 306 | 2.703125 | 3 | [
"MIT"
] | permissive | require_relative 'TimerUI'
class TimerPenalty < TimerUI
def markup(text)
return "<span color='#{@color}'>#{text}</span>"
end
def text
if @map.currentStat.penalty.seconds > 0 then
@color = 'orange'
else
@color = 'black'
end
return ' ' + @map.currentStat.penalty.elapsedTime
end
end
| true |
052ec37749bae1d479c932d126d891080378d8ff | Ruby | BerilBBJ/scraperwiki-scraper-vault | /Users/O/Ooble/steam_sale_latest.rb | UTF-8 | 2,794 | 2.65625 | 3 | [] | no_license | # encoding=utf-8
require 'cgi'
require 'date'
CURRENCIES = {
'uk' => '£',
'us' => '$',
'fr' => '€'
}
ORDER = ['uk', 'us', 'fr']
ScraperWiki::attach "steam_sale"
latest = ScraperWiki::select('MAX(date) latest from steam_sale.prices')[0]['latest']
prices = ScraperWiki::select '''game.id, game.name, game.count... | true |
b1f3b90a134aad06e923e95c2982ef260803dd15 | Ruby | brenooliveira/rmoip | /lib/rmoip/comissoes.rb | UTF-8 | 772 | 2.53125 | 3 | [] | no_license | module Rmoip
class Comissoes
def initialize(&block)
@comissionados = []
instance_eval &block if block_given?
end
def size
@comissionados.size
end
def add(*args, &block)
@comissionados << Comissao.new(&block) if block_given?
@comissionados << args.first unless args.... | true |
6c3bda1f1456872ed85e46d364023f696a0f9704 | Ruby | shioimm/til | /practices/exercism/ruby/2019/strain.rb | UTF-8 | 209 | 3.109375 | 3 | [] | no_license | # Strain from https://exercism.io
class Array
def keep
each_with_object([]) { |s, arr| arr << s if yield s }
end
def discard
each_with_object([]) { |s, arr| arr << s unless yield s }
end
end
| true |
20fa9bbe8f9975c6015ed4d6b44b096af4982d0f | Ruby | alexauritt/MathHotSpot | /test/lib/content_generation/math_problem_yaml_text_creator_test.rb | UTF-8 | 4,167 | 2.671875 | 3 | [] | no_license | require 'test/unit'
require_relative '../../../lib/content_generation/math_problem_yaml_text_creator'
class MathProblemYamlTextCreatorTest < Test::Unit::TestCase
def setup
@problem_info = {
:problem_level_id => 5,
:markup_templates => {
:question => "something @sub_me and also @sub_this_one... | true |
6ad907eba5b4f7d3caf187261260c1ee98a8dfc3 | Ruby | tdfranklin/kele | /lib/kele.rb | UTF-8 | 2,353 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'httparty'
require 'json'
require 'roadmap'
class Kele
include HTTParty
include Roadmap
BASE_URI = 'https://www.bloc.io/api/v1'
def initialize(email, password)
response = self.class.post("#{BASE_URI}/sessions", body: { 'email': email, 'password': password })
ra... | true |
d84dcc0590a00dc5ea3a25f0fcb42db16957fefd | Ruby | NNCT18J/ruby-cercil | /sosuu.rb | UTF-8 | 329 | 2.953125 | 3 | [] | no_license | i=0
n=0
while i<20 #素数の個数:i
if(n<=1) #1までなので足し算して次のループ処理へ
n+=1
next
end
k=2
while (n%k)>0
if(k>(n/2))
break
end
k+=1
end
if(k>(n/2))
print n," "
i+=1
end
n+=1
end
print "\n"
| true |
24a1c575cd6e6744a885eb90c4083defd9683240 | Ruby | lupinthe14th/codewars | /lib/simple_multiplication.rb | UTF-8 | 88 | 3.15625 | 3 | [
"MIT"
] | permissive | def simple_multiplication(number)
return 8 * number if number.even?
9 * number
end
| true |
85b5fbe2c7a45b93cbb381c11f85e4b35aa66130 | Ruby | buren/bh | /lib/bh/helpers/progress_bar_helper.rb | UTF-8 | 2,287 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'bh/classes/progress_bar'
module Bh
# Provides the `progress_bar` helper.
module ProgressBarHelper
# @see http://getbootstrap.com/components/#progress
# @return [String] an HTML block to display a progress bar.
# @example A 50%-filled, striped progress bar.
# progress_bar percentage: 50, ... | true |
2eb79d7de142a47f4bdf15a7dfc1bfa57f874c87 | Ruby | mzakany23/farkle | /helper/interface.rb | UTF-8 | 6,594 | 2.984375 | 3 | [] | no_license | module InterfaceHelper
def has?(symbol)
turn.current_roll.count_pairs.has_key?(symbol)
end
def show_result_of_one_last_turn(last_throws)
runner_up = last_throw_runner_up(last_throws)
if runner_up.count > 1 && game.winner.score == runner_up[0].score
p '-------------------------------------------'
p "It'... | true |
2acaa4e32f262a1b3a89be7e561f6281835c58e0 | Ruby | pierremugnier/surfcamp-challenges | /Beginners/01-Ruby/01-Programming-basics/03-What-your-name/lib/interface.rb | UTF-8 | 277 | 3.453125 | 3 | [] | no_license | def enter_info(para)
puts "entrez votre #{para}"
return gets.chomp
end
first_name = enter_info("prénom")
second_name = enter_info("second prénom")
last_name = enter_info("nom de famille")
puts "bienvenue à #{first_name.capitalize} #{second_name} #{last_name.upcase}"
| true |
a1d7368d447603e1b34152888d31c2bd228eee71 | Ruby | ccls/buffler | /test/active_support_extension/test_case.rb | UTF-8 | 6,840 | 2.625 | 3 | [] | no_license | module ActiveSupportExtension::TestCase
def self.included(base)
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
base.alias_method_chain :method_missing, :create_object
# I can't seem to find out how to confirm that
# method_missing_without_create_object
# doesn't already exist! WTF
# We don't w... | true |
8433b8b970b4c71996bd11a6d8966b34d9e8a881 | Ruby | dimpleok/ruby-sample | /string.rb | UTF-8 | 1,130 | 4.0625 | 4 | [] | no_license | #!/usr/bin/ruby
# http://ruby-doc.org/core-2.2.3/String.html
# Reverse a string
name = "wan"
puts "I will reverse your name: #{name}"
puts name.reverse()
puts name.reverse
# Get string's length
puts "The length of '#{name}' is #{name.length}"
# Repeat
puts "Just repeat myself"
puts name * 5
# Replace
s = "hello, wo... | true |
c3d7dbae472a9de7b6933732e5556f7471bd42de | Ruby | vbelov/blockchain | /app/models/currency.rb | UTF-8 | 509 | 2.5625 | 3 | [] | no_license | class Currency < ApplicationRecord
self.primary_key = :code
has_many :stock_currencies, foreign_key: 'app_currency_code'
scope :active, -> { where(active: true) }
class << self
def find_by_code(code)
find_by(code: code.downcase)
end
def find_by_code!(code)
find_by!(code: code.downcas... | true |
dea635ccb8f9c1200df45964b789295a9fc600a9 | Ruby | SalamanderMike/notes | /week_06_ruby_intro/day_2_file_operations/file_example_1.rb | UTF-8 | 419 | 3.0625 | 3 | [] | no_license | #file_example_1.rb
def make_todo(fname, title)
if !Dir.exist?("todos")
Dir.mkdir("todos")
end
newTodo = File.new("todos/#{fname}", "w")
newTodo.write "### #{title} ###\n"
newTodo.close
end
def time_created
Time.new.strftime("%Y%m%d%H%M%S")
end
def start
title = ARGV[0]
status = "incomplete"
time... | true |
1abda7a6ec66ceb30908813c25854549bb30edc5 | Ruby | QPC-WORLDWIDE/rubinius | /benchmark/app/rdoc-2.4.3/test/xref_data.rb | UTF-8 | 390 | 2.984375 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | XREF_DATA = <<-XREF_DATA
class C1
attr :attr
attr_reader :attr_reader
attr_writer :attr_writer
attr_accessor :attr_accessor
CONST = :const
def self.m
end
def m
end
end
class C2
class C3
def m
end
class H1
def m?
end
end
end
end
class C3
class H1
end
class ... | true |
217f1218b2667dbdc4d5c454915b7d65438c7d83 | Ruby | ShinSemiya/cross_river_with_titans | /spec/lib/rubicon_spec.rb | UTF-8 | 6,539 | 2.671875 | 3 | [] | no_license | require 'spec_helper'
describe Rubicon do
let!(:rubicon){ Rubicon.new(3, 2) }
describe "#initialize" do
it "max_number is 3" do
rubicon.max_number.should == 3
end
it "matrix is initialized" do
rubicon.matrix.should == [[1, 1, 1, 1], [0, 1, 0, 0], [0, 0, 1, 0], [1, 1, 1, 1]]
end
end
... | true |
39dc561ca3499e3b1b9e38a45f81403fcdd86bdf | Ruby | maxgud/Edabit_Code | /even_or_odd.rb | UTF-8 | 139 | 3.75 | 4 | [] | no_license | def isEvenOrOdd(num)
num = num
if (num % 2 == 0)
return "even"
else
return "odd"
end
end
puts isEvenOrOdd(5)
puts isEvenOrOdd(6) | true |
00030693317abb6e959c61fcf3bc16037bd0932b | Ruby | CeliaTHP/rubyd2 | /multiples.rb | UTF-8 | 293 | 3.421875 | 3 | [] | no_license | def sum_of_3_or_5_multiples(num)
x = 0;
res = 0
if num > 0
while x <= num
if is_multiple_of_3_or_5(num)== true
res = res + x
else
x++
puts #{res}
end
end
end
def is_multiple_of_3_or_5?(n)
if num > 0
if n >= 0 && n < 1000
if n % 3 == 0 || n % 5 == 0
return true
else
return false
end
end
end
| true |
9affb1529cbc65fc5454d6ddaf168fce6286e714 | Ruby | niallryan/GigHub | /test/unit/status_test.rb | UTF-8 | 765 | 2.71875 | 3 | [] | no_license | # Treehouse (2013) Building Social Features in Ruby on Rails. [online]
# Available at: http://teamtreehouse.com/library/programming/building-social-features-in-ruby-on-rails [Accessed: 23 May 2013].
require 'test_helper'
class StatusTest < ActiveSupport::TestCase
test "that a status requires content" do
status... | true |
514b0d3caa950c54bf71e9ec29478313b0b5efda | Ruby | patrick99e99/lpcinator | /lib/autocorrelator.rb | UTF-8 | 1,247 | 2.859375 | 3 | [] | no_license | module LPCinator
class Autocorrelator < Bufferable
def self.coefficients_for(buffer)
new(buffer).coefficients
end
def self.sum_of_squares_for(buffer)
new(buffer).sum_of_squares
end
def self.normalized_for(buffer, minimum_period, maximum_period)
new(buffer).normalized_for(minimu... | true |
d4640aadff33c860e98632b99791eeacba992bcd | Ruby | Mschmidt19/Day-1-Pairing-Challenges | /hashes.rb | UTF-8 | 646 | 3.484375 | 3 | [] | no_license | hash1 = { a: 1, b: 2 }
print hash1.merge(hash1){ |key, value| value + 1 }
puts ""
hash2 = { a: 2, b: 5, c: 1 }
value_array = []
hash2.each{ |key, value| value_array.push value}
value_array.sort!
current_index = 0
hash2.each do |key, value|
hash2[key] = value_array[current_index]
current_index += 1
end
print hash2
... | true |
0b4e629ea20e49843da32fe5d23c373dd643794f | Ruby | parkdy/ActiveRecordLite | /lib/active_record_lite/mass_object.rb | UTF-8 | 1,481 | 3.578125 | 4 | [] | no_license | class MassObject
# takes a list of attributes.
# creates getters and setters.
# adds attributes to whitelist.
def self.my_attr_accessible(*attributes)
@attributes = []
attributes.each do |attribute|
@attributes << attribute
end
# Create getters and setters
my_attr_accessor(*attributes... | true |
d3961b67cbc3f8816f0d75a68dac90dcd02250cd | Ruby | krainboltgreene/scripts | /ebnf_parser.rb | UTF-8 | 2,899 | 2.859375 | 3 | [] | no_license | require "parslet"
class EBNFParser < Parslet::Parser
rule(:eol) do
match["\r|\n"]
end
rule(:eol?) do
eol.repeat(0)
end
rule(:term) do
match["a-Z\s"].repeat
end
rule(:list) do
terminal >> (operator >> terminal).repeat(0)
end
rule(:first_quote) do
str("'")
end
rule(:second_... | true |
eeca28b517bbbeef829844d870eafcaa1d34a9c3 | Ruby | jesse-spevack/date_night | /test/node_test.rb | UTF-8 | 1,059 | 3.078125 | 3 | [] | no_license | require './test/test_helper'
require './lib/node'
class NodeTest < Minitest::Test
def test_it_has_all_attributes_of_a_node
node = Node.new(50, "Hannibal Buress: Animal Furnace")
assert_instance_of ScoreMovie, node.data
assert_equal nil, node.left
assert_equal nil, node.right
end
def test_it_know... | true |
6cd0f75d1a65cd9311c6e664e2fa1fce24e033a3 | Ruby | kinoppyd/blinkman | /lib/blinkman/adapter/shell.rb | UTF-8 | 493 | 2.640625 | 3 | [
"MIT"
] | permissive | module Blinkman
module Adapter
class Shell < Base
require 'readline'
attr_reader :stopped
PROMPT = '> '
def initialize(bot)
@stopped = false
super
end
def listen
while ! stopped
bot.on_receive(read)
end
end
def read
... | true |
64a0fc1201cbe955719ddf0e7da7d59c4e7b1520 | Ruby | LillianLuzinsky/sei-31 | /06-sinatra/intro.rb | UTF-8 | 1,109 | 3.234375 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
require 'pry' # This is a bad idea in general
# DSL: Domain Specific Language
get '/' do
"Hello world from Sinatra!!!!!!!"
end
get '/lucky_number' do
"Here is your lucky number #{ rand 1..40 }"
end
get '/uptime' do
"The server uptime is: #{ `uptime` }</body></html>... | true |
c9bf6c93db5fcba368b3c189802d1c925e21b334 | Ruby | ripperbone/mpd-remote | /app.rb | UTF-8 | 7,343 | 2.625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'sinatra/base'
require 'ruby-mpd'
require 'json'
class App < Sinatra::Base
before do
content_type 'application/json'
response.headers['Access-Control-Allow-Origin'] = '*'
if !@mpd.connected?
@mpd.connect
end
end
def alexa_request?
request... | true |
581f11323d14be76b6686b407528b79090a0dfc5 | Ruby | kdiep90/rubystuff | /ex15.rb | UTF-8 | 597 | 4.09375 | 4 | [] | no_license | filename = ARGV.first # assigns a variable to the first argument passed in the shell
txt = open(filename) # assigns a variable to whatever is in the file called
puts "Here's your file #{filename}:"
print txt.read # reads the content of the sample file
print "Type the filename of the file you want to view: "
file_agai... | true |
012cdef1bee100b4f1a838a094a300f4189207e6 | Ruby | kguadron/BinaryAndDecimal | /lib/binary_to_decimal.rb | UTF-8 | 795 | 4.5 | 4 | [] | no_license | # A method named `binary_to_decimal` that receives as input an array of size 8.
# The array is randomly filled with 0’s and 1’s.
# The most significant bit is at index 0.
# The least significant bit is at index 7.
# Calculate and return the decimal value for this binary number using
# the algorithm you devised in clas... | true |
0c8089c4dbc2aedaefa4fde25c61f8f27aac1bd2 | Ruby | doytsujin/net-http-server | /spec/net/http/server/parser_spec.rb | UTF-8 | 2,615 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'net/http/server/parser'
describe Net::HTTP::Server::Parser do
it "should not parse garbage" do
garbage = (1..255).map { |b| b.chr }.join * 100
lambda {
subject.parse(garbage)
}.should raise_error(Parslet::ParseFailed)
end
describe "request line" do
it "shoul... | true |
5b90624801e18f3083af4b763091b3cd296b83f3 | Ruby | google-code/aufgabe-2a-v4 | /H_Cube/lib/v_zylinder_v0.rb | UTF-8 | 928 | 2.625 | 3 | [] | no_license | $LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
require 'ext_pr1_v4'
#Zylindervolumenberechnung
# berechne_kreis_flaecheninhalt ::= (radius)::
# Test { (12.0 => 452.39), (12.5 => 530.93), ((-1) => Err), ((0) => Err), (("Welt") => Err)}
#
# berechne_zylinder_volumen ::= (radius, hoehe)::
#
... | true |
ec07f8646f4ef0dd34334c3b7add5b5d1b079081 | Ruby | zato91/ruby-oo-object-relationships-has-many-lab-wdc01-seng-ft-060120 | /lib/author.rb | UTF-8 | 346 | 3.109375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Author
attr_reader :name
def initialize(name)
@name = name
@@all = []
end
def posts
Post.all.select {|post| post.author == self }
end
def add_post(post)
@@all << post.author = self
end
def add_post_by_title(title)
Post.new(title).author = self
end
def self.post_count
... | true |
8f7f081a2396ad11aded67d9e0a40854e5a1920f | Ruby | lingaramo/algorithm-problems | /DP/Tetrahedron - 166E.rb | UTF-8 | 442 | 3.25 | 3 | [] | no_license | def solution(n)
h = { :A => Array.new(n+1, 0), :B => Array.new(n+1, 0), :C => Array.new(n+1, 0), :D => Array.new(n+1, 0) }
h[:D][0] = 1
positions = [:A, :B, :C, :D]
for i in 1..n do
positions.each do |position|
cnt = 0
(positions - [position]).each do |jump_to|
cnt += h[jump_to][... | true |
f220de0792ae4a751847b4376f905508a3f2fece | Ruby | lindsey-kirch/learnToProgramExercises | /c5_fullNameGreeting.rb | UTF-8 | 578 | 3.875 | 4 | [] | no_license | puts 'Hey there, sexy. What\'s your name?'
firstName = gets.chomp
puts 'How original. NOT. What about your last name?'
lastName = gets.chomp
puts 'Weirdly, I know a ' + firstName + ' ' + lastName + '. What is your middle name?'
middleName = gets.chomp
puts 'So, your name is ' + firstName + ' ' + middleName + ' ' + last... | true |
0fd60a99b6c70b75aafe1fdf47eaf28f4d6b4a44 | Ruby | caramorelli/count-elements-nyc-web-100818 | /count_elements.rb | UTF-8 | 203 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def count_elements(array)
count_hash = Hash.new
array.each do |ele|
if count_hash.has_key?(ele)
count_hash[ele] += 1
else
count_hash[ele] = 1
end
end
count_hash
end
| true |
df669ed2503193f848bf31b9dd948533690009b3 | Ruby | Janfred/cryptcheck-engine | /lib/cryptcheck/engine/double_hash.rb | UTF-8 | 293 | 2.828125 | 3 | [] | no_license | module Cryptcheck::Engine
class DoubleHash
include Enumerable
def initialize(hash = {})
@hash = hash.freeze
@inverse = hash.invert.freeze
end
def [](key)
@hash[key]
end
def each(&block)
@hash.each &block
end
def inverse(key)
@inverse[key]
end
end
end
| true |
4635fbd5709ccaee6272bf10e5396aa186658043 | Ruby | smn/ivr | /vumi/ivr.rb | UTF-8 | 2,724 | 2.59375 | 3 | [] | no_license | require 'vumi/say'
require 'vumi/amqp'
require 'json'
SESSION_NEW = 1
SESSION_EXISTING = 2
SESSION_END = 3
module Vumi
class IVR < Librevox::Listener::Outbound
class Menu
attr_accessor :text, :options
def self.from_json string
json = JSON.load string
new.tap do |menu|
... | true |
83ffd13239267a2afb949ef825c92450a3950efc | Ruby | yuji91/RefactoringRuby_Example_01 | /9_1_composed_condition.rb | UTF-8 | 597 | 2.84375 | 3 | [] | no_license | class Governor
def judge(target)
if target.air_vent_count.zero? || target.refresh_air_time_per_hour < 2 || target.people_count >= 5 || target.is_each_touchable == true || target.social_distance_meter < 2
:mitsudesu
else
:notmitsudesu
end
end
end
require 'teyu'
class Target
extend Teyu
... | true |
b4df9847fa58a597d618679f90e8a455d491c315 | Ruby | davepagurek/The-Cal-in-the-Hacks | /test.rb | UTF-8 | 837 | 2.875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'delegate'
require 'matrix'
require 'tf-idf-similarity'
document1 = TfIdfSimilarity::Document.new("The quick brown fox jumped over the lazy dog")
document2 = TfIdfSimilarity::Document.new("The dog jumped over the moon")
document3 = TfIdfSimilarity::Document.new("The fox jumped over the moo... | true |
f0b883242c475b3b57539c12cae3f28796251989 | Ruby | corrirc/week01_homework | /start_point/pet_shop.rb | UTF-8 | 1,283 | 3.21875 | 3 | [] | no_license | def pet_shop_name(pet_shop)
return pet_shop[:name]
end
def total_cash(sum)
return sum[:admin][:total_cash]
end
def add_or_remove_cash(cash, amount)
return cash[:admin][:total_cash] += amount
end
def pets_sold(pet_shop)
return pet_shop[:admin][:pets_sold]
end
def increase_pets_sold(pet_shop, increase_amount)... | true |
f28a2b6881dff6860912117e5b420332eece4a05 | Ruby | zarigani/pentomino | /bin/pentomino | UTF-8 | 6,329 | 3.265625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
# coding: utf-8
require 'optparse'
# オプション解析
$options = {}
OptionParser.new do |opt|
opt.banner = 'Usage: pentomino [options] [board size(3-8)]'
opt.on('-q', 'Hide progress putting a piece on board.(quiet mode)') {|v| $options[:quiet] = v}
opt.separator('')
opt.on('board size:',
' ... | true |
a157d0311e613195f76dcdd7d949cd0dc83da5ac | Ruby | abonec/geo_proxy | /lib/api.rb | UTF-8 | 1,140 | 2.671875 | 3 | [] | no_license | require 'json'
class Api < EM::Connection
include EM::Protocols::LineProtocol
def receive_line(geohash)
reduced_geohash = reduce(geohash)
cache.get(reduced_geohash) do |eta|
if eta
send_response eta
else
get_eta_for(geohash) do |eta|
if eta
cache.set(reduced... | true |
0db8e780e80b4eec9850dcc604b5f323424e2dee | Ruby | Guribot/grocery-store | /specs/customer_spec.rb | UTF-8 | 1,960 | 2.765625 | 3 | [] | no_license | # require 'minitest/autorun'
# require 'minitest/reporters'
# require 'minitest/skip_dsl'
require_relative 'spec_helper'
require_relative '../lib/order'
# TODO: uncomment the next line once you start wave 3
require_relative '../lib/customer'
customer_list = "./support/customers.csv"
test_customer = Grocery::Custome... | true |
7e9aa2e181c22ba095c2583bd14f2a7dc0a16736 | Ruby | niam0r/my-upcase-exercises | /testing-fundamentals-testing-activerecord/spec/models/person_spec.rb | UTF-8 | 419 | 2.59375 | 3 | [
"MIT"
] | permissive | require "spec_helper"
describe Person do
it "is invalid without a first_name" do
person = Person.new(first_name: nil)
expect(person).to be_invalid
end
it "is invalid with an empty first_name" do
person = Person.new(first_name: "")
expect(person).to be_invalid
end
it "is valid with a fir... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.