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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
15441f492a08293a955907c3c90df20854bb03b8 | Ruby | mlainez/attaboy | /lib/attaboy/query_builder.rb | UTF-8 | 1,642 | 2.671875 | 3 | [] | no_license | class QueryBuilder
PRESENCE_VALIDATOR = ActiveModel::Validations::PresenceValidator
def self.build_queries_for_model_validator(model_class, model_validator)
columns = model_class.columns
table_name = model_class.table_name
validator_class = model_validator.class
validator_tr... | true |
64718c7d190f12afc7a47aba481c7e219d3f90cb | Ruby | Lyra-B/patterns | /item.rb | UTF-8 | 1,022 | 3.25 | 3 | [] | no_license | class Item
attr_accessor :quantity, :title, :price, :best_before, :purchase_date,
:supplier, :supplier_contact, :supplier_number
attr_reader :id
@@next_id = 1
def initialize(attributes = {})
@observers = []
attributes.each do |attribute, value|
self.send "#{attribute}=", value
end
@id = @@next_id... | true |
89a6e451a327742b5b93d0a3989d33738360cba8 | Ruby | veekram/chamber | /lib/chamber/filters/translate_secure_keys_filter.rb | UTF-8 | 676 | 2.65625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'hashie/mash'
module Chamber
module Filters
class TranslateSecureKeysFilter
SECURE_KEY_TOKEN = /\A_secure_/
def initialize(options = {})
self.data = options.fetch(:data).dup
end
def self.execute(options = {})
new(options).__send__(:execute)
end
protected... | true |
3d142c43ffc1821eef92b72dae9c1c6380991c64 | Ruby | Nunocky/nand2tetris_solve | /10/JackTokenizer.rb | UTF-8 | 3,963 | 3.5 | 4 | [] | no_license | require 'pp'
class String
def is_number?
true if Float(self) rescue false
end
end
class JackTokenizer
KEYWORD = 0
SYMBOL = 1
IDENTIFIER = 2
INT_CONST = 3
STRING_CONST = 4
def initialize(src)
@tokens=[]
@token_index = 0
scan(src)
end
def hasMoreTokens
@token_... | true |
b9b7ac4b8f0692c6bffed122c5b8471d58d67e90 | Ruby | DeweyHammers/Ruby_Projects | /fingers_game.rb | UTF-8 | 211 | 3.53125 | 4 | [] | no_license | computer_fingers = rand(6)
puts "How many fingers am I holding up?"
player_response = gets.chomp
puts "I had #{computer_fingers} held out!"
puts "You guessed right!" if player_response.to_i == computer_fingers
| true |
e03c74f7c325d232cb48b343021cc71e3084cdc8 | Ruby | codyloyd/TOP-Ruby | /building_blocks/stock_picker/stock_picker.rb | UTF-8 | 342 | 3.453125 | 3 | [] | no_license | def stock_picker array
solution = [0,1]
profit = 0
array.each_with_index do |buy_value,buy_index |
(buy_index + 1).upto(array.length-1) do |sell_index|
if (array[sell_index] - buy_value) > profit
solution = [buy_index , sell_index]
profit = array[sell_index] - buy_value
end
en... | true |
15b193a81ac503fe748f8e07a262e50adbfd9843 | Ruby | ismudnx/dentaku | /lib/dentaku/expression.rb | UTF-8 | 1,144 | 3.28125 | 3 | [
"MIT"
] | permissive | require 'dentaku/tokenizer'
module Dentaku
class Expression
attr_reader :tokens, :variables
def initialize(string, variables={})
@raw = string
@tokenizer ||= Tokenizer.new
@tokens = @tokenizer.tokenize(@raw)
@variables = Hash[variables.map { |k,v| [k.to_s, v] }]
replace_identif... | true |
19138444e165f826dbee503cb0ecb1d0a1a58be5 | Ruby | viniciuscarneironascimento/rocklov | /api/spec/routes/equipos.rb | UTF-8 | 1,807 | 2.734375 | 3 | [] | no_license | require_relative "base_api"
# A pasta "routes" foi criada para guardar as rotas assim como fazemos com PageObject
class Equipos < BaseApi
# include HTTParty
# # Inclusão da linha abaixo que é uma propiedade do HTTParty que recebe a URL da API. Desta forma, a rota "http://rocklov-api:3333/sessions" utilizada no p... | true |
3a047d1006136d9d8af74c0b90fa076ecbc94979 | Ruby | michaelpeng/learn-ruby-the-hard-way | /ex37.rb | UTF-8 | 208 | 2.96875 | 3 | [] | no_license | BEGIN {puts "Script is starting"}
module Ex37
def self.foo
puts "foofoo"
end
self.singleton_class.send(:alias_method, :bar, :foo)
end
Ex37.bar
END {puts "Script has finished!"}
| true |
35c244d133a48ab5c4210696d275a80694a46f8a | Ruby | gsandoval/rneurofuzzy | /bin/quiz_ocr_preprocessor.rb | UTF-8 | 515 | 3.140625 | 3 | [] | no_license |
require 'chunky_png'
class QuizOcrPreprocessor
def initialize
@red = 0
@green = 1
@blue = 2
end
def process(raw_image)
raw_image = raw_image.resample 15, 15
img_w = raw_image.dimension.width
img_h = raw_image.dimension.height
img = Array.new(3, Array.new(img_h))
i... | true |
89d2cd5eb9c3f58cd15f879fac8d2e6fcd607be2 | Ruby | mechamobau/listas-ruby-fatec | /lista02/exec01/src/main.rb | UTF-8 | 446 | 2.59375 | 3 | [
"MIT"
] | permissive | require_relative 'Candidato'
require_relative 'Partido'
p1 = Partido.new("Partido dos Trabalhadores", "Socialista", :PT, 13)
p2 = Partido.new("Partido Novo", "Liberal", :NOVO, 30)
p3 = Partido.new("Partido Comunista do Brasil", "Comunista", :PCdoB, 65)
p4 = Partido.new("Progressistas", "Conservadores", :PP, 11)
c1 = ... | true |
de1fe068dd6f8b1c4fd6d2c013a71d53d6d702f0 | Ruby | fxzuz/programming_skills_test | /022_christmas/christmas.rb | UTF-8 | 142 | 2.78125 | 3 | [] | no_license | #!/usr/bin/env ruby
ARGF.each do |str|
base = str.to_i
(1..base).each do |n|
puts ' ' * (base - n) + Array.new(n, n).join(' ')
end
end
| true |
c3d21ecc48cedf9d71af26452a56e442ee507d4d | Ruby | dslh/db_mod | /lib/db_mod/transaction.rb | UTF-8 | 1,123 | 2.8125 | 3 | [
"MIT"
] | permissive | module DbMod
# Module which provides transaction blocks for db_mod
# enabled classes.
module Transaction
protected
# Create a transaction on the db_mod database connection.
# Calls +BEGIN+ then yields to the given block. Calls
# +COMMIT+ once the block yields, or +ROLLBACK+ if the
# block rai... | true |
a12045788e06d13d2bbdab367cdab320b8b4db10 | Ruby | jakejakearell/b2-final-2011 | /spec/features/flight/index_spec.rb | UTF-8 | 1,596 | 2.65625 | 3 | [] | no_license | require "rails_helper"
RSpec.describe "As a visitor" do
before(:each) do
@flight_1 = Flight.create!(number: 123, time: 0700, departure_city:"Las Vegas", arrival_city: "Denver", date: '2000-01-01 00:00:00 -0500')
@flight_2 = Flight.create!(number: 124, time: 0700, departure_city:"Las Vegas", arrival_city: "Al... | true |
5a4b6ff14046de780e5137dc89fbfb608472c4d1 | Ruby | arikui1911/YAJP | /lib/yajp.rb | UTF-8 | 2,218 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'yajp/lexer'
require 'yajp/parser'
require 'yajp/compiler'
require 'pathname'
# YAJP is "Yet Another JSON Parser".
#
# YAJP is written in order to practice using pattern matching,
# so it is not considered to be a practical library.
#
module YAJP
# Parse string which represent JSON source code.
#
# @para... | true |
894ed3a5b53c6eec65f9dde16a1d6a0549bca80c | Ruby | jsvine/crochet | /test/test.rb | UTF-8 | 2,840 | 2.609375 | 3 | [] | no_license | #!/usr/bin/env ruby
# Note: Run this from the repo's base directory
lib = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "crochet"
require "test/unit"
class TestBefore < Test::Unit::TestCase
def test_class_method
$result = nil
hoo... | true |
b5b005de6cfbe6cd17d3a6e503e9d875ef98a12a | Ruby | YoshiMejia/oo-counting-sentences-online-web-sp-000 | /lib/count_sentences.rb | UTF-8 | 444 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class String
def sentence?
if self.end_with?(".")
true
else
false
end
end
def question?
if self.end_with?("?")
true
else
false
end
end
def exclamation?
if self.end_with?("!")
true
else
false
end
end
def count_sentences
new_a... | true |
d4437a3cca916a33104a71e9d31a1fe4cd2422ac | Ruby | rcchan/hqmf-parser | /lib/hqmf-parser/data_criteria.rb | UTF-8 | 3,879 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | module HQMF
# Represents a data criteria specification
class DataCriteria
include HQMF::Utilities
attr_reader :property, :type
# Create a new instance based on the supplied HQMF entry
# @param [Nokogiri::XML::Element] entry the parsed HQMF entry
def initialize(entry)
@entry = en... | true |
de5cb136dd8d46ea9cf8ea79081e323c7bf77110 | Ruby | vinayngupta/airport_test | /spec/airport_spec.rb | UTF-8 | 601 | 2.78125 | 3 | [] | no_license | require 'airport'
describe Airport do
let(:airport) {Airport.new}
it 'has no planes' do
expect(airport).not_to have_planes
end
it 'has planes' do
airport = Airport.new [:plane]
expect(airport).to have_planes
end
it 'has no planes after taking off' do
expect(airport).not_to have_planes
end
it 'ca... | true |
f816cf6ec668ec251505f9c68c1ddf89036c7e6a | Ruby | miguel131299/hangman | /text_content.rb | UTF-8 | 1,849 | 3.53125 | 4 | [] | no_license | # frozen_string_literal: true
# Mofule used to save messages to be displayed to the user under certain conditions
module TextContent
def turn_message(message, tries = nil, guess = nil)
{
'game_start' => "The computer has chosen the codeword and now it's your turn to decipher it",
'prompt_user' => "Pl... | true |
def73db2640b8d1c82b9abb424c0331d30a9d257 | Ruby | ozPop/ttt-with-ai-project-wdf-000 | /lib/game_helpers.rb | UTF-8 | 1,254 | 3.453125 | 3 | [] | no_license | require 'pry'
def choose_start_order
decision = nil
until decision == "yes" || decision == "no"
puts "Do you want to go first? Yes or No"
decision = gets.chomp.downcase
if decision.downcase == "yes"
puts "You will go first, your token is X"
return players = {
:player1_token => "X",
... | true |
c18baa4dd3c709e406670d28bbe3e5d026206c07 | Ruby | hgsgtk/ruby-oop | /chapter8/02_has-many-part/bicycle.rb | UTF-8 | 573 | 2.953125 | 3 | [] | no_license | # Bicycle class は、継承の階層構造における抽象スーパークラス
# composition を用いるコードへと変更することを目的とする
#
# Bicycle class は、sparesメッセージへの応答責任がある、スペアパーツの一覧を返す
# 自転車 - パーツという関係
class Bicycle
# Parts オブジェクトを作る
# 部品の集合体を表す
# Bicycle have-a Parts
attr_reader :size, :parts
def initialize(args={})
@size = args[:size]
@parts = args[:par... | true |
d3316bb16e1efdadb974b21a6e8e5a22f0dc5db9 | Ruby | yousuvic/airspace-interview | /lib/address.rb | UTF-8 | 892 | 3.359375 | 3 | [] | no_license | require_relative 'geocoding'
class Address
attr_accessor :lat, :lng, :full_address
def getLocation(full_address)
@full_address = full_address
result = Geocoder.search(@full_address).first.data rescue ["Geocoder search failed in: getLocation"]
if result
@lat = result['latt'].to_f
@lng = re... | true |
6cd371b38ea93aba2318e9ffc5a552ee879828a8 | Ruby | leitongxue/huo_dong_tong | /app/models/display.rb | UTF-8 | 337 | 2.546875 | 3 | [] | no_license | class Display < ActiveRecord::Base
attr_accessible :user, :bid_name, :bid_phone, :bid_price, :success_status
def self.display(user,message)
Display.delete_all(:user => user)
if message !=nil
message.each do |activity|
new_activity = Display.new(activity)
new_activity.save
end
... | true |
01b237e56f7f0ba760325dcd214415195ce90d01 | Ruby | falqas/BEWD | /jonatan_schumacher/03_Collections_Loops/inclass_code/ex_teddit_hashes.rb | UTF-8 | 3,409 | 4.5625 | 5 | [] | no_license | # Step 1: Working with Arrays and Hashes
# Copy your solution from conditional_teddit.rb.
# Create an empty stories array. This will be used to hold all stories we capture.
# Users enter the story as they do now, but it gets put in a hash instead.
# Update any reference to the story (upvotes, category and title)
# ... | true |
da1023c1c2444af0590c4bc85f5010290a0a2c85 | Ruby | FF-Mercurial/Accelerator | /app/controller/Multicaster.rb | UTF-8 | 335 | 2.625 | 3 | [] | no_license | require 'socket'
class Multicaster
def initialize addr, port
@socket = UDPSocket.new
@socket.setsockopt :IPPROTO_IP, :IP_MULTICAST_TTL, 128
@addr = addr
@port = port
end
def write msg = ''
@socket.send msg, 0, @addr, @port
end
def close
@socket.clo... | true |
75d62df32da8ca1c1def25f56826b903525d91b3 | Ruby | DANIELROCHA1990/chordz_2021 | /key_chords/minor_key_chords.rb | UTF-8 | 522 | 2.703125 | 3 | [] | no_license | module Notes
class MinorKeyChord < KeyChord
MINOR_KEY_PATTERN = [1, 8, 9, 16, 22, 24, 30].freeze # T st T T st T T
def self.by_note(note)
minor_key_index = index_of_mode(note)
MINOR_KEY_PATTERN.map do |minor_key_interval| # Interacao com a classe Keys
minor_key_note_index = minor_key_ind... | true |
2aebd49ce5a368b4becea996204aec7cbaec3302 | Ruby | hitsumabushi/lingr_notifyer | /notify.rb | UTF-8 | 1,506 | 2.609375 | 3 | [] | no_license | require 'libnotify'
require_relative '.lib/lingr'
require_relative './setting'
# lingr の設定
lingr_conf = {
:user => Lingr_user,
:pass => Lingr_password,
:app_key => {},
# You don't have to modify, if you don't use app_key.
# Default : {}
:proxy => {}
# If you want to connect lingr via proxy.... | true |
9df586ccad5ededf632ad25bd14b31cdace17437 | Ruby | randalldfloyd/hyrax | /app/services/hyrax/custom_queries/find_file_metadata.rb | UTF-8 | 2,593 | 2.796875 | 3 | [
"Apache-2.0",
"AGPL-3.0-or-later"
] | permissive | # Provide custom queries for finding Hyrax::FileMetadata
# @example
# Hyrax.query_service.custom_queries.find_file_metadata_by(id: valkyrie_id)
# Hyrax.query_service.custom_queries.find_file_metadata_by_alternate_identifier(alternate_identifier: alt_id)
# Hyrax.query_service.custom_queries.find_many_file_metadata... | true |
14bc962af0a9d7cc61755bc3feeae6dd4e0f9a4f | Ruby | mattdp/mnemonic | /app/models/tag.rb | UTF-8 | 979 | 2.625 | 3 | [
"MIT"
] | permissive | # == Schema Information
#
# Table name: tags
#
# id :integer not null, primary key
# name :string(255)
# name_for_link :string(255)
# notes :text
# created_at :datetime
# updated_at :datetime
# event_id :integer
#
class Tag < ActiveRecord::Base
has_many :taggin... | true |
9299a483ce9bda53a6c757ff96a07655ce32caa6 | Ruby | camsys/transam_cpt | /app/reports/capital_needs_forecast.rb | UTF-8 | 1,288 | 2.515625 | 3 | [
"MIT"
] | permissive | class CapitalNeedsForecast < AbstractReport
# Include the fiscal year mixin
include FiscalYear
def initialize(attributes = {})
super(attributes)
end
def get_data_from_result_list(capital_project_list)
# Capital Needs by year
state_names = CapitalProject.state_names
a = []
... | true |
a31aaa14f924de468611540ee9c078b8b629f64b | Ruby | leouz/rsa-tool | /spec/models/rsa_spec.rb | UTF-8 | 2,263 | 2.875 | 3 | [] | no_license | require 'spec_helper'
test_inputs = [
{ p: 3, q: 13, n: 65, z: 48, e: 7, d: 55 }
# { p: 3, q: 11, n: 33, z: 20, e: 7, d: 3 }
]
test_inputs.each { |input|
describe Rsa do
c = Rsa.new
# before(:all) do
e_possibilities = c.get_e_possibilities input[:p], input[:q]
d = c.get_d input[:e]
# end ... | true |
9149204370be74d340e18278d65ea44bb0a94e19 | Ruby | GCorbel/Onopia | /lib/bank_reader/reader.rb | UTF-8 | 666 | 2.734375 | 3 | [] | no_license | module BankReader
class Reader
#Read a file with a driver and fill the records
def self.read(account)
driver = Driver.find_driver(account)
path = get_path(account)
driver.open_file(path)
driver.length.times do |line|
attributes = driver.read(line)
if account.records.... | true |
ff1a217f7f0302459db753561824159703748442 | Ruby | aumi9292/ruby_exercises | /procedural/intermediate/study_sessions_late_july.rb | UTF-8 | 1,636 | 4.03125 | 4 | [] | no_license | # frozen_string_literal: true
def accum(str)
str.upcase.chars.map.with_index { |letter, index| letter + letter.downcase * index }.join(' - ')
end
p accum('abcd') == 'A - Bb - Ccc - Dddd'
p accum('RqaEzty') == 'R - Qq - Aaa - Eeee - Zzzzz - Tttttt - Yyyyyyy'
p accum('cwAt') == 'C - Ww - Aaa - Tttt'
# study session ... | true |
fe36555a5c51c4b0f90a22e5f687c10310f43904 | Ruby | profprogrammeur/THC_KATAS-1_ruby | /3_caractère_milieu.rb | UTF-8 | 623 | 4.46875 | 4 | [] | no_license |
# You are going to be given a word.
# Your job is to return the middle character of the word.
# If the word's length is odd, return the middle character.
# If the word's length is even, return the middle 2 characters.
# Kata.getMiddle("test") should return "es"
# Kata.getMiddle("testing") should return "t"
# Kata.... | true |
bd339d2efa166afd768daa9b589c0f48de05c5f7 | Ruby | catedm/contacts-app | /contacts.rb | UTF-8 | 3,224 | 2.515625 | 3 | [] | no_license | require 'sinatra'
require "sinatra/reloader" if development?
require 'tilt/erubis'
require 'bcrypt'
require 'yaml'
require "sinatra/content_for"
require 'pry'
configure do
enable :sessions
set :erb, :escape_html => true
set :session_secret, 'secret'
end
before do
@root = File.expand_path("..", __FILE__)
se... | true |
91d08e00f8cdf708edfb3cda58dfb17b2e3d6da3 | Ruby | gulfstream15/MikeCasey_week02_day02_lab | /specs/bus_spec.rb | UTF-8 | 1,685 | 3.359375 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/emoji')
require_relative('../bus.rb')
require_relative('../bus_stop.rb')
require_relative('../person.rb')
class TestBus < Minitest::Test
# Good idea to have a setup method and
# refer to the @bus, @passenger, etc in code below
def set_up()
@bus = Bus.new(34, "Oc... | true |
cd0b0fea5fb69d2a588d31422f07d2de1211c1b0 | Ruby | jonathanpa/airinfos | /app/workers/pm25_importer.rb | UTF-8 | 1,653 | 2.5625 | 3 | [] | no_license | class Pm25Importer
def self.perform
mapping = { angers: [2], lemans: [3], nantes: [4, 5], saintnazaire: [6] }
now = DateTime.now.in_time_zone('Paris')
time_measure = DateTime.civil(now.year, now.month, now.day, now.hour)
yesterday = time_measure - 1.day
xls_source = "http://www.airpl.org/me... | true |
cade66b611ed9826e9d93ddc946026a99a91aa1f | Ruby | negatendo/twitter-toolz | /lib/delete_tweets.rb | UTF-8 | 1,087 | 2.921875 | 3 | [] | no_license | #!/usr/bin/env ruby
##
# iterate through your tweets and delete them alllllll
#
class DeleteTweets < MyCLIPart
def csvdelete(path)
# collect tweet ids from csv h
rownum = 0
ids = []
CSV.foreach(path, encoding: "utf-8") do |row|
if rownum != 0
ids << row[0]
end
rownum... | true |
004a6fcfdd76015c3b3fcdee0302e2f2d2c03a98 | Ruby | joshuaflanagan/austinrb_oct | /roman_numeral.rb | UTF-8 | 892 | 3.875 | 4 | [] | no_license |
module RomanNumeral
ORDER = { 1000 => "M",
900 => "CM",
500 => "D",
100 => "C",
90 => "XC",
50 => "L",
10 => "X",
9 => "IX",
5 => "V",
4 => "IV",
1 => "I"}
def to_roman
RomanNumeral.convert... | true |
f484f197d3a95f2df78af80d638a1755b4d39c87 | Ruby | liwii/rover_prover | /spec/lib/rover_prover/language/term/unification_term_spec.rb | UTF-8 | 2,871 | 3.046875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe UnificationTerm do
describe 'new' do
let (:x) { UnificationTerm.new('x') }
it 'has 0 as the time just after initialization' do
expect(x.time).to eq 0
end
end
describe 'free_variables' do
let (:x) { UnificationTerm.new('x') }
it 'returns empty array' do
... | true |
63142480168f5e83f3eb94cc8054a35f764ef30e | Ruby | andoniBO/Week-4 | /Day2/exercise/address_book/app/models/contact.rb | UTF-8 | 585 | 2.65625 | 3 | [] | no_license | class Contact < ActiveRecord::Base
validates :name, presence: true
validates :address, presence: true
validate :my_custom_validation
def self.get_all_contacts
all.order('lower(name) ASC')
end
def self.create_contact(contact)
contact.save
end
def self.find_by_id(id)
contact = find(id.to_i... | true |
2bac7bf59816cebe799eb3877fccf016e9a134a6 | Ruby | RodrigoRGRB/Codewars | /ucoder/1100.rb | UTF-8 | 116 | 3.328125 | 3 | [] | no_license | words = gets.strip.split
novo = words.map{|v| v.to_i}
if novo[0] == novo[1]
puts novo[0]
else
puts novo.max
end | true |
b3c2927b35df0090e900e7d71e1cd1b88b37840a | Ruby | strawberryjello/circlesoftware-apitest | /lib/tasks/csv_loader.rake | UTF-8 | 1,787 | 2.65625 | 3 | [] | no_license | require "benchmark"
require "csv"
namespace :csv do
desc "Load and parse csv files located in the data directory"
task :load => :environment do
Dir.chdir("data")
puts "Loading files in #{Dir.pwd}"
files = Rake::FileList["**/*.csv"]
puts files
elapsed_time = Benchmark.measure do
files.e... | true |
fcf1ac557d51b34e2f2380c6d78de2eb7f80ef38 | Ruby | Gerula/interviews | /LeetCode/roman_to_integer.rb | UTF-8 | 2,894 | 4.0625 | 4 | [
"MIT"
] | permissive | # Given a roman numeral, convert it to an integer.
#
# Input is guaranteed to be within the range from 1 to 3999.
#
class Fixnum
def self.roman_mapping
{
1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 => "C",
90 => "XC",
50 => "L",... | true |
6505fb62dd56a6e1144067814f602f19683ee194 | Ruby | gabynaiman/timing | /lib/timing/zone_offset.rb | UTF-8 | 1,070 | 3.0625 | 3 | [
"MIT"
] | permissive | module Timing
class ZoneOffset < TransparentProxy
REGEXP = /^([+-]?)(\d\d):?(\d\d)$/
def initialize(seconds)
raise ArgumentError, "#{seconds} is not a number" unless seconds.is_a? Numeric
super
end
def to_s(separator=nil)
"#{sign}#{hour.to_s.rjust(2, '0')}#{separator}#{minute.to_s... | true |
887bf4660458232e83c3bc3629a4961e9dfc0881 | Ruby | patricknikolaus/practice_ruby | /error.rb | UTF-8 | 937 | 4.15625 | 4 | [] | no_license | # puts "Hello!"
# greeting = gets.chomp
# if greeting == "Arrr!"
# puts "Go away, pirate."
# else
# puts "Greetings, hater of pirates!"
# end
# dickens = ["Charles Dickens", 1870]
# thackeray = ["William Thackeray", 1863]
# trollope = ["Anthony Trollope", 1882]
# hopkins = ["Gerard Manley Hopkins", 1889]
# def di... | true |
0f3a70cac86a6cb95fa4f5b5a5b31babb11cb3d2 | Ruby | jacobleesinger/w4d3 | /app/models/user.rb | UTF-8 | 1,268 | 2.6875 | 3 | [] | no_license | # require 'bcrypt'
class User < ActiveRecord::Base
# include BCrypt
attr_reader :password
validates :user_name, :password_digest, :session_token, presence: true
after_initialize :ensure_session_token
has_many(
:cats,
class_name: "Cat",
foreign_key: :owner_id,
primary_key: :id
)
#Class method ... | true |
8224c1a3e3ded921a577181f1494c7a297d679a0 | Ruby | pwnieexpress/msfrpc-simple | /lib/msfrpc-simple/client.rb | UTF-8 | 5,473 | 2.59375 | 3 | [
"BSD-3-Clause"
] | permissive | $:.unshift(File.expand_path(File.dirname(__FILE__)))
require 'msfrpc-client'
require 'features/framework'
require 'features/pro'
require 'module_mapper'
require 'timeout'
require 'logger'
module Msf
module RPC
module Simple
class Client
include Msf::RPC::Simple::Features::Framework
include... | true |
c786919bb6a3935f3870c8cee9bb393cdca8d0c5 | Ruby | ehedaoo/ascension | /lib/ascension/game/card.rb | UTF-8 | 7,061 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | class BadCardEquals < RuntimeError
end
module Card
module HonorEarned
attr_accessor :honor_earned
def honor_earned=(h)
@honor_earned = h
self.abilities << Ability::EarnHonor.new(:honor => h)
end
end
class << self
def dummy
Base.new(:name => "Dummy")
end
def all_cards_h... | true |
0effdc3c2ad4a0fceb19b4e9be9c6b5a3a380753 | Ruby | dustMason/blockchain | /lib/ledger.rb | UTF-8 | 661 | 3.078125 | 3 | [] | no_license | require_relative 'blockchain'
class Ledger
attr_reader :wallets
def initialize chain=[]
@wallets = {}
chain.each { |block| apply_transactions block.transactions if block.valid? }
end
def sufficient_funds? wallet, amount
return true if wallet == Blockchain::COINBASE
@wallets.has_key?(walle... | true |
9ce20aa6171b2218ec3e409fa371e0f47c1b6a81 | Ruby | yuanjianshi/xclarity_client | /lib/xclarity_client/connection/connection.rb | UTF-8 | 4,576 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require 'faraday'
require 'faraday-cookie_jar'
require 'uri'
require 'uri/https'
module XClarityClient
#
# Handles the LXCA connection providing some services to interact
# with the API.
#
class Connection
#
# @param [Hash] configuration - the data to create a connection with the LXCA
# @option c... | true |
9a6bc651841665d027f4464365ab6cb2bcf9a890 | Ruby | exarkun451/Course-Projects1 | /full_name_greet.rb | UTF-8 | 265 | 3.21875 | 3 | [] | no_license | puts "Please enter your first name!"
first = gets.chomp
puts "Please enter your middle name!"
middle = gets.chomp
puts "please enter your last name!"
last = gets.chomp
puts "Hello there, #{first} #{middle} #{last}! I am the matrix! You live inside me."
puts "Bye!" | true |
ddb0f4cd90eca3eab013000081c59bca47677489 | Ruby | asharbitz/moco | /lib/moco/ansi_escape.rb | UTF-8 | 532 | 2.796875 | 3 | [
"MIT"
] | permissive | module MoCo
module AnsiEscape
def self.bold(text)
escape(text, '1')
end
def self.bold_red(text)
escape(text, '1;31')
end
def self.green(text)
escape(text, '32')
end
def self.unescape(text)
text.gsub(/\e\[[\d;]+m(.*?)\e\[0*m/) do
block_given? ? yield($1)... | true |
1907210a9d24dc052bc7b64a943b3f01699ef991 | Ruby | keit1722/sort_algorithm | /test/sort_algorithm_test.rb | UTF-8 | 463 | 3.046875 | 3 | [] | no_license | # frozen_string_literal: true
require 'minitest/autorun'
require_relative '../lib/sort_algorithm'
class AortAlgorithmTest < Minitest::Test
def test_sort_algorithm
assert_equal [9, 15, 32, 38, 40], sort_algorithm([40, 38, 32, 9, 15])
assert_equal [3, 6, 12, 27, 31, 40, 49, 53], sort_algorithm([3, 40, 49, 12,... | true |
505b4b647a70e6960e7b986b320a840f4d707b88 | Ruby | SplashGordonMD/exercism | /hamming/hamming.rb | UTF-8 | 428 | 3.203125 | 3 | [] | no_license | module BookKeeping
VERSION = 3 # Where the version number matches the one in the test.
end
class Hamming
def self.compute(strand_1, strand_2)
if strand_1.length != strand_2.length
raise ArgumentError
end
count = 0
s1_array = strand_1.chars
s2_array = strand_2.chars
s1_array.each_with_... | true |
e54c49865b3c38aedb31c6cd38fc0c9d75699a16 | Ruby | purp/imdb | /lib/imdb/company.rb | UTF-8 | 342 | 2.734375 | 3 | [] | no_license | class IMDB
class Company
BASE_URL = "http://www.imdb.com/company/"
attr_accessor :id, :name
def initialize(*args)
if args[0].class == Nokogiri::XML::Element
args = [args[0]['href'].to_s.split('/')[-1], args[0].inner_text]
end
self.id = args[0];
self.name = args... | true |
c7aa8d3bf5dadeaabad82d863e5d9d23e76fb22f | Ruby | etdebruin/sdruby | /script/pulltwitterpics.rb | UTF-8 | 1,079 | 2.515625 | 3 | [] | no_license | #
# This script is meant to be run using 'rails runner script/pulltwitterpics.rb'
# which pulls as many pictures from twitter as they will send us and write urls
# to the database using the Photo model.
#
# Author: Etienne de Bruin <etdebruin@gmail.com>
# Date: 9/1/2012
#
# i <3 sdruby
#
require 'twitter'
module Twit... | true |
75b2f40b0e065f2480592c1e84a6323e636c8c13 | Ruby | Anthonyjy72/programming-univbasics-4-crud-lab-online-web-prework | /lib/array_crud.rb | UTF-8 | 1,048 | 3.96875 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def create_an_empty_array
[]
end
def create_an_array
colors = ["red", "green", "black", "gold"]
end
def add_element_to_end_of_array(array, element)
colors = ["red", "gold", "black"]
colors << "arrays!"
p colors
end
def add_element_to_start_of_array(array, element)
words = ["cool", "awesome"]
words.unsh... | true |
533c57fcf2018cd46cfce88d5ce9736b9fad386f | Ruby | kernkw/flix_tdd | /app/helpers/movies_helper.rb | UTF-8 | 144 | 2.921875 | 3 | [] | no_license | module MoviesHelper
def flop(movie)
if movie > 50000000
number_to_currency(movie)
else
movie = "Flop!"
end
end
end
| true |
fb634820990b0d7499904268906f22d3dbb69396 | Ruby | jeremywinters/arbol-midi | /lib/builder_node.rb | UTF-8 | 11,116 | 3.03125 | 3 | [] | no_license | # top level namespace
module Arbol
# base class for all builder classes
class BuilderNode
# reference to parent object
attr_accessor :parent
# array of child expressions referring to this parent
attr_accessor :expressions
# reference to the current object being built
attr_accessor :current... | true |
07b0778dc96de5c041fc6238aadafd67eb89785a | Ruby | solid5nake/status-quo | /lib/status_quo/resource.rb | UTF-8 | 577 | 2.75 | 3 | [
"MIT"
] | permissive | require "status_quo/resource/segment"
module StatusQuo
class Resource
def initialize(identifier, &block)
@identifier = identifier
instance_exec &block if block_given?
end
def identifier
@identifier
end
def segments
@segments ||= []
end
def segment(identifier, &... | true |
f9d1538fb6b314bfd17e83f5aa2aeb61ae14e55e | Ruby | adrian-sal-kennedy/git-challenge | /index.rb | UTF-8 | 354 | 3.390625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'faker'
require 'colorize'
def hello_world
data = {
name: Faker::Name.name,
address: Faker::Address.full_address
}
puts "Hello world".colorize(color: :black, background: :light_white)
puts "I'm #{data[:name]} and I live at #{data[:address]}".colorize(color: :black, backgrou... | true |
a0bec733f03487a1d4a8b691830c53c3aa2805f5 | Ruby | learn-co-students/Seattle-web-012720-DSA | /05-compress-the-string/solution.rb | UTF-8 | 903 | 3.90625 | 4 | [] | no_license | # lief's iterative version
def str_compress_iterative(str)
start = str[0]
count = 1
output = String.new
str.chars.each {|char|
if output[-1] == char && char != start
count += 1
else
output << count.to_s
count = 1
output << char
end... | true |
a8e7403c3e58039e84f1c8c1b125ec833e5d23bf | Ruby | EvilScott/dieroll | /bin/dieroll | UTF-8 | 669 | 2.921875 | 3 | [] | no_license | #!/usr/bin/env ruby
# Dice rolling program
# by Brian Towle -- March 2012
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'dieroll'
require 'optparse'
usage_string = "Usage: roll [-r] <roll-string>"
options = {}
OptionParser.new do |opts|
opts.banner = usage_string
options[:results] = false... | true |
07fb84cadc0b11e06e31a0a72fd975df76910043 | Ruby | rhogotargaryen/oo-student-scraper-v-000 | /lib/scraper.rb | UTF-8 | 2,261 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'open-uri'
require 'pry'
require 'nokogiri'
class Scraper
def self.scrape_index_page(index_url)
doc = Nokogiri::HTML(open(index_url))
student_hashes = []
studs_links = doc.css(".student-card a")
studs_links.each do |stud_link|
stu = {}
stu[:name] = stud_link.css("h... | true |
2168bb6ba7deb18ca5e623bd5920781f70c7d84c | Ruby | jronallo/linter | /lib/rdf/linter/extensions.rb | UTF-8 | 872 | 2.71875 | 3 | [
"Unlicense",
"LicenseRef-scancode-public-domain"
] | permissive | require 'rdf'
require 'tsort'
# Allow graph to be topologically sorted
class RDF::Graph
include TSort
alias_method :tsort_each_node, :each_subject
##
# Reverse this, as we want reverse dependency order
def tsort_each_child(node, &block)
query(:object => node) do |statement|
block.call(stateme... | true |
5201fa819bcca8474b8561c0a76be100e75a109b | Ruby | tiy-indy-bee-ror-sept16/course-notes | /week2/day1/thing.rb | UTF-8 | 739 | 3.21875 | 3 | [] | no_license | require 'erb'
thing = ARGV[0].to_s.downcase
puts ARGV.inspect
puts thing.inspect
if thing.start_with? "h"
output = "Hello"
elsif thing.start_with? "k"
output = "Karate Kid, \"Part 2\""
elsif thing[-1] == "r"
output = "This is an R-ending word"
else
output = "I don't understand that."
end
big_12_teams = ["I... | true |
9380df82e080e3bc02831c02a9051d07b889cdad | Ruby | HeatherRB/gcd | /gcd.rb | UTF-8 | 695 | 4.25 | 4 | [] | no_license | # Heather Reeve-Black
# May 2014
# Program for finding the gcd of two integers
# get the user input
puts "This program finds the greatest common divisor of two numbers, using Euclid's algorithm."
print "Please enter two positive integers (separated by a space): "
number_string = gets.chomp
# separate the input into t... | true |
02cb637c2c90a5479434d0c0891e3e803d68ba01 | Ruby | ruby/typeprof | /smoke/ivar4.rb | UTF-8 | 259 | 2.65625 | 3 | [
"MIT"
] | permissive | def foo
bot = @undefined_ivar
unless bot
bot.nil?
end
end
foo # There were a bug that type profiling is terminated at this line
def bar
end
__END__
# Classes
class Object
@undefined_ivar: bot
private
def foo: -> true
def bar: -> nil
end
| true |
80cd939e6ea0852204b65f06d23c24c0ca6517ed | Ruby | bhyvex/mccloud | /bin/mccloud | UTF-8 | 599 | 2.5625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'mccloud'
begin
# Disable color if the proper argument was passed
shell = ARGV.include?("--no-color") ? Thor::Shell::Basic.new : Thor::Base.shell.new
# Start the CLI
begin
env = Mccloud::Environment.new(:cwd => ".")
# # Attach the UI
env.ui = ::Mccloud::UI::Shell.ne... | true |
fe615b8f372f79348d66924091898258a3a92074 | Ruby | internetAaron/notes0 | /algorithms-phonenumbers/ranges2numbersarr.rb | UTF-8 | 557 | 3.421875 | 3 | [] | no_license | def ranges2numbersarr(ranges)
result = []
for i in ranges.split(';')
if i.include? "-" then
range = i.split('-')
number = range[0].to_i
until number > range[1].to_i
result << number
number = number + 1
end
else
result << i.to_i
end
end
result... | true |
1f4cceaf6de7fcded78f1f8767e3f697639e7039 | Ruby | davekinkead/barton-old | /spec/barton_spec.rb | UTF-8 | 946 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'barton'
describe Barton do
describe 'Constants' do
before do
@states = ['Queensland', 'New South Wales', 'Victoria', 'Australian Capital Territory', 'Tasmania', 'South Australia', 'Western Australia', 'Northern Territory']
end
it "should return all states" do
Barton::STATES.each... | true |
ba00129e57722775fbf2b37adf3dc0b039f3a053 | Ruby | cfoust/leetcode-problems | /problems/remove-duplicate-letters/solution.rb | UTF-8 | 83 | 2.609375 | 3 | [] | no_license | # @param {String} s
# @return {String}
def remove_duplicate_letters(s)
end | true |
8cd2d6892739ae609045302eab72bf56cf1ea36e | Ruby | lenriquez/Programing-Problems | /next_permutation/generate_next_permutation.rb | UTF-8 | 1,341 | 3.921875 | 4 | [] | no_license | #/usr/bin/env ruby
def generate_next_permutation(list)
# Deal with lists of zero length or empty lists
if list.length <= 1
return false
end
# Start from the second last element
i = list.length - 2
# Go backwards and find the first element which is
# less th... | true |
b4c030c0cf042429adec684fab49f13bac6c22bf | Ruby | momajd/ruby-js-algorithms | /Ruby/trees/lib/bst_sequences.rb | UTF-8 | 1,479 | 3.828125 | 4 | [] | no_license | # CCI 4.9 - BST Sequences
# see solution for good analysis on time complexity
class Node
def initialize(val)
@val = val
@left, @right = nil, nil
end
attr_accessor :val, :left, :right
end
# Simple approach - builds a string and checks inclusion
# O(n + m) time, O(n + m) space
def pre_order_values(root, o... | true |
a534a752cb48b593457de3d7f5c97e9b0f8ca738 | Ruby | ltrainor1/operators-v-000 | /lib/operations.rb | UTF-8 | 212 | 3.046875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def unsafe?(speed)
if speed > 60 || speed < 40
return true
else
return false
end
end
def not_safe?(speed)
too_fast = speed > 60
too_slow = speed < 40
too_fast || too_slow ? true : false
end
| true |
70160c63d22cd3cd1cda50f0610c0aa34d06136d | Ruby | ZoeThorne/ironhack-ruby | /Week 2/Day 5/Movie Quiz/spec/quiz_spec.rb | UTF-8 | 341 | 2.828125 | 3 | [] | no_license | require_relative("../models/quiz.rb")
RSpec.describe Quiz do
let(:quiz) { Quiz.new}
it "should search for a movie based on a given word" do
expect(quiz.search("funny")).to be_truthy
end
it "should store the first nine movies from a search" do
quiz.search("funny")
quiz.add_movies
expect(quiz.movies.length... | true |
b30e69b148739f305168de67190c0066e3d17f7e | Ruby | colinwarmstrong/denver_public_library | /test/author_test.rb | UTF-8 | 1,044 | 2.96875 | 3 | [] | no_license | require './test/test_helper'
require './lib/library.rb'
require './lib/author.rb'
class AuthorTest < Minitest::Test
def test_authors_exits
charlotte_bronte = Author.new({first_name: "Charlotte", last_name: "Bronte"})
assert_instance_of Author, charlotte_bronte
end
def test_authors_are_initialized_with... | true |
8510e97ac3f1352e88518633881322a62c882667 | Ruby | davidas1798/P9-Documentation | /lib/p6/list.rb | UTF-8 | 1,740 | 3.671875 | 4 | [] | no_license | Node = Struct.new(:value, :next, :prev)
class List
include Enumerable
attr_accessor :size, :head, :tail
def initialize()
@size = 0
@head = nil
@tail = nil
end
def push(item)
item = Node.new(item, nil, nil)
if(empty)
@tail = item
item.next = nil
else
head.prev = item
item.next = @head
... | true |
3ce00592b70a4e004b7b0c08a7779a508ecb8f0c | Ruby | DaviRibs/A180 | /code4testers/loops.rb | UTF-8 | 245 | 3.140625 | 3 | [] | no_license |
# i = 1
# 10.times do
# puts "Execução número #{i}"
# i = i + 1
# end
bandas = ["Aerosmith", "Só pra contrariar", "Claudinho e Bucheca", "Megadeth"]
# i = 0
# bandas.size.times do
# puts bandas[i]
# i = i + 1
# end
bandas.each do |banda|
puts banda
end | true |
2be7bacda348f5fbb301ac7d39be06554b219490 | Ruby | grange-book-club/eloquent-ruby | /chapter_19/airship_script.rb | UTF-8 | 345 | 2.515625 | 3 | [] | no_license | require './Airship_class.rb'
require './location_class.rb'
include Location
my_airship = AirShip.new
at "location1" do
my_airship.fill_tank
my_airship.travel_to("location2")
end
at "location2" do
my_airship.go_adventuring
my_airship.travel_to("location3")
end
at "location3" do
my_airship.... | true |
0038488fe75d8fddf55153c6f1f751b231887a97 | Ruby | helloimiskra/speaking-grandma-online-web-prework | /grandma.rb | UTF-8 | 206 | 2.890625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | if grandma == "shout".upcase
puts "NO, NOT SINCE 1938!"
elsif grandma == "I LOVE YOU GRANDMA!".upcase
puts "I LOVE YOU TOO PUMPKIN!"
else grandma == "say".downcase
puts "HUH?! SPEAK UP, SONNY".upcase
| true |
101d22e4fe32975463610b3640b8b854a904d49f | Ruby | ngeballe/ls101 | /lesson_2_small_programs/mortgage calculator/mortgage_calculator.rb | UTF-8 | 1,623 | 3.46875 | 3 | [] | no_license | require 'pry'
require 'yaml'
MESSAGES = YAML.load_file('mortgage_calculator_messages.yml')
def prompt(message)
puts "=> #{message}"
end
def valid_number?(s)
/\d/.match(s) && /^\d*\.?\d*$/.match(s)
end
def monthly_payment(loan_amount, monthly_interest_rate, loan_duration_months)
loan_amount * monthly_interest_r... | true |
400f0a85ee3d0562087a7c836ea8e9a2e68435dc | Ruby | learn-co-students/chicago-se-031521 | /05-oo-relationship-has-many-to-many/run.rb | UTF-8 | 475 | 2.640625 | 3 | [] | no_license | require 'pry'
require_relative 'models/doctor'
require_relative 'models/patient'
require_relative 'models/appointment.rb'
doctor1 = Doctor.new("Dre", "Beats", "Northwestern")
doctor2 = Doctor.new("Octavious", "Spiderman", "Saint Mary's")
patient1 = Patient.new("Susan", "12")
patient2 = Patient.new("Peter", "24")
a... | true |
6945815c36766f18ed7159d6b96b5f3f3c06d302 | Ruby | chelseylin/phase-0-tracks | /ruby/vampires.rb | UTF-8 | 1,803 | 4.28125 | 4 | [] | no_license | #Ask for number of employees to process:
puts "Please input how many employees you want to process:"
number = gets.chomp.to_i
#Use while loop to process each employee
while number != 0
result = "Results inconclusive."
#Get Name
puts "What is your name?"
name = gets.chomp
#Get Age and YOB
puts "How old ar... | true |
afe3a3181390ea63e6980424a0222e8ab6e14d2d | Ruby | AliceArmstrong/bank | /spec/atm_spec.rb | UTF-8 | 486 | 3.125 | 3 | [] | no_license | require 'atm'
require 'bank_account'
describe Atm do
bank_account = BankAccount.new
atm = Atm.new
it "can deposit into balance count" do
atm.deposit(5)
expect(atm.deposit(5)).to eq(10)
end
it "can withdraw from balance count" do
expect(atm.withdraw(5)).to eq(5)
end
it... | true |
0be7cd5d124aba7566b3878686981065e706be89 | Ruby | davidtadams/advent-of-code | /2021/10/part1.rb | UTF-8 | 696 | 3.203125 | 3 | [] | no_license | # frozen_string_literal: true
scores = { ')' => 3, ']' => 57, '}' => 1197, '>' => 25_137 }
open_chars = ['(', '[', '{', '<']
open_to_close = { '(' => ')', '[' => ']', '{' => '}', '<' => '>' }
illegal_chars = { ')' => 0, ']' => 0, '}' => 0, '>' => 0 }
ARGF.each_line(chomp: true) do |line|
open_chars_stack = []
lin... | true |
8981416d5c9db0178f8b5296e914eb50ecc32288 | Ruby | gregxsunday/ruby | /lab1/domowe/test.rb | UTF-8 | 826 | 2.953125 | 3 | [] | no_license | require 'minitest/autorun'
load 'main.rb'
# Tests
class TestSum < MiniTest::Test
def setup
@result1 = sum(2, 2)
@result2 = sum(2, 1.5)
@result3 = sum(2, '2')
@result4 = sum('2.1', '2.0')
@result5 = sum('2/3', '1/6')
@result6 = sum('3-5i', '2+4i')
end
def test_sum_integer_integer
asse... | true |
d71b79fe47c0c3e0f1adc7ec946a44c6c6fe4f53 | Ruby | imwithsam/web_guesser | /web_guesser.rb | UTF-8 | 1,023 | 3.40625 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
def reset_game
@@guesses_remaining = 5
@@secret_number = rand(100)
end
def lost_game
reset_game
" You lost. A new number has been generated."
end
def check_guess(guess, secret_number)
if guess
if guess.to_i > (secret_number + 5)
@@guesses_remaining -= ... | true |
63cb805cdc82ec9cc5d800f0cec51e291d3fa7e1 | Ruby | dqmrf/dive-in-ruby | /sandbox/hashes/built_in_methods/invert.rb | UTF-8 | 364 | 3.75 | 4 | [] | no_license | h = { 1 => "one", 2 => "two" }
print h.invert; puts "\n" #=> {"one"=>1, "two"=>2}
# Be careful when you invert hashes. Because hash keys are unique, but values aren’t,
# when you turn duplicate values into keys, one of the pairs is discarded:
h = { 1 => "one", 2 => "more than 1", 3 => "more than 1" }
print h.invert; p... | true |
9dcba2f12e9433a93fcfb85513923add7d8bc562 | Ruby | Strompy/battleship | /test/board_test.rb | UTF-8 | 3,401 | 3.265625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/board'
require './lib/ship'
require './lib/cell'
class BoardTest < Minitest::Test
def setup
@board = Board.new
@cruiser = Ship.new("Cruiser", 3)
@submarine = Ship.new("Submarine", 2)
end
def test_it_exists
assert_instance_of Boa... | true |
d135239821541a3b143b19560aece1198aedd72c | Ruby | Nerajno/many-to-many-through-event-ticket-attendee | /many-to-many-through-event-ticket-attendee/app/models/event.rb | UTF-8 | 1,226 | 3.5 | 4 | [] | no_license | require "pry"
class Event
attr_reader :name, :total_cost, :ticket_price
@@all = []
def initialize(name, total_cost, ticket_price)
@name = name
@total_cost = total_cost.to_i
@ticket_price = ticket_price.to_i
@@all << self
end
def self.all
@@all
end
... | true |
9e0246cacd236dca54752cb8e98e3538ff53542b | Ruby | essian/LS-Programming-and-Back-end-Development | /120_Object_Oriented_Programming/twenty_one.rb | UTF-8 | 5,267 | 4.03125 | 4 | [] | no_license | # frozen_string_literal : true
module Display
def welcome
clear
puts "Welcome to twenty one!"
end
def clear
system('clear') || system('cls')
end
def press_a_key
puts "Hit enter to continue..."
gets
end
def show_dealing
sleep 1
puts '...dealing'
sleep 1
end
def show... | true |
ce95f62106b3a480ed485577b11f7c24ca6e7ea2 | Ruby | SciRuby/iruby | /test/iruby/event_manager_test.rb | UTF-8 | 2,273 | 2.703125 | 3 | [
"MIT"
] | permissive | module IRubyTest
class EventManagerTest < TestBase
def setup
@man = IRuby::EventManager.new([:foo, :bar])
end
def test_available_events
assert_equal([:foo, :bar],
@man.available_events)
end
sub_test_case("#register") do
sub_test_case("known event name") do
... | true |
7abc68e12c9c777b2a7dfed7284245af55b698fa | Ruby | gghatano/pwscup2018sample | /check-f1/check-f1.rb | UTF-8 | 1,092 | 2.953125 | 3 | [] | no_license | # coding: utf-8
# 概要: T, A' が正しい前提で F' の書式を確認
# 入力: J(T, A', F')
# 出力:
# 正しければ何もなし
# 正しくなければ標準エラーにエラーメッセージを吐いてエラー終了
require './common-io.rb'
# IDの集合を取り出す
def to_ids(t)
h = {}
t.each{|line| h[line.split(/,/)[0]] = true}
return h
end
# エラーメッセージを吐いて終了
def error(i, msg = '')
raise "Line #{i}: #{msg}"
end
#... | true |
2a251d2cf394184811507417fcfc6af8ba589fbd | Ruby | ramonlg/octo_search | /app/services/github/repos_search_service.rb | UTF-8 | 653 | 2.546875 | 3 | [] | no_license | require 'net/http'
require 'builders/github/uri_query_builder'
require 'json_parsers/github/repos_search_parser'
module Github
class ReposSearchService < ApplicationService
def call
response = Net::HTTP.get_response(uri)
parse_items(response.body)
end
private
attr_reader :params
de... | true |
36a03c5c140ffaf7f4b5fc5a4b947c98bde38221 | Ruby | yangchuanosaurus/RemoteDataCli | /lib/command.rb | UTF-8 | 1,558 | 2.90625 | 3 | [
"Apache-2.0"
] | permissive | require_relative 'handler_new'
require_relative 'handler_add_action'
require_relative 'handler_run'
require_relative 'handler_run_all'
module RemoteDataCli
RemoteDataCli::Accept_commands = {
"new" => "RemoteDataCli::Creator",
"add_action" => "RemoteDataCli::AddAction",
"run_action" => "RemoteDataCli::R... | true |
b599380dd4d16cc1926e98ab4aa1b84880334f37 | Ruby | StyvenSoft/Learn-Ruby | /2_ControlFlow/14-BillionsOfBooleans.rb | UTF-8 | 254 | 3.265625 | 3 | [
"MIT"
] | permissive | ( 1 == 1 ) && ( 2 == 2 ) # true
( 1 == 2 ) || ( 2 == 2 ) # true
!( false ) # true
# test_1 should be true
puts test_1 = (3 == 3) || (4 != 5)
# test_2 = should be true
puts test_2 = (5 > 3) && (7 < 10)
# test_3 = should be false
puts test_3 = (5 != 5) | true |
3862a8761af104eebef06f04f8a03a35e9cb4761 | Ruby | dqh725/game | /lib/command.rb | UTF-8 | 3,975 | 3.703125 | 4 | [
"MIT"
] | permissive | require_relative "constants"
# Execution module defined [place, move, left, right, report] mothod which
# can be extended into command object to do the operation with robot
# this module is open for expanding new command ...
module Execution
# move command
def move
case
when @robot.face == "north" && @... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.