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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
be4042d989ae48f1f2f4d370c9d70037c0b7d87c | Ruby | jenshaw86/ruby-class-variables-and-class-methods-lab-seattle-web-051319 | /lib/song.rb | UTF-8 | 1,263 | 3.90625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class Song
attr_accessor :name, :artist, :genre
@@count = 0
@@genres = []
@@artists = []
def initialize(name, artist, genre)
@name = name
@artist = artist
@genre = genre
@@count += 1
@@genres << genre
@@artists << artist
end
def self.count
... | true |
e98adbb7618ddd82fa6b1c0cee1b40ea6ff2d0c9 | Ruby | umaibow/rails_tutorial | /sample_app/app/controllers/users_controller.rb | SHIFT_JIS | 2,072 | 2.625 | 3 | [] | no_license | class UsersController < ApplicationController
#ҏWOɃOCmF
before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
#[UmF
before_action :correct_user, only: [:edit, :update]
#Ǘ҂mF
before_action :admin_user, only: :destroy
def index
@users = User.paginate(page: params[:page])
end
def new
@... | true |
4895b1130dfccb2b32ad5a2053538e1bebe5fd63 | Ruby | dojomaringa/dojo_20121123 | /gerador_expressoes.rb | UTF-8 | 675 | 3.5625 | 4 | [] | no_license | class GeradorExpressoes
def self.sei(abre, fecha, expressao)
resultado = ""
expressao.split.each_with_index do |word, index|
resultado << " " unless index == 0
if index == abre
resultado << "("
end
resultado << word
if index == fecha
resultado << ")"
end
end
resultado
end
... | true |
e04c8cdf21563fca25de9f1dd1a8fb5f14676058 | Ruby | sienatime/jmdict-rails | /app/models/dictionary_parser.rb | UTF-8 | 328 | 2.640625 | 3 | [] | no_license | class DictionaryParser
def initialize(file_name)
# Create a new parser
puts "Deleting all Entries and Senses"
Entry.delete_all
Sense.delete_all
handler = OgaSax.new
Oga.sax_parse_xml(handler, File.open(file_name))
puts "Entry.count: #{Entry.count}"
puts "Sense.count: #{Sense.count}"
... | true |
a1395000439332baac8a8e4590e382981dedade5 | Ruby | NicholasJacques/black_thursday | /test/customer_repository_test.rb | UTF-8 | 1,788 | 2.703125 | 3 | [] | no_license | require './test/test_helper'
class TransactionRepositoryTest < Minitest::Test
include CsvParser
attr_reader :parent
def setup
@parent = SalesEngine.from_csv({:customers => './test/fixtures/customer_three.csv'})
end
def test_it_exists
data = open_file("./test/fixtures/customer_three.csv")
cr... | true |
08b1cf854cd1ad42a1aa8656072b7157744d001b | Ruby | tolentinoel/programming-univbasics-4-simple-looping-lab-sfo01-seng-ft-100520 | /lib/simple_loops.rb | UTF-8 | 592 | 4.21875 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Write your methods here
message_string = "Howdy!"
def loop_message_five_times(message_string)
puts message_string
puts message_string
puts message_string
puts message_string
puts message_string
end
def loop_message_n_times (string, num)
count = 0
while count < num do
puts string
count += 1
end
end
de... | true |
c48461658b1dc457835ae83ed777786225abb1aa | Ruby | Dancalif/Learning-Ruby | /TA/HW_18/script_18_03.rb | UTF-8 | 318 | 4.03125 | 4 | [] | no_license | #Display result both conditions of the logical operator '&&' using the 'a' and 'b' variables
a = 10
b = 3
if a == 10 && b == 3
puts "Correct"
else
puts "Incorrect"
end
if a == 3 && b == 10
puts "Correct"
else
puts "Incorrect"
end
if a == 5 && b == 3
puts "Correct"
else
puts "Incorrect"
end | true |
6d528e5b91a81daf8dbb916ede5f419dff184069 | Ruby | leonmezu1/Enumerables | /spec/enumerable_spec.rb | UTF-8 | 7,405 | 3.671875 | 4 | [
"MIT"
] | permissive | # frozen_string_literal: true
require './enumerable.rb'
RSpec.describe 'Enumerables' do
let(:unitary) { [1] }
let(:arr0) { [0, 0, 1] }
let(:arr1) { [1, 2, 3, 4, 5] }
let(:arr2) { [true, 'all', 'string', 0.2, 0.578, 'max'] }
let(:arr3) { %w[word again a word] }
let(:arr4) { [true, false] }
let(:arr5) { (... | true |
948e52863287715c7fbec1ede7c38b1b75c3de59 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/robot-name/e3755f031de44af4a40848f434337c9b.rb | UTF-8 | 1,102 | 3.5625 | 4 | [] | no_license | class Robot
require 'set'
attr_reader :name
START_OF_ASCII_CAPS = 65
LETTERS = 26
@@names_generated = Set.new
def initialize
reset
end
def reset
generate_name
if @@names_generated.include? @name
reset
else
@@names_generated << @name
end
end
private
def ge... | true |
2effc3e12ab659fba67537da4b29014198cf0e66 | Ruby | IndicoDataSolutions/IndicoIo-ruby | /lib/indico/settings.rb | UTF-8 | 3,268 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'inifile'
require_relative 'version'
HEADERS = { 'Content-Type' => 'application/json',
'Accept' => 'application/json',
'client-lib' => 'ruby',
'version-number' => Indico::VERSION }
# APIS
TEXT_APIS = [
"political",
"sentiment",
"sentiment_hq",
"language",
"text_tag... | true |
491235fb704ada9cef251beb80c269731e7e6fed | Ruby | fraserbrookhouse/student-directory | /directory.rb | UTF-8 | 2,894 | 4.125 | 4 | [] | no_license | @students = [] #empty array accessible to all methods
#main program loop, gives menu options then runs selection
def interactive_menu
loop do
print_menu
#get user input
process(STDIN.gets.chomp)
end
end
#prints menu options
def print_menu
puts "What would you like to do?"
puts "1. Input the studen... | true |
2956d57290b1b9c0a6c80670902b435d4398ec60 | Ruby | phuongnd08/Giasu-iOS | /app/views/card_view.rb | UTF-8 | 709 | 2.53125 | 3 | [] | no_license | class CardView < UIView
attr_accessor :card
def card=(c)
p "set card in carview"
@card = c
p @card
@chains = @card[:structure][:chains]
addUIComponents
end
def addUIComponents
self.subviews.map { |view| view.removeFromSuperview }
@chains.each_with_index do |chain, chain_idx|
... | true |
2b929248bdaca77c48505b24480070a79bebf3da | Ruby | fsetiawan29/app-news | /app/services/topic_delete_service.rb | UTF-8 | 412 | 2.5625 | 3 | [] | no_license | class TopicDeleteService
attr_reader :topic, :repository
def initialize(topic, repository = TopicRepository.new)
@topic = topic
@repository = repository
end
def call
if repository.delete(topic)
return { error: false, message: 'Data has been deleted successfully', status: 200 }
else
... | true |
1d0e0bef8700106007d4b30c482020c8aefb4ca6 | Ruby | stovermc/black_thursday | /test/invoice_repository_test.rb | UTF-8 | 1,277 | 2.765625 | 3 | [] | no_license | require './test/test_helper'
class InvoiceRepositoryTest < Minitest::Test
attr_reader :ir, :invoices, :invoice_1, :invoice_2, :invoice_3
def setup
@invoice_1 = Invoice.new(id:"2", customer_id:"1", merchant_id:"12334753", status:"shipped", created_at:"2012-11-23", updated_at:"2013-04-14")
@invoice_2 = Inv... | true |
25a6564655db1e9b537c00f1c315f24a54bd4ece | Ruby | Linzeur/codeable-exercises | /week-3/day-2/vale/AlphabetWar.rb | UTF-8 | 761 | 3.953125 | 4 | [] | no_license | def alphabet_war(fight)
@left_side = {
w: 4,
p: 3,
b: 2,
s: 1
}
@right_side = {
m: 4,
q: 3,
d: 2,
z: 1
}
winner(fight)
end
def leftie(fight)
splitted = fight.split("")
left = splitted.map { |x| @left_side[x.to_sym] }
left.c... | true |
b6aee39a3b161b9197027e26c026984245dd6e76 | Ruby | madking55/LearnToCodeWithRuby | /Getting_Started/The_puts_method.rb | UTF-8 | 239 | 3.71875 | 4 | [] | no_license | puts "I'm alive and well"
puts "Hello Ruby"
puts "I made $65 dollars or a profit of 25%! "
puts 5
puts 5.23456
puts 4 + 3
puts "4" + "3"
puts 4 + "3" # Error: String can't be coerced into Integer
puts
puts
puts "Two line breaks above"
| true |
1395e384e6195ca4a9df46e8f88c1e70d45cee54 | Ruby | kingsleyh/woot | /authentication/repository/sessions.rb | UTF-8 | 678 | 2.578125 | 3 | [] | no_license | require_relative '../repository/repository'
require_relative '../model/session'
class Sessions
def self.create(user_id, session_id, start_time, ip_address, user_agent, login_method)
Repository.instance.records.add(Session.def, sequence(Session.new(user_id, session_id, start_time, ip_address,
... | true |
5a90b3cdcc4abba86fca04489e984fa1f9ebd176 | Ruby | markfranciose/drops_of_knowledge | /ruby/%qs.rb | UTF-8 | 339 | 3.578125 | 4 | [
"MIT"
] | permissive | # %Q acts like a double quote delimiter
percent_Q = %Q("This is a string" and it can include double quotes without escaping)
# useful if you have a string with double quote marks.
puts percent_Q
# %q does the same for single quotes
single_quotes = %q('this is a string' and it can include quotes without escaping)
p... | true |
f6764f46ecb15042bac4df478e845aa35726c852 | Ruby | nmking22/Enigma | /test/encryption_test.rb | UTF-8 | 3,670 | 3.234375 | 3 | [] | no_license | require './test/test_helper'
require './lib/encryption'
require 'mocha/minitest'
require 'mocha/setup'
class EncryptionTest < Minitest::Test
def test_it_exists
encryption = Encryption.new("Hello World", "12345", "040520")
assert_instance_of Encryption, encryption
end
def test_it_has_readable_attributes... | true |
9f774c057b8a61ad529adf2f7180c18858312d57 | Ruby | kaji-hiro/AtCoder_beginner_contest | /ABC183/C-Travel.rb | UTF-8 | 310 | 2.84375 | 3 | [] | no_license | n, k = gets.split.map(&:to_i)
t = [0]
ans = 0
n.times do |n|
t[n] = gets.split.map(&:to_i)
end
(1..n-1).to_a.permutation(n - 1).each do |comb|
comb.push 0
sum = 0
l_index = 0
comb.each do |i|
sum += t[l_index][i]
l_index = i
ans += 1 if sum == k
break if sum > k
end
end
puts ans
| true |
de5ba74d48a0e06fb44a518d93180eeafc453671 | Ruby | Crunch09/lastme | /lib/lastme/connection.rb | UTF-8 | 1,080 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'net/http'
require 'json'
module Lastme
class Connection
def fetch_token
params = {
'api_key' => ENV['LASTME_API_KEY'],
'method' => 'auth.gettoken'
}
response = request params
response['token']
end
def fetch_session
params = {
'method' => 'a... | true |
895e9c1408bd5b2a27c1863cf456d69abe0967ec | Ruby | chitasan/Enigma | /lib/date_offset.rb | UTF-8 | 435 | 2.984375 | 3 | [] | no_license | require './lib/generator'
module DateOffset
include Generator
def squared_date_last_four(date)
date_squared = date.to_i ** 2
date_squared.digits.reverse.last(4)
end
def date_offsets(date)
last_four = squared_date_last_four(date)
date_offsets_hash = {}
offsets_hash_keys.each_with_index ... | true |
54cc2791a895c8c7fe50473094ae8662af2a69d4 | Ruby | sbraford/rbet | /lib/et/list.rb | UTF-8 | 4,675 | 2.53125 | 3 | [
"MIT"
] | permissive | #
# Copyright (c) 2007 Todd A. Fisher
#
# Portions Copyright (c) 2008 Shanti A. Braford
#
# 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 t... | true |
910d24ba042914e26422e4d5b1cf6ea8fcd955dd | Ruby | epang1/rps-game-app-001 | /models/rps_game.rb | UTF-8 | 917 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class RPSGame
attr_accessor :type
def initialize(type)
if type != :rock && type != :paper && type != :scissors
raise self.class::PlayTypeError
end
@type = type
end
class PlayTypeError < StandardError
end
def self.valid_play?(type)
if type == :rock || type == :paper || type == :sc... | true |
d253e1185c9c7b433a336e40e8e62831876fdec8 | Ruby | mheshmati-tech/oo-ride-share | /lib/driver.rb | UTF-8 | 1,836 | 3.359375 | 3 | [] | no_license | require 'csv'
require_relative 'csv_record'
module RideShare
class Driver < CsvRecord
attr_reader :id, :name, :vin, :status, :trips
VALID_STATUSES = [:AVAILABLE, :UNAVAILABLE]
def initialize(id:, name:, vin:, status: :AVAILABLE, trips:[])
super(id)
@name = name
raise(ArgumentError... | true |
b1e4e046fdbd172b116e2e2b57912a5085875c5e | Ruby | kkirsche/Bark | /lib/bark/client.rb | UTF-8 | 2,992 | 3.109375 | 3 | [
"Apache-2.0"
] | permissive | # Bark is a client for interacting with the Monit client.
module Bark
# The Client class is the primary communicator between the program and the
class Client
# `:host` = The hostname of the Monit server
# `:port` = The port used to connect to the Monit server
# `:user` = The username used for basic auth... | true |
26043f6baec8d85ed0c862acc782500d085f84f9 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/combine_anagrams_latest/12817.rb | UTF-8 | 603 | 3.453125 | 3 | [] | no_license |
def combine_anagrams(words)
# Use a hash to group the anagrams. Set up a default block for when an undefined key
# is used to create a blank array for that key.
groups = Hash.new { |hash, key| hash[key] = Array.new}
#loop through each word
wor... | true |
2ac8bcf371fafeb78fe630b3fb045ac774e7bed2 | Ruby | Jacfem/phase-0 | /week-7/gps6/my_solution.rb | UTF-8 | 4,220 | 4.1875 | 4 | [
"MIT"
] | permissive | # Virus Predictor
# I worked on this challenge with Dan Shapiro.
# We spent 1.5 hours on this challenge.
# EXPLANATION OF require_relative
#Direct to another Ruby file so that we can reference in our Driver Code
#A relative file is internal to our project
require_relative 'state_data'
class VirusPredictor
#We are in... | true |
0b52775656fec736d9f1c8107681907366342df0 | Ruby | paullewallencom/ruby-978-1-78439-295-6 | /01/01-new-syntax.rb | UTF-8 | 757 | 2.703125 | 3 | [] | no_license | require 'rspec'
describe 'new RSpec syntax' do
it "uses the new assertion syntax" do
# new # deprecated
expect(1 + 1).to eq(2) # (1 + 1).should == 2
end
context "mocks and expectations" do
let(:obj) do
# new # deprecated
double(... | true |
7b01a6660d61d6b90f529101ae01ffdcec58964b | Ruby | vinidiktov/ruby-spacy | /examples/linguistic_features/rule_based_morphology.rb | UTF-8 | 330 | 3.015625 | 3 | [
"MIT"
] | permissive | require "ruby-spacy"
require "terminal-table"
nlp = Spacy::Language.new("en_core_web_sm")
doc = nlp.read("Where are you?")
puts "Morph features of the third word: " + doc[2].morph.to_s
puts "POS of the third word: " + doc[2].pos
# Morph features of the third word: Case=Nom|Person=2|PronType=Prs
# POS of the third w... | true |
1407bf505c0ab4f021fb4a45b904d1c6dfed93e7 | Ruby | progapandist/kuby-core | /lib/kuby/docker/metadata.rb | UTF-8 | 1,972 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'uri'
module Kuby
module Docker
class Metadata
DEFAULT_DISTRO = :debian
DEFAULT_REGISTRY_HOST = 'https://docker.io'.freeze
LATEST_TAG = 'latest'
attr_accessor :image_url
attr_reader :definition, :distro
def initialize(definition)
@definition = definition
... | true |
b22e2682a960633cf73b586e1cc6bd5c1903154f | Ruby | davidmcdeavitt/WDI_12_HOMEWORK | /David/wk05/1-mon/warmup/order.rb | UTF-8 | 215 | 2.96875 | 3 | [] | no_license | #
# class Order
# attr_accessor :name, :type, :sugar, :strength
# def initialize(name, type, sugar, strength)
# @name = name
# @type = type
# @sugar = sugar
# @strength = strength
# end
# end
| true |
7475b9e87cbb29c1856ad329e31222d87f836013 | Ruby | jmoypace/countdown-to-midnight-cb-000 | /countdown.rb | UTF-8 | 216 | 3.46875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #write your code here
def countdown(number)
while number>0
puts "#{number} SECOND(S)!"
number-=1
if number==0
return "HAPPY NEW YEAR!"
end
end
end
def countdown_with_sleep(number)
sleep(number)
end
| true |
f0f8a1c5ca708159a22fd492a935d1f51b24e90c | Ruby | 18F/identity-idp | /lib/analytics_events_documenter.rb | UTF-8 | 5,672 | 2.546875 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | #!/usr/bin/env ruby
require 'yard'
require 'json'
require 'optparse'
require 'stringio'
require 'active_support/core_ext/object/blank'
require_relative './identity_config'
# Parses YARD output for AnalyticsEvents methods
class AnalyticsEventsDocumenter
DEFAULT_DATABASE_PATH = '.yardoc'
PREVIOUS_EVENT_NAME_TAG = :'... | true |
21d4cdb4ff1fbedac957681aebb7ec0eee92537d | Ruby | hassanshamim/chess | /test/test-controller.rb | UTF-8 | 3,832 | 3.359375 | 3 | [] | no_license | require 'controller.rb'
require 'test/unit'
class ControllerTest < Test::Unit::TestCase
def test_01_contoller_new_takes_only_two_arguments
assert_raise(ArgumentError) do
Controller.new('one variable')
end
assert_raise(ArgumentError) do
Controller.new('var1', 'var2', 'var3')
end
... | true |
53069d26f92f51bb40266c72c6314ca556b14b49 | Ruby | Maumagnaguagno/MAPC2016_Charts | /preprocess.rb | UTF-8 | 690 | 2.53125 | 3 | [] | no_license | begin
if ARGV.empty?
puts "Usage:
ruby preprocess.rb matchX_folder
Writes CSV file at matchX_folder/matchX_folder.csv"
else
# Each simulation is a folder with 1001 XML step files
xml_folder = ARGV.first
values = ''
1001.times {|index|
# <team jobs="XXX" money="($1)" name="($2)"/>
... | true |
f0fc45c01d1beecd5d1d9b21d2c3fe2795e78468 | Ruby | mbijon/occams-record | /lib/occams-record/results.rb | UTF-8 | 6,444 | 2.9375 | 3 | [
"MIT"
] | permissive | module OccamsRecord
# Classes and methods for handing query results.
module Results
# ActiveRecord's internal type casting API changes from version to version.
CASTER = case ActiveRecord::VERSION::MAJOR
when 4 then :type_cast_from_database
when 5 then :deserialize
end
... | true |
a1a1ebee51e2b03a99723faa7403dd658e9cc705 | Ruby | houstonfloyd/ruby-exercises | /easy.rb | UTF-8 | 27,052 | 3.8125 | 4 | [] | no_license | require 'pry'
require 'date'
##### Accidentally deleted Easy 1 work
##### Easy 2
#1.
# def age(name = 'Teddy')
# age = rand(20..200)
# puts "#{name} is #{age} years old!"
# end
# age('Joseph')
#2.
# METERS_FEET_CONVERT = 10.7639
# puts 'Enter the length of the room in meters:'
# length = gets.chomp
# puts 'En... | true |
89a5c001f6a31a7b0ad0f2a64487085870741c4c | Ruby | pawelbardzinski/monitoring | /lib/monitoring_script/monitoring.rb | UTF-8 | 859 | 2.84375 | 3 | [] | no_license | require 'net/ssh'
unless ARGV.size == 3
puts '# Usage:'
puts '> ruby monitoring.rb [hostname] [user] [path to the key file]'
exit
end
hostname = ARGV[0]
user = ARGV[1]
keys_file = ARGV[2]
cpu_stdout = ''
mem_stdout = ''
Net::SSH.start(hostname,user,:keys=>keys_file) do |ssh|
ssh.exec!("ps --no-headers -eo ... | true |
150b77c218c355b3628eae0fbb4dcfb8b28546dd | Ruby | theodi/coopy-ruby | /lib/coopy/table_view.rb | UTF-8 | 378 | 2.59375 | 3 | [
"MIT"
] | permissive | module Coopy
class TableView
include Coopy::View
def to_s(d)
d.to_s
end
def get_bag(d)
nil
end
def get_table(d)
d
end
def has_structure?(d)
true
end
def equals(d1, d2)
puts("TableView#equals called")
false
end
def to_datum(st... | true |
1c1c26f38a46dce62c009cfa420dece881110865 | Ruby | msmirnoff/right_on | /lib/right_on/restricted_by_right.rb | UTF-8 | 815 | 2.546875 | 3 | [
"MIT"
] | permissive | module RestrictedByRight
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def restricted_by_right(options = {})
options ||= {}
options[:group] ||= 'other'
Right.associate_group(self, options[:group])
class << self
def accessible_to(user)
... | true |
f6aaf0e98f3ae2bcb752c6b8dc52380a04bcda96 | Ruby | ErikKierstead/Ruby-Assignment | /problem2.rb | UTF-8 | 378 | 3.84375 | 4 | [] | no_license | def palindrome?(string)
#Strips Special Characters and Digits:
string.gsub!(/[\W\d]/, "")
#Outputs True/False if Reversed:
puts string.downcase + " == " + string.downcase.reverse + ": "
return string.downcase == string.downcase.reverse
end
p palindrome?("A man, a plan, a canal -- Panama")
p pal... | true |
c9e22cc1fbd52bfdd041876a921d1b93463910cc | Ruby | marcmo/blog.coldflake.com | /_plugins/tag_gen.rb | UTF-8 | 1,343 | 2.578125 | 3 | [] | no_license | require 'logger'
require 'pp'
$logger = Logger.new('logfile.log')
$logger.level = Logger::DEBUG
$logger.formatter = proc do |s, d, progname, msg|
"tag_gen: #{d}: #{msg}\n"
end
module Jekyll
class TagIndex < Page
def initialize(site, base, dir, tag)
$logger.debug("TagIndex:: initialize tag=#{tag}")
... | true |
83fa34c34167e1da3d2b718c2c9d857816b1502e | Ruby | UNC-Libraries/hy-c | /lib/tasks/migrate/services/progress_tracker.rb | UTF-8 | 712 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require 'set'
module Migrate
module Services
class ProgressTracker
def initialize(filename)
@filename = filename
@write_mutex = Mutex.new
create_log
end
def add_entry(entry)
# Prevent multiple threads from writing to the file at th... | true |
363010ec8964ba38f582a0b62cb74b717876c7bb | Ruby | alanrubin/top-parsers-WCFG-MySQL | /src/rule_encoder.rb | UTF-8 | 289 | 2.78125 | 3 | [] | no_license | class RuleEncoder
def initialize(rule, codifier)
@rule = rule
@codifier = codifier
end
def method_missing(method_id)
result = @rule.send(method_id)
return result if (!result.is_a? String || method_id.to_s =~ /terminal/)
@codifier.encode(result)
end
end | true |
f0bd1d5814f130f36a5d35beb6d277599253ffc0 | Ruby | ruby-processing/The-Nature-of-Code-for-JRubyArt | /chp03_oscillation/ExtraOscillatingUpAndDown/ExtraOscillatingUpAndDown.rb | UTF-8 | 300 | 2.71875 | 3 | [
"MIT"
] | permissive | # ExtraOscillatingUpAndDown
def setup
sketch_title 'Extra Oscillating Up And Down'
@angle = 0
end
def draw
background(255)
y = 100 * sin(@angle)
@angle += 0.02
fill(127)
translate(width / 2, height / 2)
line(0, 0, 0, y)
ellipse(0, y, 16, 16)
end
def settings
size(400, 400)
end
| true |
caa3c9829686c37c2773804c48f4c4917d0cd312 | Ruby | jayniz/zeta | /lib/zeta/runner.rb | UTF-8 | 3,080 | 2.703125 | 3 | [] | no_license | # encoding: UTF-8
require 'optparse'
class Zeta::Runner
COMMANDS = {
'full_check' => 'Update contracts and validate infrastructure',
'validate' => 'Validate the architecture in the contracts cache dir',
'update_own_contracts' => 'Update your own contracts in the contracts cach... | true |
94f86cbb786113aa2998e48b30f19630cef272ff | Ruby | rock-core/tools-roby | /lib/roby/interface/subcommand_client.rb | UTF-8 | 1,748 | 2.609375 | 3 | [
"LicenseRef-scancode-cecill-b-en",
"CECILL-B"
] | permissive | # frozen_string_literal: true
module Roby
module Interface
# Representation of a subcommand on {Interface} on the shell side
class SubcommandClient
# @return [ShellClient,ShellSubcommand] the parent shell /
# subcommand
attr_reader :parent
# @return... | true |
1f19489aa42d2984ecc6ce0c5606bcecd859c062 | Ruby | Vaguery/CargoBot-ruby | /lib/cargobot.rb | UTF-8 | 7,494 | 2.8125 | 3 | [] | no_license | class CargoBot
attr_accessor :script, :program
attr_accessor :stacks, :starting_stacks, :execution_stack
attr_accessor :claw_position, :claw_holding
attr_accessor :moves, :crashes, :steps, :topples, :broken
attr_accessor :step_limit, :height_limit, :goal, :unstable, :fragile
def initialize(script="", ... | true |
1eb60d9da442703e8b046299438256cd3996cddd | Ruby | dantelove/120_object_oriented_programming | /lesson_4/1_easy1/easy1_1.rb | UTF-8 | 388 | 4.71875 | 5 | [] | no_license | # easy1.rb
# Which of the following are objects in Ruby? If they are objects,
# how can you find out what class they belong to?
# 1. true
# 2. "hello"
# 3. [1, 2, 3, "happy days"]
# 4. 142
# All of the above are objects. And you can figure out which class
# they belong to by calling the .class method on them:
p tr... | true |
bb716a1f0d6a11be8b4970f27d8f1d72e0e081b4 | Ruby | adamhollett/jekyll-relations | /lib/jekyll/relations/page.rb | UTF-8 | 1,671 | 2.5625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Jekyll
module Relations
module Page
# The next highest page in the folder structure.
#
# Returns the Page object for the parent page.
def parent
@parent ||= begin
return nil unless html?
depth = url.count('/')
site... | true |
f07b3437cdc578ceff96ab0c9bf1988726ef8d1a | Ruby | didiermarques/exruby | /exo_04.rb | UTF-8 | 334 | 2.671875 | 3 | [] | no_license | =begin le programme ne se lance pas avec ce message d'erreur :
exo_04.rb:1: unterminated string meets end of file
puts "Salut, ça farte ?
^
Parce que la string n'a pas été fermé avec le ", à l'endroit montré ci-dessus.
Il aurait fallu écrire: puts "Salut, ça farte ?"
=end
puts "Salut, ça fart... | true |
04469a2aa8b30e31094db4c639e0d69209d2bd86 | Ruby | kindkid/euler | /061.rb | UTF-8 | 1,496 | 3.3125 | 3 | [] | no_license | require 'set'
def first2(n)
(n/1000)*10 + ((n/100) % 10)
end
def last2(n)
((n/10) % 10)*10 + (n % 10)
end
start = Time.now
FUNCS = {
tri: ->(n) { n*(n+1)/2 },
sqr: ->(n) { n*n },
pent: ->(n) { n*(3*n-1)/2 },
hex: ->(n) { n*(2*n-1) },
hept: ->(n) { n*(5*n-3)/2 },
oct: ->(n) { n*(3*n-2... | true |
53af8688a9655bd323cbed348557d4af6c83f32f | Ruby | tiago-DaSilva/Ruby | /level2/main.rb | UTF-8 | 948 | 3.0625 | 3 | [] | no_license | require "json"
require "date"
file = File.read('data.json')
data = JSON.parse(file)
result = {"rentals" => []}
i = 0
data['rentals'].each do |elements|
car_id = elements['car_id'].to_i
nb_days = (Date.parse(elements['end_date']) - Date.parse(elements['start_date']) + 1).to_i
price_per_day = data["cars"].select {... | true |
3b547a5a6cfc7cf5f1d82c6c5105517e7eea64da | Ruby | BkBky/ruby_fase0 | /bk/dia_01/ejercicio8.rb | UTF-8 | 366 | 3.296875 | 3 | [] | no_license |
#Ejercicio Operaciones Aritméticas
suma = (4+4)
resta = (16-8)
p suma == resta
#=>true
#------------------------------------
var1 = 20
var2 = 10
resta = var1-5.5
multiplicacion = resta * var1 + var2
#multiplicacion = (14.5 * 20) + 10
#multiplicacion = (290) + 10
#multiplicacion = 300
division = multiplicacion / 3... | true |
474c02d7c638c3e2251375b4db5262430e83541d | Ruby | earlsabal/euler_solutions | /spec/09_special_pythagorean_triplet_spec.rb | UTF-8 | 202 | 2.625 | 3 | [] | no_license | require "09_special_pythagorean_triplet"
describe "Special pythagorean triplet" do
it "finds the product of the special triplet" do
expect(special_pythagorean_triplet(1000)).to eq(31875000)
end
end | true |
7a9381f4acc241ff1090cc1c5471364ad92c4eb3 | Ruby | andrewtimberlake/css | /spec/lib/css/properties/outline_property_spec.rb | UTF-8 | 2,860 | 2.6875 | 3 | [
"MIT"
] | permissive | require "spec_helper"
module CSS
describe OutlineProperty do
context "As a long-hand property" do
it "should store that value" do
outline = Property.create('outline-color', '#FFF')
outline.color.should == '#FFF'
end
end
context "Expanding CSS shorthand" do
context "with... | true |
043e4dfb1286ea469255e0b3c4e5c68cd33a2c02 | Ruby | notonthehighstreet/active_record_deprecate_columns | /spec/active_record_deprecate_columns_spec.rb | UTF-8 | 2,959 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'active_record'
describe ActiveRecordDeprecateColumns do
before(:all) do
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
m = ActiveRecord::Migration
m.verbose = false
m.create_table :brand_new_objects do |t|
t.string :shiny_attrib... | true |
8c36ab2bb4b50df1205126d6eab5d2c0465490c0 | Ruby | jwsharpe/module-one-final-project-guidelines | /lib/controller/gamepad_handler.rb | UTF-8 | 669 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class GamepadHandler
attr_reader :digital_output_x, :digital_output_y
attr_accessor :magnitude, :deadzone
def initialize(magnitude: 15, deadzone: 0.15)
@digital_output_x = 0
@digital_output_y = 0
@magnitude = magnitude
@deadzone = deadzone
end
def update_controller_axis_digital_output(event)... | true |
1d4292c7019da0ee15f6e199a7b333f6ca334c68 | Ruby | Aperta-project/Aperta | /app/models/answer.rb | UTF-8 | 3,715 | 2.546875 | 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 |
807a1e971a2230ad27df3ffaebc9618165c7ad3d | Ruby | doomspork/icepick | /lib/icepick/prompt.rb | UTF-8 | 2,809 | 3.09375 | 3 | [
"MIT"
] | permissive | require 'colorize'
module Icepick
class Prompt
class << self
# Pry prompt's target object
attr_accessor :target
# The nesting level of the current Pry
attr_accessor :level
# An instance of the current Pry session
attr_accessor :pry
# Our configuration instance
... | true |
354f8b13287d254949f9f54cc965e91dd54100c6 | Ruby | godfat/ludy | /lib/ludy/array/tail.rb | UTF-8 | 84 | 3.265625 | 3 | [
"Apache-2.0"
] | permissive |
class Array
# simply call
# array[1..-1]
def tail
self[1..-1]
end
end
| true |
64d32ec2729154fc8eb664f5178f1db0e4f36313 | Ruby | ioreka/ruby-class-variables-and-class-methods-lab-london-web-060418 | /lib/song.rb | UTF-8 | 676 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Song
attr_accessor :name, :artist, :genre
@@all_songs = []
@@count = 0
@@artists = []
@@genres = []
def initialize(name, artist, genre)
@name = name
@artist = artist
@genre = genre
@@all_songs << @name
@@artists << @artist
@@genres << @genre
@@count += 1
... | true |
b862cec802a820e6075ddfef5598c857b36f1415 | Ruby | dalizard/design_patterns_in_ruby | /composite/make_batter_task.rb | UTF-8 | 454 | 2.890625 | 3 | [] | no_license | class MakeBatterTask < Task
def initialize
super 'Make batter'
@sub_tasks = []
add_sub_task AddDryIngredientsTask.new
add_sub_task AddLiquidsTask.new
add_sub_task MixTask.new
end
def add_sub_task task
@sub_tasks << task
end
def remove_sub_task task
@sub_tasks.delete task
end
... | true |
6d0dec66a61e68dcbc950f5bf52b81d69deac331 | Ruby | Rockster160/Portfolio | /app/service/chat_gpt.rb | UTF-8 | 1,294 | 2.59375 | 3 | [] | no_license | module ChatGPT
module_function
def last_ask = @last_ask
def last_response = @last_response
def last_chat_data = @last_chat_data
def client
@client ||= OpenAI::Client.new
end
def ask(str)
@last_ask = str
response = client.chat(
parameters: {
model: "gpt-3.5-turbo", # Required.
... | true |
3db7530b8072dbcc4a48b81113554237e790d438 | Ruby | DGaffney/dgaff | /lib/dgaff/class.rb | UTF-8 | 123 | 2.921875 | 3 | [
"MIT"
] | permissive | class Class
def downcase
return self.to_s.downcase
end
def underscore
return self.to_s.underscore
end
end
| true |
380644f18a045aa420f8985359c46cb76652b803 | Ruby | olichwiruk/sandbox-manager | /lib/entities/sandbox.rb | UTF-8 | 941 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
module Entities
class Sandbox
attr_reader :email, :token, :created_at, :lifetime, :active
def initialize(email:, token:, created_at:, lifetime:, active:)
@email = email
@token = token
@created_at = Time.parse(created_at.to_s)
@lifetime = lifetime.to_i
... | true |
33acc3bc1da1ba640ee0f18126bf0a2c0fe4301c | Ruby | hardikhardiya/movie-theatre | /app/helpers/movie_lists_helper.rb | UTF-8 | 218 | 2.578125 | 3 | [] | no_license | module MovieListsHelper
def get_show_details(movielist)
arr = []
movielist.each do |movie|
movie.shows.each do |s|
arr << [movie.name, movie.price, s.show_time, s.show_hall]
end
end
arr
end
end
| true |
151350664ad7bcde31726d23986156194ebe4be1 | Ruby | DakotaLMartinez/dlm_now_showing | /concerns/resources.rb | UTF-8 | 489 | 2.609375 | 3 | [
"MIT"
] | permissive | module Concerns::Creatable
def create(name)
self.new(name).save
end
end
module Concerns::Destroyable
def destroy_all
self.all.clear
end
end
module Concerns::Savable
def save
self.class.all << self
self
end
end
module Concerns::Findable
def find_by_name(name)
... | true |
1d5fc90a0f8b9bbeb7f570901d67e7ce248650a6 | Ruby | izumin5210-sandbox/coding-exercises | /abc041/a/main.rb | UTF-8 | 36 | 2.84375 | 3 | [
"MIT"
] | permissive | s = gets
i = gets.to_i
puts s[i-1]
| true |
2b607d3949d800d5f8a7286629b92d780cabf632 | Ruby | jbbarth/golf-scripts | /test_rb.rb | UTF-8 | 220 | 2.765625 | 3 | [] | no_license | #!/usr/bin/env ruby
res = %x(cat input.txt | ruby script.rb)
size = File.read("script.rb").chomp.length
if res.strip == File.read("output.txt").strip
puts "ok! #{size}"
exit 0
else
puts "KO! #{size}"
exit 1
end
| true |
93b04b91b62b0e39f53a548b017a51feb0278640 | Ruby | criskelly/gecko | /lib/graphite.rb | UTF-8 | 653 | 2.6875 | 3 | [] | no_license | require 'JSON'
require 'rest-client'
require 'date'
require 'URI'
class Graphite
# Pass in the url to where your graphite instance is hosted
def initialize(url)
@url = url
return url
end
# This is the raw query method, it will fetch the JSON from the
# Graphite and parse it
def query(name, since=n... | true |
d3548ae3a07fe143bb02160e1c7d1ed4fa8b5470 | Ruby | danawoodman/Google-SketchUp-Material-Changer | /SU_MaterialChanger/MaterialChanger.rb | UTF-8 | 10,588 | 3.28125 | 3 | [
"MIT"
] | permissive | # TODO: Performance improvements. I'm sure the recursion I'm doing here isn't
# needed. Get material changes working faster for large groups of entities.
class SU_ChangeMaterial
# Intialize the class by creating instance variables that we will use later.
def initialize
@model = Sketchup.active_model
@... | true |
4ff88aad142ad426f2cf14561a667da1143d64f3 | Ruby | cnemeth/minefield | /lib/minefield/reader.rb | UTF-8 | 403 | 2.9375 | 3 | [] | no_license | require 'awesome_print'
module Minefield
class Reader
def initialize; end
def read(file)
return [] unless file && File.exist?(file)
read_file(file)
end
private
def read_file(file)
data = []
File.open(file, "r") do |f|
f.each_line do |line|
data << line... | true |
10b4248ca0b5df24dc30e0d6f9a7354b16eef7d8 | Ruby | lucyfox4131/APICurious | /app/services/user_service.rb | UTF-8 | 875 | 2.703125 | 3 | [] | no_license | class UserService
def initialize(user)
@_user = user
@_connection = Faraday.new("https://api.github.com")
@_connection.headers["Authorization"] = "Token #{user.oauth_token}"
end
def followers
parse(connection.get('/user/followers'))
end
def following
parse(connection.get('/user/followin... | true |
7d8e3c3036ac2044ba3a5fcda2f133e789b22289 | Ruby | katryc/mygem | /lib/mygem/capitalizer.rb | UTF-8 | 78 | 2.75 | 3 | [
"MIT"
] | permissive | class String
def capitalizer
self.capitalize.center(15)
end
end
| true |
dc759640294431187ea9d64d6a9c3d99d85d237f | Ruby | fiskeben/kanduanbefale.dk | /lib/oembed.rb | UTF-8 | 659 | 2.84375 | 3 | [] | no_license | require 'net/http'
require 'uri'
require 'json'
class OEmbed
def initialize(oembed_json)
@json = oembed_json
end
def method_missing(method, *args, &block)
return @json[method.to_s]
end
def self.get(tweet_id)
oembed_url = "https://api.twitter.com/1/statuses/oembed.json?id=#{tweet_id}&align=c... | true |
e65e44d1d6644faa7faa1310624d6aa8f9150494 | Ruby | 495-Labs-Projects/ChoreTrackerAPI | /app/controllers/children_controller.rb | UTF-8 | 3,280 | 2.671875 | 3 | [] | no_license | class ChildrenController < ApplicationController
# This is to tell the gem that this controller is an API
swagger_controller :children, "Children Management"
# Each API endpoint index, show, create, etc. has to have one of these descriptions
# This one is for the index action. The notes param is optional bu... | true |
3bce13a21f29ae9615a83e3fa62a377e3d872122 | Ruby | jaykornder/ttt-game-status-cb-gh-000 | /lib/game_status.rb | UTF-8 | 1,278 | 3.828125 | 4 | [] | no_license | # Helper Method
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
# Define your WIN_COMBINATIONS constant
WIN_COMBINATIONS = [
[0,1,2], # Top row
[3,4,5], # Middle row
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6],
]
def won?(board)
won = nil
WIN_COMBINATIO... | true |
55a801884b32a06d17b20c2ec06eeb9e77f592ac | Ruby | RonuGhoshal/voting_data | /fill_gaps.rb | UTF-8 | 510 | 2.78125 | 3 | [] | no_license | require 'csv'
data = File.new('datasofar22.csv')
parsed_data = data.to_a.join()
data_so_far= (CSV.new(parsed_data, :headers => true, :header_converters => :symbol)).to_a.map {|row| row.to_hash}
data_so_far.select {|row| row[:id] == "4012"}[0].each do |year, value|
if value == "000000"
value = data_so_far.select... | true |
bcdd872832d64d5a6fe245ec058c496718fb96a4 | Ruby | mateuadsuara/isp_comparison_java_ruby | /ruby/implementation_of_group_a.rb | UTF-8 | 172 | 2.71875 | 3 | [] | no_license | class ImplementationOfGroupA
def method_1_used_in_group_A
puts "Method 1 of group A!"
end
def method_2_used_in_group_A
puts "Method 2 of group A!"
end
end
| true |
9a718123f703175a6bba5e3f950675b16446c77c | Ruby | freerange/mocha | /lib/mocha/configuration.rb | UTF-8 | 13,226 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'mocha/ruby_version'
module Mocha
# Allows setting of configuration options. See {Configuration} for the available options.
#
# Typically the configuration is set globally in a +test_helper.rb+ or +spec_helper.rb+ file.
#
# @see Configuration
#
# @yieldparam configuration [Configuration] the conf... | true |
d4cb5fc547935a184e9867d3a8b817726649fbbe | Ruby | cgledezma1101/uwr-tournament | /app/models/user_club.rb | UTF-8 | 449 | 2.5625 | 3 | [] | no_license | class UserClub < ApplicationRecord
belongs_to :user
belongs_to :club
validates :user, presence: true, uniqueness: { scope: :club }
validates :club, presence: true
# The full name of the user included in this relationship
#
# @return [String] Full name of the user associated
def user_name
self.user.name
end... | true |
47d84cab5f08c736292ee1db3cef0d91effc73a9 | Ruby | cdunham1989/code-wars-solutions | /sum_of_multiples.rb | UTF-8 | 146 | 2.78125 | 3 | [] | no_license | def solution(number)
arr = []
(1..(number-1)).each do |x|
if x % 3 == 0 || x % 5 == 0
arr << x
end
end
arr.reduce(:+)
end
| true |
ea84f9fed9be5461da1079f8499f169f1575fe3d | Ruby | marcofognog/image_testing | /spec/comparator_spec.rb | UTF-8 | 7,693 | 2.546875 | 3 | [] | no_license | $LOAD_PATH << "."
require 'rspec'
require 'spec_helper'
require 'lib/image_testing'
describe "Comparator" do
describe "#find_couple" do
context "Unidimensional" do
it "should find a couple with the first pixel of the contained image within the whole image" do
container = Image.read("unidimensional... | true |
35b964dfb8ab8ca11c56c3a4e90e615057af4526 | Ruby | starjuice/auth_dns_check | /lib/auth_dns_check/client.rb | UTF-8 | 3,877 | 2.671875 | 3 | [
"MIT"
] | permissive | module AuthDnsCheck
# Client for performing authoritative DNS checks
#
# @todo IPv6 not supported
class Client
# Default record types for checks like +all?+
DEFAULT_TYPES = ["A"] unless defined?(DEFAULT_TYPES)
# authoritative name server overrides
attr_reader :overrides
# default resolve... | true |
766e1d49efe36374da2c0043ddf79334ba32c8cf | Ruby | lukaskai/rubyCourse | /app/models/user.rb | UTF-8 | 851 | 2.578125 | 3 | [] | no_license | # Module for system user
class User < ApplicationRecord
has_one :company
has_many :proposals
validates_format_of :email,
with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
on: 'new'
validates_uniqueness_of :email
after_initialize do
validate_password(password... | true |
2d08c4ffc8d6738e7976e6f2d454695674b9bedc | Ruby | t-kot/bataille | /lib/bataille/search_result.rb | UTF-8 | 1,830 | 2.734375 | 3 | [
"MIT"
] | permissive | # coding: utf-8
module Bataille
class SearchResult
attr_accessor :results, :word
include Enumerable
def initialize(results, word)
@results, @word = results, word
end
def length
@results.length
end
def each
@results.each { |r| yield r }
end
def limit(n=1)
... | true |
5950de81c4abe2f6c88b11077a3956af55d78459 | Ruby | toanhtran/launch_school | /intro_to_programming/more_stuff/ex_01.rb | UTF-8 | 244 | 2.859375 | 3 | [] | no_license | def has_word_lab(string)
if /lab/ =~ string
puts string
else
puts "No match here."
end
end
has_word_lab("laboratory")
has_word_lab("experiment")
has_word_lab("Pans Labyrinth")
has_word_lab("elaborate")
has_word_lab("polar bear") | true |
a53054d350e6d7d750e8d466d2dc973f36e65c06 | Ruby | kirbynator/Brain-Teasers | /Caps.rb | UTF-8 | 886 | 3.390625 | 3 | [] | no_license | require "pry"
def caps
puts "Give me a sentence"
print "> "
s = gets.strip.split('').unshift(' ')
@c=0
@n = []
s.each do |l|
@l = l
if @c == 1
case @l
when "a"
@l = "A"
when "b"
@l = "B"
when "c"
@l = "C"
when "d"
@l = "D"
when "e"
@l = "E"
when "f"
@l = "F"
when "g"
... | true |
e35cc39826b6e9b299982a4f9316aebb8029a4d2 | Ruby | chelseadeane14/RubyProjects | /program.rb | UTF-8 | 2,395 | 4.21875 | 4 | [] | no_license | puts "It has been a great day."
puts "Unfortunately, it's already #{Time.now}"
# Defining a Method
def say_hi(user_name)
result = "Hi, #{user_name.capitalize}!" #Capitalize is a method
return result
end # end terminates code blocks
#Personalized Greeting
puts say_hi('mark')
puts say_hi("Mary")
puts "Testing the ... | true |
ed27f36800ea12b8b27c840260c39f4d61464ebe | Ruby | LincolnFleet/oo-cash-register-atlanta-web-career-031119 | /lib/cash_register.rb | UTF-8 | 1,056 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
def initialize(discount=0)
@discount=discount
@items=[]
@total=0
end
attr_accessor :discount, :total
def set_total
if self.items.length>0
@total=@items.map{|hash| hash['price'] * hash['quantity']}.flatten.reduce(0){|acc,num| acc+num}
... | true |
d83af34110afc9c5bd93af780d469a56fd584fbd | Ruby | duykhoa/haythat | /test/test_command_engine.rb | UTF-8 | 995 | 2.703125 | 3 | [] | no_license | require 'helper'
class TestCommandEngine < Minitest::Test
def setup
@engine = CommandEngine.new
end
def test_put_command_to_stack
command = "grow_crop 1 wheat"
@engine.receive(command)
assert_equal(1, @engine.commands.size)
end
def test_execute
fields = [Field.new]
farm_activity = ... | true |
ce28d247cf3a5826cd6735cbb4b2db2a8505d023 | Ruby | GertjanF/New-Women-Writers | /vendor/rails/activesupport/lib/active_support/core_ext/range/include_range.rb | UTF-8 | 1,805 | 2.671875 | 3 | [
"MIT"
] | permissive | #
# Copyright 2009 Huygens Instituut for the History of the Netherlands, Den Haag, The Netherlands.
#
# This file is part of New Women Writers.
#
# New Women Writers is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundat... | true |
d02fd8bbc7273a19d40aa8158a94c0139632dcb3 | Ruby | ac6087/algorithms | /ruby/graphs/unit_tests/seed_graph.rb | UTF-8 | 768 | 2.828125 | 3 | [] | no_license | require_relative '../graph'
class SeedGraph
class << self
def undirected_graph
v1 = Vertex.new('WHITE', 1, nil, [], 1)
v2 = Vertex.new('WHITE', 1, nil, [], 2)
v3 = Vertex.new('WHITE', 1, nil, [], 3)
v4 = Vertex.new('WHITE', 1, nil, [], 4)
v5 = Vertex.new('WHITE', 1, nil, [], 5)
... | true |
4390df880f17e7094730e6e173daec21dcb8d35f | Ruby | martinjos/pkunzip-deflate-ruby | /huffgen.rb | UTF-8 | 514 | 2.84375 | 3 | [] | no_license | def huffgen(alphabet, lengths)
group = lengths.group_by(&:to_i)
lens = group.keys.sort
starts = {}
start = 0
(1..lens[-1]).each{|len|
num = group[len-1]
if num && len > 1
num = num.size
else
num = 0
end
start = (start + num) << 1
starts[len] = start
}
codes = [0] * alphabet.size
sorted_info = ... | true |
d93af95b055094692e03bb889d4fddda0b6dac84 | Ruby | plee777/phase-0-tracks | /ruby/gps2_2.rb | UTF-8 | 2,563 | 4.375 | 4 | [] | no_license | # Method to create a list
# input: string of items separated by spaces (example: "carrots apples cereal pizza")
# steps:
# identify which items are wanted
# arr = ["carrots", "apples", "ceral"]
# set default quantity : 0
# print the list to the console [can you use one of your other methods here?]
# output: ha... | true |
07b37cee7e7f03979defb52605088f4e739675c3 | Ruby | odremaer/ruby-test | /matrix.rb | UTF-8 | 684 | 3.5625 | 4 | [] | no_license | require 'mathn'
def det(matrix)
matrix = Matrix[*matrix]
det = matrix.det
end
STDOUT.flush
matrix = []
while true do
k = 0
cur_input = gets.chomp
if cur_input == ''
if matrix.length == 0
puts "Не было введено ни одной строки"
break
elsif matrix.length == matrix[0].length
puts "Матр... | true |
0da777f5126d76eee4d1050a57a5350ca21777ba | Ruby | Circuit-killer/rpicsim | /lib/rpicsim/memory_watcher.rb | UTF-8 | 3,222 | 3.125 | 3 | [
"MIT"
] | permissive | require 'set'
# @api public
module RPicSim
# This class can attach to an MPLAB X memory class and watch for changes in it, and
# report those changes as a hash associating variable names to new values. This is
# very useful for writing tests that assert that not only were the desired variables
# written to, b... | true |
ed8e5e34b5f9bb98d89632a60e921a0dde1965aa | Ruby | Tumbles/magic-search-engine | /indexer/lib/patches/patch_itp_rqs_rarity.rb | UTF-8 | 647 | 2.53125 | 3 | [
"MIT"
] | permissive | # Fix rarities of ITP/RQS from "special" to whatever they were in 4ed
# These are basically 4ed precons, except with updated copyright from 1995 to 1996
# so it's silly to treat them as some "special" printings
class PatchItpRqsRarity < Patch
def call
each_card do |name, printings|
affected_printings = pri... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.