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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
27fb5c51fc990642f9a8befd247a109a21f26b1e | Ruby | fromheten/hamt | /gen_test_data.rb | UTF-8 | 262 | 2.6875 | 3 | [] | no_license | #!/usr/bin/env ruby
File.open("test_data", 'w') do |f|
100_000_000.times do
if rand < 0.9
f.puts ["S", rand(1_000_000).to_s(36), rand(1_000_000).to_s(36)].join("\t")
else
f.puts ["D", rand(1_000_000).to_s(36)].join("\t")
end
end
end
| true |
6180cddc36ca56c3d0787c6513dcd16eb8a64327 | Ruby | RealSilo/ruby | /lib/design_patterns/solid.rb | UTF-8 | 4,471 | 4 | 4 | [] | no_license | # SINGLE RESPONSIBILITY PRINCIPLE
# Design your classes so, that they only have one reason to change.
# Gather together the things that change for the same reasons and separate
# things that change for different reasons.
# Readability, Reusability, Easier to test
# What is a reason to change? For instance you have a... | true |
b86ecbdee4deff9efc6859ee4699758892b8a459 | Ruby | pramod-sharma/learning_tasks | /advanced_ruby/Dynamic_class_from_csv/new_dynamic_Class.rb | UTF-8 | 2,665 | 3.65625 | 4 | [] | no_license | require 'csv'
class ClassCreator
def self.create_class( class_name, csv_fields )
new_class = Class.new do
@@list = []
#puts instance_variables
#send :attr_reader, *instance_variables
def initialize args
index = 0
puts args
#iterates through all the instance variable... | true |
7f878d13155db5e21835b3c93fac7ec5394b4036 | Ruby | hinashin38/egotter | /app/models/search_request_validator.rb | UTF-8 | 647 | 2.515625 | 3 | [
"MIT"
] | permissive | class SearchRequestValidator
def initialize(user)
@user = user
end
def blocked_user?(screen_name)
if user_signed_in?
client.user_timeline(screen_name, count: 1)
false
else
false
end
rescue => e
AccountStatus.blocked?(e)
end
def protected_user?(screen_name)
if user... | true |
5ed11e1344dc76231e421fb89a51a6363520afb2 | Ruby | penta8/ltp | /8_chapter/1_building_sorting_array.rb | UTF-8 | 175 | 3.46875 | 3 | [] | no_license | words = []
word = 'begin'
until word == ''
print 'Enter a word (enter to finish): '
word = gets.chomp
unless word == ''
words.push(word)
end
end
puts words.sort
| true |
564209511e81374ad64a851e113c6c5b15d7a63d | Ruby | hi-ogawa/ruby_elasticsearch_backend_example | /import_hotels.rb | UTF-8 | 571 | 2.546875 | 3 | [] | no_license | require './hotel'
module ImportHotels
class << self
def run(file_path)
JSON.parse(File.read(file_path)).each do |h|
Hotel.create({
bc_id: h['id'],
name: h['name'],
address: h['address'],
zip: h['zip'],
hotel_url: h['hotel_url'],
... | true |
2174a87b4c6e652a5ed1adba79a251a6d121fa8d | Ruby | sneharpatel/Learn-Ruby | /Inventory.rb | UTF-8 | 719 | 3.703125 | 4 | [] | no_license | class Item
def initialize(item,maker)
@item=item
@maker=maker
end
def display
puts "Item ==> " + @item
puts "Maker ==> " + @maker
end
end
class ItemNumber < Item
def initialize(item,maker,number)
super(item,maker)
@number=number
end
def store_numberOfItem(number)
@total=0
... | true |
584ef693839813629a3a9f960cd45151324a2213 | Ruby | buzzyn/log_parser | /app/file_parser.rb | UTF-8 | 695 | 2.984375 | 3 | [] | no_license | require_relative 'entry'
class FileParser
attr_reader :log_file, :entries
def initialize(log_file)
@log_file = log_file
@entries = []
end
def read_file
File.read(log_file).each_line do |line|
construct_entry(line)
end
end
def ordered_pages_views
grouped_paths.map { |key, value|... | true |
bb57100bab533423b3abbea40c3158fd77d1f187 | Ruby | tobyhs/simplecov_html_inline | /spec/fixtures/test2.rb | UTF-8 | 109 | 2.78125 | 3 | [
"MIT"
] | permissive | module Test2
def self.abs(number)
if number >= 0
number
else
-number
end
end
end
| true |
be2aec4740e5149ab611ff74e2465a0f831cace8 | Ruby | sadiqmmm/tenderjit | /misc/build-ruby-internals.rb | UTF-8 | 13,407 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require_relative "ruby_internals"
require "erb"
module Layout
class CObject < Struct.new(:name, :byte_size, :aliases, :children)
def has_bitfields?; children.any?(&:bitfield?); end
def has_autorefs?; children.any?(&:autoref?); end
def bitfields; children.select(&:bitfield?); end
def autorefs; childre... | true |
5fdcca57d0f7cba16493781839d9af6c3ebdb487 | Ruby | nkeller1/flash_cards | /flashcard_runner.rb | UTF-8 | 1,189 | 3.40625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/card'
require './lib/turn'
require './lib/deck'
require './lib/round'
require './lib/cardgenerator'
@round = Round.new(
@deck = Deck.new(
@cards = CardGenerator.new('./data/cards.txt').cards))
def start
puts "-" *75
puts "Welcome to Flashca... | true |
88a41e730405e30ddb01ac536b8b76d318c04598 | Ruby | justinwang11/AppAcademy | /w3d2-master/question.rb | UTF-8 | 2,258 | 2.75 | 3 | [] | no_license | class Question
attr_accessor :title, :body, :author_id
def self.find_by_id(id)
result = QuestionsDatabase.get_first_row(<<-SQL, id: id)
SELECT
*
FROM
questions
WHERE
id = :id
SQL
Question.new(result)
end
def self.find_by_author_id(author_id)
results ... | true |
71c145adebf1bcd1d23aed34f5420e2e6d28acc6 | Ruby | joakimk/devbox-tools | /lib/metadata.rb | UTF-8 | 785 | 2.859375 | 3 | [
"MIT"
] | permissive | # Stores information about dependencies. Usually used for caching
# to avoid having to run expensive lookups more than nessesary
#
# We need it to be fast so that running "dev" when nothing needs to be done
# or cd'ing to a directory remains fast (~sub 200ms).
class Metadata
def initialize(dependency_name)
@depe... | true |
1f5637fed053c7b5977c5219ab3af872e6db7f6a | Ruby | kgraves/codewars-kata | /solutions/ruby/findIt.rb | UTF-8 | 243 | 3.015625 | 3 | [
"MIT"
] | permissive | def find_it(seq)
counts = Hash.new
seq.each do |i|
counts[i] = counts[i] ? counts[i] + 1 : 1
end
counts.each do |k,v|
if v % 2 == 1 then return k end
end
return nil
end
def find_it_redux(seq)
return seq.reduce(:^)
end
| true |
65a7a607169f520ef16be2cff8ac51e490f838c4 | Ruby | alexformagio/monk | /block2.rb | UTF-8 | 155 | 3.40625 | 3 | [] | no_license | def block1
puts "Start of the method"
yield("Hello",99)
puts "End of the method"
end
block1{
| str, num | puts "#{str} Inside the block #{num}"
}
| true |
d143a3d25161d0528dde76d3513807aa8d01269a | Ruby | anogno/wukong-load | /lib/wukong-load/syncers/prepare_syncer/ordered_handler.rb | UTF-8 | 1,291 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | module Wukong
module Load
class PrepareSyncer
# Can be included into another Handler class to make that
# handler create a strict ordering for files in its output
# directory.
module OrderedHandler
# Return the output path for the given `original` file.
#
... | true |
ff8298a964ebbdd3c49e9d86e15568925b8524ab | Ruby | amcejamorales/oo-ride-share | /lib/trip.rb | UTF-8 | 1,126 | 2.953125 | 3 | [] | no_license | require 'csv'
require 'time'
module RideShare
class Trip
attr_reader :id, :passenger, :driver, :start_time, :end_time, :cost, :rating
def initialize(input)
@id = input[:id]
@driver = input[:driver]
@passenger = input[:passenger]
@start_time = input[:start_time]
@end_time = inpu... | true |
789d6e938554559c5056e5b28fe481576b9f5c4c | Ruby | wags83/ruby-enumerables-introduction-to-map-and-reduce-lab-nyc-web-012720 | /lib/my_code.rb | UTF-8 | 1,088 | 3.4375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # My Code here....
def map_to_negativize(array)
i=0
return_array = []
while i < array.length do
return_array[i] = -1*array[i]
i += 1
end
return_array
end
def map_to_no_change(array)
i=0
return_array = []
while i < array.length do
return_array[i] = array[i]
i += 1
end
return_array
en... | true |
1831f2d8821821e692dfc575e8ab66edffac656b | Ruby | adlotz/movie_search | /app/services/search_movie.rb | UTF-8 | 373 | 2.71875 | 3 | [] | no_license | class SearchMovie
def initialize(movie_name)
@movie = movie_name
end
def perform
log_mdb
find_movies(@movie)
end
def log_mdb
Tmdb::Api.key(ENV['keydb'])
end
def find_movies(movie)
Tmdb::Search.movie(movie).results.each do |movie|
director = Tmdb::Movie.director(movie.id).each do |director|
m... | true |
bf11dbf1ea8d68384a68cd412e2f5a193105d357 | Ruby | kferko/GKMicroBlog | /models.rb | UTF-8 | 4,740 | 2.921875 | 3 | [] | no_license | class User < ActiveRecord::Base
# users rate and write about individual dishes
has_many :reviews
# users can follow other users
has_many :user_friends, through: :user_friendships
has_many :user_friendships
def followers # users are followed by followers
followerships = UserFriendship.where(user_friend_id: self.i... | true |
42500600d5257ce32c9539424279d7dc37b56ff7 | Ruby | rjammal/AppAcademy | /wk01/d4/eval_block.rb | UTF-8 | 105 | 2.828125 | 3 | [] | no_license |
def eval_block(*args, &prc)
unless block_given?
puts "NO BLOCK GIVEN!"
end
prc.call(*args)
end | true |
ebef9a65b4d628452a8264638c305cac2a8e0eb9 | Ruby | Khalosh/ror-tasks | /task-2/lib/todo_list.rb | UTF-8 | 1,410 | 2.90625 | 3 | [] | no_license | class TodoList
# Initialize the TodoList with +items+ (empty by default).
def initialize(parameters=[])
@network = parameters[:social_network]
@parameters = parameters
raise IllegalArgument if parameters[:db].nil?
end
def empty?
@parameters[:db].items_count == 0
end
def size
... | true |
53d263aaa9963b258f82625f34f19579f6ca097a | Ruby | centresource/temping | /lib/temping.rb | UTF-8 | 1,511 | 2.65625 | 3 | [
"MIT"
] | permissive | require "active_record"
require "active_support/core_ext/string"
class Temping
class << self
def create(model_name, &block)
connect unless ActiveRecord::Base.connected?
model_class_name = model_name.to_s.classify
if eval("defined?(#{model_class_name})")
model_class_name.constantize
... | true |
8be78fdaa8d31a7358ebdb9a196bb815491182db | Ruby | ysbaddaden/rbs | /lib/rbs/parser.rb | UTF-8 | 18,750 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'rbs/errors'
require 'rbs/parser/node'
module RBS
LHS = %i(identifier member_expression)
INLINE_TERM = %i(EOF else elsif end when })
BINARY_PRECEDENCE = {
'||' => 1,
'&&' => 2,
'|' => 3,
'^' => 4,
'&' => 5,
'==' => 6,
'!=' => 6,
'<' => 7,
'>' => 7,
'... | true |
0380b65bb7e0ad8171d7b9b6b089ebf3576a60d1 | Ruby | AdrianCann/boilerplate | /ruby_boil.sh | UTF-8 | 585 | 2.578125 | 3 | [] | no_license | #!/usr/bin/ruby
arg_one = ARGV[0]
raise 'Need argument' unless arg_one
name = arg_one.downcase
camelcase = name.split('_').collect(&:capitalize).join
def mkdirifnone_exists(name)
Dir.mkdir(name) unless File.exists?(name)
end
mkdirifnone_exists "lib"
mkdirifnone_exists "spec"
File.open("lib/#{name}.rb", "w") do |f... | true |
f3cc868b4a7f0b574193c21473fd2e59963703fb | Ruby | AfreenMunshi/CrowdFunding | /lib/tasks/campaign.rake | UTF-8 | 729 | 2.609375 | 3 | [] | no_license | namespace :campaign do
desc "TODO"
task stop: :environment do
campaigns = Campaign.where('closed_date is null')
closable_campaigns = campaigns.select do |camp|
(camp.created_at + camp.days.days < Date.today)
end
puts "\nFOUND #{closable_campaigns.length} campaigns whose date are due"
c... | true |
c1956eb94933552946a04bf9791ed4317ad3e52b | Ruby | pcarolan/hi-svg | /test/hi_test.rb | UTF-8 | 1,936 | 2.90625 | 3 | [
"MIT"
] | permissive | class HiTest < ActiveSupport::TestCase
def setup
@line_object = {:id => "l2", :x1 => 200, :y1 => 200,:x2 => 400, :y2 => 400, :stroke => "red"}
end
# lines
test "a line has accurate dimensions" do
assert_includes Hi.line(@line_object), "<line id=\"l2\" x1=\"200\" y1=\"200\" x2=\"400\" y2=\"400\""
en... | true |
3876a4788f97872bc573e22f58a2afa1e6d0629e | Ruby | wingrunr21/backbone-computedfields-rails | /Rakefile | UTF-8 | 1,692 | 2.578125 | 3 | [
"MIT"
] | permissive | require "bundler/gem_tasks"
require 'open-uri'
require 'json'
# Helper Functions
def name
@name ||= Dir['*.gemspec'].first.split('.').first
end
def version
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end
def latest_tag
tags = JSON.parse(op... | true |
1650981943b23895ccf03921a7f1f0579d1dbb29 | Ruby | Folashade/Creamery | /app/models/assignment.rb | UTF-8 | 3,389 | 2.71875 | 3 | [] | no_license | class Assignment < ActiveRecord::Base
# Callbacks
# --------------------
# ends previous assignment before adding a new one
before_create :end_previous_assignment
before_save :store_active?
before_save :employee_active?
# Relationships
# -----------------------------
belongs_to :store
belongs_to ... | true |
01a8206e5cc0bb92ce64bfeb64d1b243c7d65864 | Ruby | tyler-rand/console_game | /windows/right_window.rb | UTF-8 | 1,966 | 3.265625 | 3 | [] | no_license | require 'curses'
# right window, displays player stats
class RightWindow
attr_accessor :win
def initialize
@win = Curses::Window.new(36, 30, 0, 70)
box_with_title
@win.refresh
end
def box_with_title
@win.box('|', '-')
@win.setpos(0, 7)
@win.attron(Curses.color_pair(3)) { @win.addstr('... | true |
8b698dc1dad8b9a680fe86d38238b845547bbc1f | Ruby | keirmacd/Record-store-project | /db/seeds.rb | UTF-8 | 790 | 2.515625 | 3 | [] | no_license | require('pry-byebug')
require_relative ('../models/artist')
require_relative ('../models/album')
require_relative ('SqlRunner.rb')
@artist1 = Artist.new ({
"name" => "Reel Big Fish"})
@artist2 = Artist.new ({
"name" => "Less Than Jake"})
@artist3 = Artist.new ({
"name" => "Operation Ivy"})
@artist1.save
@arti... | true |
1cd6e7eb35f2da46854e6a493e685c8a8cd77749 | Ruby | henryco1/LS100 | /lesson1_basics/exercise2.rb | UTF-8 | 443 | 4.21875 | 4 | [] | no_license | =begin
Use the modulo operator, division, or a combination of both to take a 4 digit number and
find the digit in the: 1) thousands place 2) hundreds place 3) tens place 4) ones place
=end
puts "Input a four digit number: "
num = gets.chomp
num = num.to_i
thousands_place = num / 1000
hundreds_place = num % 1000 / 10... | true |
3b71216831d171232262dc28cec4efabe272cfcc | Ruby | splattael/meta_code_commenter | /test/test_meta_code_commenter.rb | UTF-8 | 1,035 | 2.625 | 3 | [] | no_license | require 'helper'
context "Generates output" do
def asserts_output(description, input, expected, args={})
input.chomp!
expected.chomp!
asserts(description) do
MetaCodeCommenter::Generator.new(input.split(/\n/), args).to_s
end.equals(expected)
end
asserts_output("empty", <<-'IN', <<-'OUT')
... | true |
420eca1b9c34d4408ca5bda792194c242d0901c6 | Ruby | adusome/MemoryGame | /main.rb | UTF-8 | 1,724 | 3.5 | 4 | [] | no_license | puts "\n\n\n\nWelcome to the Memory Game!!!\n\n\n\n"
topic = ""
sleep(1)
# load the topic list
topic_name_list = Hash.new
topic_name_list["states"] = "us_states.txt"
topic_name_list["ttc stations"] = "ttc_stations.txt"
topic_name_list["nhl teams"] = "nhl_teams.txt"
topic_name_list["european countries"] = "e... | true |
a5eaebee3d220a4431a4f4c437977042918a67c5 | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz30_sols/solutions/Gavin Kistner/barrel_of_tests.rb | UTF-8 | 2,674 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'test/unit'
require 'barrel_of_classes.rb'
class SongTest < Test::Unit::TestCase
def test_cleaning
song_name = 'Hello World'
clean_name = song_name.downcase
s1 = Song.new( song_name )
assert_equal( clean_name, s1.clean_name )
song_name = 'Hello World (remix)'
... | true |
63afbcbe48950ff8053c0d76249e21138c2e1d16 | Ruby | kacesera/bank-tech-test | /lib/atm.rb | UTF-8 | 807 | 3.359375 | 3 | [] | no_license | require_relative 'atm_printer'
require_relative 'transaction'
class ATM
def initialize(transaction_class = Transaction, atm_printer = ATMPrinter)
@atm_printer = atm_printer
@transaction_class = transaction_class
@balance = 0
@transactions = []
end
def check_balance
@balance.round(2)
end
... | true |
5431a8c442a773a8e5b719bc94aa7fb9062c27d9 | Ruby | lefthandme/ideal-postcodes-ruby | /lib/idealpostcodes.rb | UTF-8 | 2,360 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'rest-client'
require 'uri'
require 'multi_json'
require 'cgi'
require 'idealpostcodes/version'
require 'idealpostcodes/postcode'
require 'idealpostcodes/util'
require 'idealpostcodes/errors'
module IdealPostcodes
@base_url = 'https://api.ideal-postcodes.co.uk'
@version = '1'
class << self
attr_accessor ... | true |
e2b8e478b71c489eb6e69ec3ccee81c1f7d099c5 | Ruby | gatorjuice/acltc | /week1/pair_programming/groups.rb | UTF-8 | 751 | 3.21875 | 3 | [] | no_license | system('clear')
puts "Welcome to the ROOM SPLI-TTER".center(63)
puts "The ONLY way to divide the people in the room into groups ever."
puts
puts "Start typing in the group members names: (just press return when complete)"
names = []
name = gets.chomp
names << name
until name == ""
puts "NAME ADDED, ENTER ANOTHER O... | true |
85809bfbf57731dd837788b64bec62f3166c7380 | Ruby | CaioFML/star_wars_swapi | /lib/star_wars_api/characters/request.rb | UTF-8 | 676 | 2.640625 | 3 | [] | no_license | module StarWarsAPI
module Characters
class Request
STAR_WARS_URI = "https://rawcdn.githack.com/akabab/starwars-api/0.2.1/api/all.json".freeze
# rubocop:disable Naming/AccessorMethodName
def get_people
@response = HTTParty.get(STAR_WARS_URI)
parse_response
end
# rubo... | true |
283919b9c2b3e028e0eb2e43ce3c38e1197bd748 | Ruby | orlandorubydojo/string_calculator | /lib/string_calculator.rb | UTF-8 | 173 | 3.265625 | 3 | [] | no_license | class StringCalculator
def add(string_number)
return 0 if string_number.empty?
string_number.split(",").map{|string_num| string_num.to_i }.inject(0,:+)
end
end
| true |
ce97eff3597ba5b3414185709fbb5c0e975a471b | Ruby | NikitaSmall/ruby-lessons | /hm_one.rb | UTF-8 | 34 | 2.8125 | 3 | [] | no_license | str = gets.chomp
puts str.reverse
| true |
2d2906939fe65c4765e46536c0b720da9cda8a51 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/space-age/5b801406e9054891b9168fc031c9c38b.rb | UTF-8 | 646 | 3.34375 | 3 | [] | no_license | class SpaceAge
attr_reader :seconds
def initialize(seconds)
@seconds = seconds
end
period_factors = { earth: 1.0,
mercury: 0.2408467,
venus: 0.61519726,
mars: 1.8808158,
jupiter: 11.862615,
... | true |
89f9aeeb809676fa22d54fb1d671d0dfea331dde | Ruby | kmc653/OO_Tic-Tac-Toe | /tictactoe.rb | UTF-8 | 2,203 | 3.875 | 4 | [] | no_license | class Board
WIN_CONDITION = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8],
[3, 6, 9], [1, 5, 9], [3, 5, 7]]
def initialize
@square = {}
(1..9).each {|pos| @square[pos] = ' '}
end
def empty_position
@square.select {|_, v| v == ' '}.keys
end
def mark_square(pos, marke... | true |
09e1217d55972dbb988d41e41036787cb3cca91d | Ruby | knowuh/resource_squasher | /lib/resource_squasher/file_entry.rb | UTF-8 | 2,241 | 2.640625 | 3 | [
"MIT"
] | permissive | module ResourceSquasher
class FileEntry
attr_accessor :old_base
attr_accessor :base
attr_accessor :old_name
attr_accessor :name
attr_accessor :uniq_level
attr_accessor :name_root
def initialize(_rez_path, _old_base, _new_base="/tmp", name=nil)
self.old_name = _rez_path
sel... | true |
9c94dde53987b974735753e3c5408a03d17efb00 | Ruby | leftees/complete-me | /test/complete_me_test.rb | UTF-8 | 722 | 3 | 3 | [] | no_license | require_relative 'test_helper'
require 'minitest/autorun'
require 'complete_me'
class NodeTest < Minitest::Test
def setup
@node = Node.new
end
def test_new_object_gets_created_in_the_Node_class
assert_equal Node, @node.class
end
end
class CompleteMeTest < Minitest::Test
def setup
@complet... | true |
367a2c0505e770a4129a5e39aae7dd05f923a51d | Ruby | Kassim95/Rock_paper_scissor | /rock_paper_scissors.rb | UTF-8 | 1,552 | 3.984375 | 4 | [] | no_license | user_wins = 0
ai_wins = 0
def game(your_wins, cpu_wins)
# Rock Paper Scissors
puts "Welcome to rock, paper, scissors"
user_choice = ""
until user_choice == 'paper' or user_choice == 'rock' or user_choice == 'scissors'
# ask the user for their selection
puts "Please enter paper, rock, ... | true |
8b8f044e166b87eb455afce0871b1ddbd3b7bcc0 | Ruby | rNavarrete/frita | /spec/models/items_spec.rb | UTF-8 | 1,548 | 2.828125 | 3 | [] | no_license | require 'spec_helper'
describe "creating an item" do
it "should have a title" do
item = Item.new(title: "Crickets", description: "crunchy")
expect(item.title).to eq "Crickets"
end
it "should have a description" do
item = Item.new(description: "Crunchy")
expect(item.description).to eq "Crunchy"... | true |
8c357753b30301f6f1a0a25c278a7256168e37ea | Ruby | dsilberschmidt/Euler | /37.rb | UTF-8 | 373 | 3.34375 | 3 | [] | no_license | require 'prime'
class Integer
def trunc?
(1..self.to_s.length-1).inject(true){|memo,c| memo=memo && ( self.to_s[0..-c-1].to_i.prime?) && ( self.to_s[c..-1].to_i.prime?)}
end
end
def struncs
s,n=0,0
p=Prime.new
while n<11 do
pr=p.succ
if pr < 10 then next
end
if pr.trunc? then
s+=... | true |
8990fc0f916141d2f91716e25ee40a4e0e9de3c2 | Ruby | 747/redcloth-parslet | /spec/parser/inline/shared_examples_for_simple_inline_elements.rb | UTF-8 | 3,923 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | shared_examples 'a simple inline element' do |rule_name, mark, ast_class|
# These were conceived as examples for strong (*) but apply to all simple inlines
describe "specific parser rule" do
it "should consume a #{rule_name} word" do
parser.send(rule_name).should parse("#{mark}hey#{mark}")
end
it... | true |
5bc4a8ad1468b82c457779236e5d1e6f39b92ec3 | Ruby | fonzo14/myfirstnn | /lib/myfirstnn/embeddings.rb | UTF-8 | 804 | 3.109375 | 3 | [] | no_license | class Embeddings
UNK = 'unk'
attr_reader :dimensions_count
def initialize(file)
@text2id = { UNK => 0 }
@id2text = { 0 => UNK }
@embeddings = {}
IO.foreach(file).with_index do |line,i|
if i < 1000000002
#puts i if (i % 5000).zero?
if i.zero?
@size, @dimens... | true |
fd56f1236250d68ddfda499a7e23d82f94deba15 | Ruby | programmurr/knights_travails | /main.rb | UTF-8 | 175 | 2.59375 | 3 | [] | no_license | # frozen_string_literal: true
require 'pry'
require_relative 'game'
game = Game.new
start = [game.x1, game.y1]
target = [game.x2, game.y2]
game.knight_moves(start, target)
| true |
d27b2915915751c477353530c8869909585ca568 | Ruby | martinpoljak/em-file-utils | /lib/em-file-utils.rb | UTF-8 | 2,498 | 2.8125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # encoding: utf-8
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
require "command-builder"
##
# Main EventMachine module.
# @see http://rubyeventmachine.com/
#
module EM
##
# Evented FileUtils.
#
module FileUtils
##
# Commands instances cache.
#
@@ca... | true |
edbee4c9c024d66c655d360b19dfd5af2ffe9725 | Ruby | sh-app/SimpleNote | /db/seeds.rb | UTF-8 | 2,140 | 2.53125 | 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 |
7e7438a25f9808fe0244ad4563fcba440678b707 | Ruby | jeantroiani/Airport_Flow_Control | /spec/airport_spec.rb | UTF-8 | 2,312 | 3.140625 | 3 | [] | no_license | require 'airport'
describe Airport do
let(:airport) {Airport.new}
before(:each) do
allow(airport).to receive(:weather_condition?).and_return(true)
end
it'is empty when created' do
expect(airport.parking_lot).to eq []
end
it'has a maximum default capacity of 6' do
expect(airport.capacity).t... | true |
5156e09a0ea349cce554890868668c5c10676a40 | Ruby | StephenKline09/First-Day-Respository | /lot_inventory.rb | UTF-8 | 1,419 | 3.546875 | 4 | [] | no_license | class NewCarForm
attr_reader :car
def initialize
@car = Car.new
@car.customer = ask_question("customer name").capitalize
@car.make = ask_question("make").capitalize
@car.model = ask_question("model").capitalize
@car.year = ask_question("year")
@car.price = ask_que... | true |
c49f7f6d4ef3922101c2b9c04967c6e28a9d6954 | Ruby | Grekz/coding-problems-ruby | /lib/mx/grekz/leetcode/easy/E437_PathSumIII.rb | UTF-8 | 650 | 3.515625 | 4 | [
"MIT"
] | permissive | # @author grekz
class E437_PathSumIII
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @param {Integer} s... | true |
57cedd607190d0477f77aced158664d53e57d613 | Ruby | joofsh/nava_takehome | /quality_measures_converter.rb | UTF-8 | 1,949 | 3.5625 | 4 | [] | no_license | require 'pry'
require 'json'
class QualityMeasuresConverter
def parse_filename(filepath)
filepath.split('/').last.split('.').first
end
# This method loads all the schema files into memory, and loops through them
# creating a hash for each measure's schema
def schemas
@schema ||= Dir['schemas/*'].red... | true |
ec9f245750dadbfd8e3d6c91905aab4a8e303b1e | Ruby | patschramm/aA-classwork | /Week-4/W4D1/TicTacToe-AI/lib/tic_tac_toe_node.rb | UTF-8 | 1,457 | 3.40625 | 3 | [] | no_license | require_relative 'tic_tac_toe'
require 'byebug'
class TicTacToeNode
attr_reader :board, :next_mover_mark, :prev_move_pos
def initialize(board, next_mover_mark, prev_move_pos = nil)
@board = board
@next_mover_mark = next_mover_mark
@prev_move_pos = prev_move_pos
end
def losing_node?(evaluator)
... | true |
545e04d03d552976cc1cb8a6d6dc9328a555c5bf | Ruby | rshiva/MyDocuments | /01-notes-programming /04-ruby+rails/ruby1.9/samples/extruby_43.rb | UTF-8 | 496 | 3.3125 | 3 | [] | no_license | #---
# Excerpted from "Programming Ruby",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www... | true |
3be6da66e0e5a40744e164769debaa4b2ddb5d2b | Ruby | mathphreak/prodenfd | /enforcers/battle.net.rb | UTF-8 | 646 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'sys/proctable'
# require 'win32/process'
require 'andand'
module Enforcers
# Kill Steam if Steam is running.
class BattleDotNet
include Sys
def initialize(settings)
@bnet_folder = settings['bnet-folder']
end
def run
bnet_running = ProcTable.ps.any? do |p|
p.cmdline.an... | true |
301d1ac3cee08979513ab4a79ab4a09c46096fd6 | Ruby | YutoKashiwagi/competitive_programming | /AtCorder/B/Coins.rb | UTF-8 | 290 | 2.984375 | 3 | [] | no_license | # カンニングしたやつ
# 問題URL: https://beta.atcoder.jp/contests/abc087/tasks/abc087_b
a, b, c, x = 4.times.map { gets.to_i}
count = 0
(0..a).each do |d|
(0..b).each do |e|
(0..c).each do |f|
count += 1 if d * 500 + e * 100 + f * 50 == x
end
end
end
p count
| true |
fe0ad387b9d358a4590e7e6a9e61f6e35b55ce4c | Ruby | lchangdev/game-time | /server.rb | UTF-8 | 1,875 | 2.90625 | 3 | [] | no_license | require 'sinatra'
require 'csv'
require 'shotgun'
require 'pry'
# Methods
def load_data
master_data = []
CSV.foreach('team_data.csv', headers: true, converters: :all) do |row|
master_data << row.to_hash
end
master_data
end
def team_data
team_name = []
CSV.foreach('team_names.csv', headers: true, conv... | true |
4d7e38a0d841acbfb7a5f2a5d988406a2d873a28 | Ruby | adambure21/ruby_code_snippets | /Dec5/1_D_array_create_Object_construction_way.rb | UTF-8 | 661 | 3.65625 | 4 | [] | no_license | #Other method to create array is to Use the Array.new() method.
#a = Array.new(array_size,Default_value)
#To give command to terminal via a programme we can use backquotes.
print "Other way to create Array using new method of Array Class"
array = Array.new(1,2) #Array.new() will only take the two arguemnts .
# first... | true |
da3a339322784b27f61847ae93dc06de6558af40 | Ruby | ninkibah/railsstrap | /app/helpers/railsstrap/date_picker_helper.rb | UTF-8 | 3,628 | 2.71875 | 3 | [
"MIT"
] | permissive | # Railsstrap Datepicker Helper
#
# Setup instructions:
# open your application.js & application.css asset manifest file and uncomment the block to include the UI libraries
# use the date_picker helper for the html and the date_picker_javascript helper in your templates
#
# You can set these options a few ways:
# with h... | true |
96c16aebc05f2e13d58491aec54abf7b1b437a20 | Ruby | jhon-ran/tic_tac_toe | /lib/game.rb | UTF-8 | 1,609 | 3.953125 | 4 | [] | no_license | require 'board'
require 'show'
require 'player'
class Game
attr_accessor :current_player, :status, :board, :array_players, :count_turn
def initialize
# Players in an array
@player1 = Player.new("Player 1")
@player2 = Player.new("Player 2")
@array_players = [@player1, @player2]
@current_player = ... | true |
4dba27519b58c39baa6e2aa72b56a2b7f02f60e5 | Ruby | mbulat/sonic | /lib/sonic/service_checker.rb | UTF-8 | 1,091 | 2.53125 | 3 | [
"MIT"
] | permissive | module Sonic
class ServiceChecker
attr_accessor :protocol
attr_accessor :host
attr_accessor :port
attr_accessor :username
attr_accessor :password
attr_accessor :vhost
attr_accessor :path
attr_accessor :payload
attr_accessor :ssl_key
attr_accessor :ssl_cert
attr_accessor :r... | true |
ddcc190ab28d965d55fdbb2dc7bde7082cf0f62f | Ruby | RobinClowers/photo-album | /app/mappers/favorites_mapper.rb | UTF-8 | 920 | 3.1875 | 3 | [
"MIT"
] | permissive | class FavoritesMapper
attr_reader :favorites, :current_user
def initialize(favorites, current_user)
@favorites = favorites
@current_user = current_user
end
def self.map(favorites, current_user)
new(favorites, current_user).map
end
def map
{
"count" => favorites.length,
"names"... | true |
8dc380aa7aa8874c8dc9bd4ccaa84e7afe9e5c42 | Ruby | tarasdemyanets/LinkUp-practice | /03_simon_says/simon_says.rb | UTF-8 | 583 | 3.90625 | 4 | [] | no_license | def echo(s)
return s
end
def shout(s)
return s.upcase
end
def repeat(s, repeat=2)
s += ' '
s *= repeat
s = s.strip
s
end
def start_of_word(word, letters)
word[0..letters - 1]
end
def first_word(s)
s = s.split(' ')
word = s[0]
word
end
def titleize(expression)
articles = %w[of the a to in of o... | true |
8aefd5dbc6de19e07467a596e06edf125a2fef3c | Ruby | loust333/ruby-workspace | /zip_codes.rb | UTF-8 | 631 | 3.796875 | 4 | [] | no_license | zips = { 'differdange' => '4670',
'esch' => '3455',
'niederkorn' => '1234' }
def get_city_names(dictionnary)
dictionnary.each { |city, _| puts city }
end
loop do
puts 'Do you want to play the game?'
prompt = gets.chomp.downcase
break if prompt != 'y'
if prompt == 'y'
get_city_names(zi... | true |
f0789a06d39315e7ae6d6729de02b2852547c837 | Ruby | ifad/colore | /lib/heathen/errors.rb | UTF-8 | 1,872 | 3 | 3 | [
"MIT"
] | permissive | #
# Errors used by Heathen
#
module Heathen
# Abstract heathen error class
class Error < StandardError; end
# Raised by task [Processor] method when a pre-condition (such as mime-type) is not valid.
class ExpectationNotMet < Error
def initialize name, value, pattern
super "Expectation failure on #{na... | true |
b3d955fc359a6d9a126f20b68445803ba4e89b72 | Ruby | lireirelico/thinknetica_course | /Lesson_2/task6.rb | UTF-8 | 1,162 | 3.796875 | 4 | [] | no_license | require 'colorize'
TEXT = {
height_error: 'Не корректный ввод число. Введите положительное число без символов!'.red,
}
def create_products
products = []
loop do
hash = {}
name = get_value('название товара')
break unless name
hash[name] = {}
hash[name]['price'] = get_value('цену')
hash[... | true |
183854007ea56a0fc804363bc0c9228406d7f68b | Ruby | benrodenhaeuser/exercises | /exercism/ruby/nth-prime/nth_prime.rb | UTF-8 | 421 | 3 | 3 | [] | no_license | class Prime
def self.nth(n)
raise ArgumentError if n < 1
current_prime = 2
list = [current_prime]
until list[n - 1]
next_prime = current_prime + 1
loop do
break if list.all? { |number| next_prime % number != 0 }
next_prime += 1
end
list << next_prime
... | true |
5aff3efc2fbeb6b4263807f3ff8ff21fa13964e7 | Ruby | AanderBahn/Tax_Trax | /app/models/job.rb | UTF-8 | 193 | 2.515625 | 3 | [] | no_license | class Job < ActiveRecord::Base
belongs_to :user
has_many :trips
def total_miles
total = 0
self.trips.each do |trip|
total += trip.miles
end
return total
end
end
| true |
3109cdde31b4637f8e095c2c0d70f497bfcb811f | Ruby | HashPoW/graftwelcomebot | /lib/response/chat_mode.rb | UTF-8 | 885 | 2.609375 | 3 | [] | no_license | require './lib/message_sender'
require './lib/main_request'
Dir['./models/*'].each {|file| require file unless File.directory?(file)}
class ChatMode
include MainRequests
attr_reader :message
attr_reader :bot
attr_reader :user
attr_reader :chat
def initialize(options)
@bot = options[:bot]
@messa... | true |
eec82108eafdce2967a822df9224e22631301179 | Ruby | curlygirly/rps-challenge | /lib/game_engine.rb | UTF-8 | 514 | 3.171875 | 3 | [] | no_license | class GameEngine
attr_accessor :player_choice
def result(player_choice)
if
player_choice == :rock && cpu_choice == :scissors ||
player_choice == :scissors && cpu_choice == :paper ||
player_choice == :paper && cpu_choice == :rock
puts :WIN
elsif
player_choice == cpu_choice
... | true |
0d9e14ab61d2684b40ceeb7de5ad497eac8df0cf | Ruby | flyerhzm/rails_best_practices | /lib/rails_best_practices/reviews/protect_mass_assignment_review.rb | UTF-8 | 3,537 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module RailsBestPractices
module Reviews
# Review model files to make sure to use attr_accessible, attr_protected or strong_parameters to protect mass assignment.
#
# See the best practices details here https://rails-bestpractices.com/posts/2012/03/06/protect-mass-assignment... | true |
53c563e32949259cfd7e88381f81209b75b3d95f | Ruby | yuya-yamaguchi/studio_reserve_app | /app/models/post.rb | UTF-8 | 916 | 2.78125 | 3 | [] | no_license | class Post < ApplicationRecord
belongs_to :user
validates :title, presence: true
validates :contents, presence: true
enum post_type: {
"---": 0,
"バンドメンバー募集": 1,
"バンド参加希望": 2,
"その他": 99
}, _prefix: true
def self.search(search_params)
post_type_num = post_... | true |
af813a95c7996c909a12290479a90c836805c14b | Ruby | oliveira-andre/calc_bills | /src/services/spent_service.rb | UTF-8 | 2,485 | 3.546875 | 4 | [] | no_license | # frozen_string_literal: true
require 'bigdecimal'
class SpentService
def initialize
@spent_value = 0
@spent_name = 0
@total_spent = 0
@total_amount = 0
@column_space = 35
end
def execute
puts
load_values
raw_result
puts
end
private
def load_values
%w[spent_name ... | true |
b28d23255c5d1a13971146b44c7e588e8f3b9844 | Ruby | ish-lynxrufus/lunch-calendar | /app/models/calendar.rb | UTF-8 | 861 | 2.515625 | 3 | [] | no_license | class Calendar
APPLICATION_NAME = ENV['GOOGLE_CALENDAR_APPLICATION_NAME'].freeze
CALENDAR_ID = ENV['GOOGLE_CALENDAR_ID'].freeze
def initialize
@service = calendar_service
@calendar_id = CALENDAR_ID
end
def events
@service.list_events(
@calendar_id,
time_min: 30.minute.since.iso8601,
... | true |
b459dc7675f8d772f0e253f0503ecee459915b9f | Ruby | paulfioravanti/pianoforall | /section03/lesson03/trouble.rb | UTF-8 | 802 | 2.671875 | 3 | [
"MIT"
] | permissive | # Section 3 - Lesson 3 - New Chords Cm, Fm, Gm, Db, Eb, Ab
# Trouble - Coldplay
require "#{Dir.home}/ruby/pianoforall/section03/lesson03/half_beat_bounce"
use_synth :piano
use_bpm 40
in_thread(name: :right_hand) do
half_beat_bounce_treble(:F4, shift: -2)
half_beat_bounce_treble(:D4, :minor, shift: -1)
2.times do... | true |
5d67de261007c900d1f7258d08d65b88dc56bbe3 | Ruby | 3t8U/Ruby_Rock-Paper_Scissors | /spec/find_and_replace_spec.rb | UTF-8 | 323 | 2.890625 | 3 | [] | no_license | require ('rspec')
require ('find_and_replace.rb')
describe('find_and_replace') do
it( "Returns a new string replaced with words replaced") do
str = Finder.new("She sells sea shells by the sea shore")
expect(str.find_replace("sea", "seal")).to(eq("She sells seal shells by the seal shore"))
end
e... | true |
f916ada80ce305be0c93507061e7a4a21b8e5b4a | Ruby | earl-stephens/jungle_beats | /lib/jungle_beat.rb | UTF-8 | 349 | 3.171875 | 3 | [] | no_license | require 'pry'
class JungleBeat
attr_reader :list
def initialize
@list = LinkedList.new
end
def append(data)
individual_data = data.split(' ')
individual_data.each do |datum|
@list.append(datum)
end
end
def count
@list.count
end
def play
beats = @list.to_string
`say... | true |
8572a3a497a6f82ef8b71cffaa5e78f0192e4e86 | Ruby | Jlesse/sudoku_solver | /source/sudoku.rb | UTF-8 | 7,157 | 3.640625 | 4 | [] | no_license | #Takes a board as a string in the format
#you see in the puzzle file. Returns
#something representing a board after
#your solver has tried to solve it.
# create sudoku_board array containing all sudoku values
# Define add_number(sudoku_board, index = 0)
# Iterate through array of numbers 1-9 |number|
# IF number s... | true |
4c8860c8c4450f587101f8a1a87bbd603d3b2f6e | Ruby | alpendergrass/montanacycling-racing_on_rails | /test/unit/race_number_test.rb | UTF-8 | 13,158 | 2.5625 | 3 | [
"Ruby",
"MIT"
] | permissive | require "test_helper"
class RaceNumberTest < ActiveSupport::TestCase
def test_defaults
assert_not_nil(NumberIssuer.find_by_name(ASSOCIATION.short_name), 'Number issuer exists')
race_number = RaceNumber.new(:value => '999', :person => people(:alice))
race_number.save!
assert_equal(Date.today.year, rac... | true |
6c35f0340e90cf75c359e0928cacedec9fc6fd28 | Ruby | Vladimir9858713/a | /fourth_task.rb | UTF-8 | 351 | 3.140625 | 3 | [] | no_license | class FourthTask
def find hash
hash.each do |key, value|
if key == "key9".to_sym
puts value
end
if value.class == Hash
find(value)
end
end
end
end
fourth = FourthTask.new
hash = { key1: {}, key2: {}, key3: { key4: 'str', key5: 'str2', key6: { key7: { key8: 1, ke... | true |
f705257c96822ead030ba90d8e5af8e256893520 | Ruby | IanPFoertsch/Proposition | /lib/proposition/parser/lexer.rb | UTF-8 | 3,351 | 3.796875 | 4 | [] | no_license | module Proposition
module Parser
class Lexer
OPEN_PARENTHESIS = "("
CLOSE_PARENTHESIS = ")"
SLASH = "/"
WHITESPACE = [" ", "\t"]
TERMINALS = [";", "\n"]
AND = "and"
OR = "or"
XOR = "xor"
IMPLICATION = "=>"
BICONDITIONAL = "<=>"
NOT = "not"
... | true |
a2ab2df1ffb4bd4def0500cf1e1cd4d8cf32d44a | Ruby | chopmo/project-euler-solutions | /74/main.rb | UTF-8 | 829 | 3.375 | 3 | [] | no_license | # Very slow, takes minutes
$fact_cache = {}
class Integer
def fact
$fact_cache[self] ||= (2..self).inject(1) { |f, n| f * n }
end
def fact_sum
i = self
res = 0
while i > 0
res += (i % 10).fact
i /= 10
end
res
end
end
@chain_lengths = {}
def num_non_repeating_terms(i)
x ... | true |
516987c34f89a70fc5942b00e8fd7ab2a3a3bf6e | Ruby | lazyrayza/sessions | /db/seeds.rb | UTF-8 | 10,213 | 2.734375 | 3 | [] | no_license | puts "destroying users"
Review.destroy_all
ChatRoom.destroy_all
Booking.destroy_all
puts "destroyed users"
puts "destroying reviews"
puts "destroyed reviews"
puts "Starting seed"
puts "making languages"
english = Language.create!(
language_name: "Portuguese",
)
english = Language.create!(
language_name: "Englis... | true |
659ac8aee65170f5d9da762013dabe145b385132 | Ruby | Jonathan1031r/Ironhack | /week1/day3/day3exer.rb | UTF-8 | 206 | 2.921875 | 3 | [] | no_license | hash = {:wat=>[0,1,2{:wut=>[0,1[[1,2,3,4,5,6,7,8,9{:bbq=>"YOOOO!!"}]]]}]}
#arr = [[0,1,2,3,4,5{:secret=>{:unlock=>[0,1]}}]]
puts hash[:wat][2][:wut]#[1]#[0][9][:bbq]
#puts arr[0][5][:secret][:unlock][1] | true |
aac518725e9712a989225efa847d4c295620a433 | Ruby | lmshepherd1/hw2fall15 | /lib/part5.rb | UTF-8 | 592 | 3.828125 | 4 | [] | no_license | class CartesianProduct
include Enumerable
def initialize(sequence1, sequence2)
# if sequence1.class is iterable and sequence2.class is iterable
if sequence1.respond_to? :each and sequence2.respond_to? :each
# determine whether each index is the correct format
@sequence1 = sequence1
@seque... | true |
95f00a0bf1240572c00503d04ac49ddf22537496 | Ruby | nobu/stderr-p | /test/test_stderr_p.rb | UTF-8 | 516 | 2.71875 | 3 | [
"Ruby",
"BSD-2-Clause"
] | permissive | # -*- coding: us-ascii -*-
require 'test/unit'
require 'tempfile'
require_relative '../lib/stderr/p'
class TestSTDERR < Test::Unit::TestCase
def test_p
args = [[1,2,3], {foo: "bar"}]
result = Tempfile.open("x") do |tmp|
tmp.close
begin
stderr = STDERR.dup
STDERR.reopen(tmp.path)
... | true |
8cdbd804ac65ae0bc8b5b1d85ce83814ab842a41 | Ruby | AgileVentures/gatherer | /app/models/project.rb | UTF-8 | 798 | 2.546875 | 3 | [] | no_license | class Project < ApplicationRecord
include Sizeable
has_many :tasks, dependent: :destroy
validates_presence_of :name
def self.velocity_window_in_days
21
end
def unfinished_tasks
tasks.select(&:unfinished?)
end
def done?
unfinished_tasks.none?
end
def remaining_size
unfinishe... | true |
88c0cc58a58772277d03c4a06de8411899d43056 | Ruby | Souravgoswami/ruby-masterclass | /Section 9: Conditions/Part6_The_&&_&_and_operators.rb | UTF-8 | 4,272 | 4.90625 | 5 | [
"Unlicense",
"LicenseRef-scancode-proprietary-license"
] | permissive | #!/usr/bin/ruby -w
# PART 6
# The & and | are methods on some of the objects in Ruby.
# The &&, ||, or are short-circuit operators
# In case of short-circuit evaluators the second argument
# is evaluated only if the first argument succeeds of fails.
# Let's look at & first
# returns true if both the caller object an... | true |
cca3116b6f55856849a142e1e40b0d581916b174 | Ruby | divniy/task_manager | /test/unit/story_test.rb | UTF-8 | 1,902 | 2.53125 | 3 | [] | no_license | require 'test_helper'
class StoryTest < ActiveSupport::TestCase
setup do
@user = Factory(:user)
@attr = { title: "Test Task", content: "Some text" }
end
test "should create new story" do
story = @user.stories.create(@attr)
assert story.save
end
test "should have user attribute" do
story... | true |
54d3c20350ffb9be509238342b31897dd1c92ad9 | Ruby | grant-olson/rubygems-openpgp | /lib/rubygems/commands/sign_command.rb | UTF-8 | 1,129 | 2.59375 | 3 | [] | no_license | require "rubygems/command"
require "rubygems/package"
require 'rubygems/version_option'
require "rubygems/gem_openpgp"
require 'fileutils'
# CLI interface to the internal signing code:
#
# gem sign gemname-0.0.0.gem
#
# gem sign -key 0xDEADBEEF gemname-0.0.0.gem
class Gem::Commands::SignCommand < Gem::Command
i... | true |
c68148fa813374949f520f6a1ab10482bb71c886 | Ruby | garcia50/bon_appetit | /lib/pantry.rb | UTF-8 | 1,317 | 3.34375 | 3 | [] | no_license | require './lib/recipe'
require 'pry'
class Pantry
attr_reader :stock,
:shopping_list
def initialize
@stock = {}
@shopping_list = {}
@add_to_cookbook = {}
end
def stock_check(food)
if !@stock.has_key?(food)
0
else
@stock[food]
end
end
def restock(food, nu... | true |
e5e709b3dbd606f5a71d86fb3e96231644afcedf | Ruby | knoxknox/ce250-course | /materials/14/pgm14_07.rb | UTF-8 | 160 | 3.421875 | 3 | [] | no_license | def fibonacci(n)
if n == 0 or n == 1
return n
else
if n % 2 == 0
return a * (a + 2 * b)
else
return a * a + b * b
end
end
end
| true |
29d02b41144e7c7418643b417519308c4a9680f7 | Ruby | fs-labs/dice-roll-ruby-nyc-web-060418 | /dice_roll.rb | UTF-8 | 139 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
# Feel free to google "how to generate a random number in ruby"
def roll
dice = [1, 2, 3, 4, 5, 6]
answer = dice[rand(dice.length)]
end
| true |
9bafeb118837517a146377f98b62890530a6897c | Ruby | LadyBuggs/programming-univbasics-4-array-concept-review-lab-online-web-prework | /lib/array_methods.rb | UTF-8 | 276 | 3.265625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def find_element_index(array, value_to_find)
counter = 0
while counter < array.length
if array[counter] == value_to_find
puts counter
end
end
def find_max_value(array)
# Add your solution here
end
def find_min_value(array)
# Add your solution here
end
| true |
4a65049558fd51fb9561d06209498511bd53e5c3 | Ruby | lkrych/ruby-algorithms | /week1multiplication/multiply_recur.rb | UTF-8 | 473 | 3.703125 | 4 | [] | no_license | def multiply(num1,num2)
if num2 == 1
return num1
else
return num1 + multiply(num1, num2 -1)
end
end
if ARGV.length != 2 #handle invalid input
puts "Usage: ruby multiply_recur.rb int1 int2"
return
end
num1 = ARGV[0].to_i
num2 = ARGV[1].to_i
answer = multiply(num1,num2)
puts "#{num1} * #{num2} is eq... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.