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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
77de6e25db3d0d1ca8bb3238d412ce4903822547 | Ruby | a-woodworth/ls_projects | /oop_book/section_4/exercise_7.rb | UTF-8 | 573 | 4.65625 | 5 | [] | no_license | # Create a class 'Student' with attributes name and grade. Do NOT make the grade getter public,
# so joe.grade will raise an error. Create a better_grade_than? method, that you can call
# like so...
# puts "Well done!" if joe.better_grade_than?(bob)
class Student
def initialize(name, grade)
@name = name
@g... | true |
0cb9f0e9c059b3877387ba0d0cd257eb480d442a | Ruby | zoexanos/programming-univbasics-4-array-simple-array-manipulations-part-2-chi01-seng-ft-062220 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 1,069 | 3.125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_concat(array, array2)
array.concat(array2)
end
my_favorite_things = ["raindrops on roses", "whiskers on kittens"]
more_favs = ["sports cars", "flatiron school"]
using_concat(my_favorite_things, more_favs)
def using_insert(array, object)
array.insert(4, object)
end
list_of_programming_languages = ["Ruby",... | true |
2d6850f83d21f721f6062de80262074fa00ed8ff | Ruby | kwalendzik/anagram-detector-online-web-pt-081219 | /lib/anagram.rb | UTF-8 | 184 | 3.453125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Your code goes here!
class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
def match(array)
array.select { |x| x.chars.sort == @word.chars.sort}
end
end | true |
2c5936e27cc34601a69fa2a85b6b44aa70156a66 | Ruby | jclosure/seeker | /lib/seeker.rb | UTF-8 | 2,142 | 2.71875 | 3 | [] | no_license | require 'whois'
require 'active_support'
require 'active_record'
def smart_require name
begin
require name
rescue LoadError
puts "unable to load #{name} from gem cache. falling back to local directory."
path = File.expand_path("#{name}.rb", File.dirname(__FILE__))
require path
end
end
smart_re... | true |
bcc61f50df50e39c228536f023e3122b22fc7b62 | Ruby | Coolagin/patterns_doc | /creational/abstract_factory/abstract_factory.rb | UTF-8 | 1,024 | 3.453125 | 3 | [] | no_license | # Создание фабрики для реализации 1
class RealisationFactory1
def create_button
Realisation_1.new
end
end
# Создание фабрики для реализации 2
class RealisationFactory2
def create_button
Realisation_2.new
end
end
# Базовый клас
class BaseClass
attr_accessor :caption
end
# Реализация класса
class Rea... | true |
b261fb6f9477928b9cb2b8c46a648ad3d015e215 | Ruby | marcusg/foreign_key_validation | /lib/foreign_key_validation/validator.rb | UTF-8 | 1,344 | 2.640625 | 3 | [
"MIT"
] | permissive | module ForeignKeyValidation
class Validator
attr_accessor :collector, :object
def initialize(collector, object)
self.collector = collector
self.object = object
end
def validate
to_enum(:invalid_reflection_names).map {|n| attach_error(n) }.any?
end
private
def i... | true |
db6fcc238d461131c9b8b7e446fc6159ba8bd89a | Ruby | melborne/itunes_track | /lib/itunes_track.rb | UTF-8 | 1,639 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'appscript'
require 'csv'
require 'ostruct'
require 'itunes_track/version'
include Appscript
class ItunesTrack
ATTRS = %i(name time artist album genre rating played_count year composer track_count track_number disc_count disc_number lyrics)
require 'itunes_track/cli'
class Track < OpenStruct
end
... | true |
8e5ac599508d3ad8a86a91219c5612330caa5fba | Ruby | metalefty/rubygem-fradium | /lib/fradium.rb | UTF-8 | 4,232 | 2.65625 | 3 | [
"MIT"
] | permissive | require "fradium/version"
require 'securerandom'
require 'sequel'
require 'time'
class Fradium
class UserAlreadyExistsError < StandardError; end
class UserNotFoundError < StandardError; end
class UsernameEmptyError < StandardError; end
class CorruptedUserDatabaseError < StandardError; end
def initialize(par... | true |
89fa8c3535e7d7e92704327d87c037bee4bffe94 | Ruby | littlemove/barometer | /lib/barometer/data/sun.rb | UTF-8 | 969 | 3.234375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Barometer
class Data::Sun
attr_reader :rise, :set
def initialize(rise=nil, set=nil)
raise ArgumentError unless (rise.is_a?(Data::LocalTime) || rise.nil?)
raise ArgumentError unless (set.is_a?(Data::LocalTime) || set.nil?)
@rise = rise
@set = set
end
def rise=(time)
... | true |
59c5d9259d66453699e594701440fdebff373165 | Ruby | lonewolf28/Coding | /Ruby/ctrl_flow.rb | UTF-8 | 719 | 3.5 | 4 | [] | no_license | #!/home/raj/.rbenv/shims/ruby
#puts "enter the first word you can think of: "
#words = %w(apple orange banana)
#response = words.collect do |w|
#print w + ">"
#response = gets.chomp
#if response.size == 0 then
#redo
#end
#response
#end
#puts "#{response}"
def factorial(n)
begin
raise ArgumentError.excep... | true |
930074be73daa4024bb81763178356243a15a73a | Ruby | codeodor/with | /lib/with.rb | UTF-8 | 2,896 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'with_sexp_processor'
require 'parse_tree'
class With
VERSION = "0.0.2"
def self.object(the_object, &block)
@the_object = the_object
@original_context = block.binding
anonymous_class = Class.new
anonymous_class.instance_eval { define_method("the_block", block) }
anonymous_class_as... | true |
c9ff39d81a51c48544ee4c86b2f0e8454ff7b624 | Ruby | rodrigomanhaes/dweller | /lib/dweller/state.rb | UTF-8 | 552 | 2.96875 | 3 | [
"MIT"
] | permissive | module Dweller
module State
attr_reader :name, :acronym, :region
class DwellerCity; include Dweller::City; end
def cities
@state_hash[:subregions].map do |city_hash|
city = DwellerCity.new
city.send "city_hash=", city_hash
city
end
end
def city(name)
ci... | true |
c58067d4d8c905dccfbb72d39a5d3323cab5fe8c | Ruby | Sheikh-Inzamam/AppAcademy-1 | /poker/lib/game.rb | UTF-8 | 879 | 3.6875 | 4 | [] | no_license | require 'deck'
require 'hand'
require 'player'
class Game
#game is the dealer
#should handle UI, progression of the game, blinds (small and big)
#initializes with game deck
#asks how many players there are
#builds pot from players
#takes ante from each player
#until game_over--One player gets all th... | true |
14ee9d92819da2a29db9bd6fcdeae1de097bfcd1 | Ruby | Lycoris/Project-Euler | /121-130/124.rb | UTF-8 | 436 | 3.421875 | 3 | [] | no_license | # http://projecteuler.net/problem=124
#
#
require 'prime'
def e(n, limit)
k = Hash.new
limit.times {|i|
k[rad(i + 1)] = [] if k[rad(i + 1)] == nil
k[rad(i + 1)] << i + 1
}
sum = 0
i = 0
until sum > n or sum == n
i += 1
sum += k[i].size if k[i] != nil
end
return k[i][-((sum - n) + 1)]
end
def rad... | true |
56fd7ac3adfc1319e46f032b4e7299004b6f2b0d | Ruby | hasumin71/rensyu | /drill_63.rb | UTF-8 | 297 | 4.3125 | 4 | [] | no_license | #1,2,3が全て配列内に入っていれば「True」それ以外は「False」と出力されるメソッドを作りましょう。
def array123(nums)
if nums.include?(1) && nums.include?(2) && nums.include?(3)
puts "True"
else
puts "False"
end
end
array123([1,2,3,4,5,6]) | true |
746a123d87a8c0e6b915db4b800e9e3699a4dcff | Ruby | FSlyne/Ruby | /threads/thread_class.rb | UTF-8 | 337 | 3.765625 | 4 | [] | no_license | class MyClass
def run
while 1<2 do
print "Hello"
sleep(2)
end
end
end
threads = []
# start creating active objects by creating an object and assigning
# a thread to each
threads << Thread.new { MyClass.new.run }
# now we're done just wait for all objects to finish ....
threads.eac... | true |
c439ddd2bde41c4978363e03ffac296ec6067136 | Ruby | luisbilecki/desafio-blumpa | /spec/support/ricky_and_morty_api/ricky_and_morty_mock.rb | UTF-8 | 797 | 2.609375 | 3 | [] | no_license | module RickyAndMortyMock
BASE_URL = 'https://rickandmortyapi.com'
def mock_get_character(id:, success: true)
content = read_json('./spec/support/ricky_and_morty_api/character_response.json')
stub = stub_request(:get, "#{BASE_URL}/api/character/#{id}")
if success
stub.to_return(status: 200, b... | true |
1555f35bb4936a013a03ec20e62c51b0780adbf5 | Ruby | CompanyCam/fancy-count | /lib/fancy_count/adapter.rb | UTF-8 | 526 | 2.671875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module FancyCount
class Adapter
def initialize(name, config)
@name = name
@config = config
end
def increment
counter.increment
end
def decrement
counter.decrement
end
def change(value)
counter.value = value
end
def re... | true |
c950ebbbc56f0c665eb7ff20236d7a55db6d9506 | Ruby | honzasp/ropucha | /spec/ropucha/parser/subroutines_spec.rb | UTF-8 | 2,124 | 2.703125 | 3 | [] | no_license | require 'spec_helper'
describe Ropucha::Parser do
include_context "parser"
describe "subroutine definitions and calls" do
it "parses a no-parameter procedure definition" do
@program = <<-END
procedure do()
x = y
end
END
sexp.should == [:ropucha, [
[:procedure_de... | true |
d43aa0dbcd1a5cb9eedf0314f709e343af0b3261 | Ruby | asciiman/bowling1978 | /test/models/throw_test.rb | UTF-8 | 425 | 2.671875 | 3 | [] | no_license | require 'test_helper'
class ThrowTest < ActiveSupport::TestCase
test "newly initialized" do
current_throw = Throw.new
assert_equal(0, current_throw.score)
end
test "some down" do
current_throw = Throw.new(pins_down: "110101101")
assert_equal(6, current_throw.score)
end
test "all down" do
... | true |
404b5a705b97ba2562ecc18b63998913b1d0203c | Ruby | cgoodmac/ruby | /labs/dinner_time/dinner_time.rb | UTF-8 | 1,087 | 3.75 | 4 | [] | no_license | require 'pry'
load 'food.rb'
load 'protein.rb'
load 'carb.rb'
dinner = []
puts "Create a (p)rotein, (c)arb, or (q)uit?"
prompt = gets.chomp
while prompt != 'q'
case prompt
when 'p'
puts "What kind of protein?"
animal_type = gets.chomp
when 'c'
puts "What kind of carb?"
grain_type = gets.chomp
end
pu... | true |
5fa9da8323e6210f10f950fb37caf0c9677f2252 | Ruby | WillowGardener/plant-directory-new | /lib/plant.rb | UTF-8 | 1,266 | 2.984375 | 3 | [] | no_license | require 'pg'
class Plant
attr_reader(:attributes, :name, :id)
def initialize(attributes)
@attributes = attributes
@name = attributes[:name]
@id = attributes[:id]
end
def save
results = DB.exec("INSERT INTO plants (plant_name) VALUES ('#{@name}') RETURNING id;")
@id = results.first['id'].t... | true |
679355de9edf7566f4a9950634e60312e3aec88a | Ruby | ScottGarman/vmfloaty | /lib/vmfloaty/utils.rb | UTF-8 | 3,322 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive |
require 'vmfloaty/pooler'
class Utils
# TODO: Takes the json response body from an HTTP GET
# request and "pretty prints" it
def self.format_hosts(hostname_hash)
host_hash = {}
hostname_hash.delete("ok")
domain = hostname_hash["domain"]
hostname_hash.each do |type, hosts|
if type != "doma... | true |
83d43cbc980b2f80584606e1463234ea0c777b13 | Ruby | grahamedgecombe/lancat | /lib/lancat/receiver.rb | UTF-8 | 1,447 | 2.78125 | 3 | [
"ISC"
] | permissive | require 'socket'
require 'ipaddr'
module Lancat
class Receiver
def initialize(verbose, timeout, output)
@verbose = verbose
@timeout = timeout
@output = output
end
def start
STDERR.puts 'Waiting for broadcasts...' if @verbose
addr = nil
port = nil
# wait for mu... | true |
787662d04720a55e79a8f6429f2bc3ad2323da38 | Ruby | swanandp/gcj | /2013/round_1b/a.rb | UTF-8 | 1,137 | 3.0625 | 3 | [] | no_license | #!/usr/bin/env ruby
# a
# https://code.google.com/codejam/contest/2434486/dashboard
$:.unshift File.dirname(__FILE__)
require 'shortest_path'
def solvable?(arr, start)
solvable = true
sum = start
(arr + [0]).each do |a|
solvable = sum > a
break unless solvable
sum += a
end
solvable
end
outfile... | true |
d58799c37807bd2a2e002c08a3d40536ec0f21e2 | Ruby | eosin-kramos/Ruby-Exercises- | /hello.rb | UTF-8 | 182 | 2.796875 | 3 | [
"MIT"
] | permissive | # hello.rb, written by Kevin Ramos
# This program follows the instructions from the
# UC Berkeley Extension Coding Boot Camp
puts "Today, I wrote code"
puts "And I'm a coding machine..." | true |
3a6d785f073722cfb129e3388ec39cdd6753bef8 | Ruby | parkesma/nutrition_software | /app/models/meal.rb | UTF-8 | 892 | 3.046875 | 3 | [] | no_license | class Meal < ActiveRecord::Base
before_save :capitalize
before_create :capitalize
belongs_to :user
has_many :food_assignments, dependent: :destroy
validates :name, presence: true
validates :time, presence: true
def carbs
total = 0
self.food_assignments.each do |fa|
total += fa.food.carbs_per_exchange *... | true |
4627dd216f99fa3afe670eca0c62595c69dcf5b1 | Ruby | ZeroPivot/dragonruby-zif | /app/lib/zif/sprites/serializable.rb | UTF-8 | 1,076 | 2.96875 | 3 | [
"MIT"
] | permissive | # Throw this file into your app folder, like app/lib/serializable.rb
#
# In your main.rb or wherever you require files:
# require 'app/lib/serializable.rb'
#
# In each class you want to automatically serialize:
# class Foo
# include Serializable
# ...
# end
module Zif
# A mixin for automatically definin... | true |
84eb9829cc2d8a9740f0326cee656c3ca2f8d87e | Ruby | ben-garcia/the_odin_projects | /ruby/ruby_on_the_web/a_simple_server.rb | UTF-8 | 990 | 3.1875 | 3 | [] | no_license | require 'socket'
require 'json' # Get sockets from stdlib
server = TCPServer.open(2000) # Socket to listen on port 2000
loop do
client = server.accept
client.puts(Time.now.ctime)
request = client.gets.split(" ")
if request[0] == "GET"
if File.exists? request[1][1..-1]
string = Fil... | true |
f97f78a800d9b3cb910e83776293d862ce153145 | Ruby | goodfairy/gblearn_ruby | /compcls.rb | UTF-8 | 637 | 2.734375 | 3 | [] | no_license | class Computer < Host
##
# initialize Computer by user data, or default data
#
# default data sets Computer's ip address 127.0.0.1 without host name and default mode pc (personal computer)
# data option - Computer ip address, Computer name,Computer mode
#
def initialize(ipaddress = '127.0.0.1', dnsname = ... | true |
647d51056371921397a3063b69c9f88fc9ba8017 | Ruby | JenStrong/chitter-challenge | /spec/user_spec.rb | UTF-8 | 869 | 2.8125 | 3 | [] | no_license | require 'user'
require 'pry'
describe User do
describe '.create' do
it 'creates a new user' do
user = User.create(username: 'user1', name: 'name1', email: 'email@gmail.com', password: 'password123')
expect(user.id).not_to be_nil
end
end
describe '.all' do
it 'returns all users, wrapped ... | true |
88d7ae7e0870340b449a0c36fca3c4b1c4c73602 | Ruby | bhatarchanas/mcsmrt_mod | /final_parsing.rb | UTF-8 | 2,457 | 2.765625 | 3 | [] | no_license | require 'trollop'
opts = Trollop::options do
opt :blastfile, "File with blast information.", :type => :string, :short => "-b"
opt :otuutaxfile, "File with OTU table and utax information.", :type => :string, :short => "-u"
opt :outfile, "Output file with OTU names, OTU counts, lineage and blast results.", :type =... | true |
2884e7ce55383522b62e0f79bdb3f6d93d37a14b | Ruby | stephencelis/scantron | /lib/scantron/scanners/date_scanner.rb | UTF-8 | 480 | 2.75 | 3 | [
"MIT"
] | permissive | require 'scantron'
require 'date'
class DateScanner < Scantron::Scanner
days = Date::DAYNAMES * '|'
days << "|(?:#{Date::ABBR_DAYNAMES * '|'})\\b\\.?"
months = Date::MONTHNAMES.compact * '|'
months << "|(?:#{Date::ABBR_MONTHNAMES.compact * '|'})\\b\\.?"
human = /\b(?:(#{days}),? )?\b(#{months})( \d{1... | true |
c2503c9e0cd1b30d2f86b4585b908f7cc7eb3e55 | Ruby | pact-foundation/pact_broker | /lib/pact_broker/pacts/selector.rb | UTF-8 | 11,417 | 2.578125 | 3 | [
"MIT"
] | permissive | require "pact_broker/hash_refinements"
module PactBroker
module Pacts
# rubocop: disable Metrics/ClassLength
class Selector < Hash
using PactBroker::HashRefinements
PROPERTY_NAMES = [:latest, :tag, :branch, :consumer, :consumer_version, :environment_name, :fallback_tag, :fallback_branch, :main_b... | true |
7c45e023bfdccbb0eb8bed40f2ec778878a46aea | Ruby | leviwilson/mohawk | /lib/mohawk/accessors.rb | UTF-8 | 13,783 | 2.78125 | 3 | [
"MIT"
] | permissive | module Mohawk
module Accessors
#
# Defines the locator indicating the top-level window that will be used
# to find controls in the page
#
# @example
# window(:title => /Title of Some Window/)
#
# @param [Hash] locator for the top-level window that hosts the page
#
... | true |
43c009e586e0654fc0683274dd0ef894c7b4419c | Ruby | webguyian/nanoblog | /lib/helpers/blogging.rb | UTF-8 | 176 | 2.78125 | 3 | [] | no_license | require 'time'
def grouped_articles
sorted_articles.group_by do |a|
[ Time.parse(a[:created_at]).strftime("%B"), Time.parse(a[:created_at]).year ]
end.sort.reverse
end | true |
82add4a33e90100fdf42917e0e3110c6bcb72704 | Ruby | joshmrallen/ruby-enumerables-reverse-each-word-lab-nyc-web-030920 | /reverse_each_word.rb | UTF-8 | 210 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(string)
string_array = string.split
reversed_words = string_array.collect {|word| word.reverse}
reversed_string = reversed_words.join(" ")
return reversed_string
end | true |
e340003a78e00cc9de0fdf9ef65eb564bed0e8cc | Ruby | essa/portwarp | /lib/portwarp/utils.rb | UTF-8 | 1,989 | 2.546875 | 3 | [
"MIT"
] | permissive |
require 'net/https'
module PortWarp
module Utils
def start_http(url_str, verb, &block)
url = URI.parse(url_str)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if $options['ssl-verify-none']
5.times ... | true |
4411f81bf2b108e96fe487b7416af72c31d9ddc6 | Ruby | nassimbka/rails-longest-word-game | /app/controllers/games_controller.rb | UTF-8 | 1,947 | 3.1875 | 3 | [] | no_license | # Fuck Rubocop
require 'open-uri'
require 'json'
class GamesController < ApplicationController
def new
@letters = []
10.times do
@letters << ('A'..'Z').to_a.sample
end
end
def score
@attempt = params[:word]
@grid = params[:letters]
@game_result = score_and_message(@attempt, @grid)
... | true |
fa286bc83b0ae94ded8519f1b7c1617b020dd3be | Ruby | medericgb/18-08-2021 | /book.rb | UTF-8 | 566 | 3.671875 | 4 | [] | no_license | class Book
attr_accessor :title, :author
def initialize(title, author)
@title = title
@author = author
end
def title
p @title
end
def author
p @author
end
def get_title
p "Title: #{@title}"
end
def get_author
p "Author: #{@author}"
end
end
pp = Book.new("Pride and Pre... | true |
c73eed3925cbed291fd4840dd1ca9be3db0f5ed1 | Ruby | mfeniseycopes/the-dba | /lib/associatable.rb | UTF-8 | 2,740 | 3 | 3 | [] | no_license | require_relative 'searchable'
require 'active_support/inflector'
# base AssocOptions class
class AssocOptions
attr_accessor(
:foreign_key,
:class_name,
:primary_key
)
# create new AssocOptions instance with name and options
def initialize(name, custom_options = {})
# custom_options need not d... | true |
384f8446ae39d2ad65e9e456e7616e25788db0ce | Ruby | davidtadams/advent-of-code | /2020/day_9/part2.rb | UTF-8 | 630 | 3.3125 | 3 | [] | no_license | # frozen_string_literal: true
input = File.read('./input.txt').split("\n").map(&:to_i)
invalid_number = 85_848_519
current_index = 0
contiguous_range = []
while current_index < input.size
sum = 0
search_range = input[current_index..]
end_index = nil
search_range.each_with_index do |number, index|
sum +=... | true |
85975c600e168ebf438d5c61c52776b05129fa9b | Ruby | CorainChicago/traveling_salesman | /test/traveling_salesman_test.rb | UTF-8 | 1,025 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require 'traveling_salesman'
class TravelingSalesmanTest < Minitest::Test
class FirstCheck < Minitest::Test
def setup
@cities = [[1, 2], [3, 4], [8, 7], [10, 12], [2, 4]]
@tsp = TravelingSalesman.new(@cities)
@expected = [[3, 4], [8, 7], [10, 12], [2, 4], [1, 2]]
... | true |
a1260935122f525e35743138904145781a1cd752 | Ruby | onkis/stativus-rb | /tests/add_state.rb | UTF-8 | 1,291 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'test/unit'
require Dir.pwd()+'/tests/test_states'
class AddState < Test::Unit::TestCase
def setup
@statechart = Stativus::Statechart.new
@statechart.add_state(A)
@statechart.add_state(B)
@statechart.add_state(C)
@statechart.start("B")
@statechart.goto_state("B", Stativus::DEFAU... | true |
162e9af79000146238fd13693e40b161f25d3894 | Ruby | hrdwdmrbl/e-shipper-ruby | /test/unit/quote_test.rb | UTF-8 | 1,498 | 2.625 | 3 | [
"MIT"
] | permissive | require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
class QuoteTest < MiniTest::Test
def test_valid_quote
quote = EShipper::Quote.new({:service_id => '123', :service_name => 'fake service'})
assert quote.validate!
assert_equal '123', quote.service_id
assert_equal 'fake service', q... | true |
8bf6514d2f80e20afa3bfe9f896d5dd0b7f23ece | Ruby | patmccler/ruby-collaborating-objects-lab-pca-001 | /lib/song.rb | UTF-8 | 519 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
attr_accessor :name, :artist
@@all = []
def initialize name
@name = name
@@all << self
end
def artist_name
@artist ? @artist.name : nil
end
def self.all
@@all
end
def artist_name=(name)
@artist = Artist.find_or_create_by_name name
end
def self.new_by_filename(fi... | true |
4373570b80f7b21ac9ba4125ae454dd0096a035c | Ruby | codefoundry/svn | /lib/svn/apr_utils.rb | UTF-8 | 8,233 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | require 'rubygems'
require 'ffi'
module Svn #:nodoc:
class AprHash < FFI::AutoPointer
# when used as key length, indicates that string length should be used
HASH_KEY_STRING = -1
include Enumerable
attr_accessor :keys_null_terminated
alias_method :keys_null_terminated?, :keys_null_terminated
... | true |
3c69db68fe5f44c5dc897f5b224b20b0886d74ee | Ruby | markj9/econ_view | /lib/econ_view/rdcg_indicator.rb | UTF-8 | 512 | 2.65625 | 3 | [] | no_license | module EconView
class RDCGIndicator < EconomicIndicator
DOMESTIC_CREDIT_GROWTH = :"sodd.."
def compute_value(country)
domestic_credit_growth = courier.measurement_for(DOMESTIC_CREDIT_GROWTH, country)
cpi = courier.measurement_for(CPI, country)
if !valid_measurement?(domestic_credit_growth) || !valid_me... | true |
b3414565d57a82ba588ab6a194e7e05d7de81438 | Ruby | spy1031/simple-twitter | /app/models/tweet.rb | UTF-8 | 351 | 2.515625 | 3 | [] | no_license | class Tweet < ApplicationRecord
validates_length_of :description, maximum: 140
belongs_to :user ,counter_cache: true
has_many :replies ,dependent: :destroy
has_many :likes ,dependent: :destroy
has_many :liked_users ,through: :likes,dependent: :destroy ,source: :user
def is_like?(user)
self.liked_... | true |
6ba56dedd6b0940678e0fad093f103cdc026bafa | Ruby | DrXyclo/ttt-5-move-rb-online-web-sp-000 | /bin/move | UTF-8 | 357 | 3.265625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #!/usr/bin/env ruby
require_relative '../lib/move.rb'
# Code your CLI Here
puts "Welcome to Tic Tac Toe!"
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
display_board(board)
puts "Where yould you like to go?"
input = gets.strip
input_to_index(input)
index = input.to_i-1
move(board, index, character = "X"... | true |
641e7bbb6aff5b8c273fe60cd404fb54c9b85cc6 | Ruby | 9toon/hacker_rank | /spec/sherlock_and_anagrams_spec.rb | UTF-8 | 378 | 2.625 | 3 | [] | no_license | require_relative "../problem/sherlock_and_anagrams"
describe "Problem sherlock_and_anagrams" do
it { expect(sherlockAndAnagrams('abba')).to eq(4) }
it { expect(sherlockAndAnagrams('abcd')).to eq(0) }
it { expect(sherlockAndAnagrams('ifailuhkqq')).to eq(3) }
it { expect(sherlockAndAnagrams('kkkk')).to eq(10) }
... | true |
14d47fae08664ac2966896934db6e30fe235bd40 | Ruby | zachalewel/array_practice | /index_of_arrays.rb | UTF-8 | 291 | 3.5 | 4 | [] | no_license | #!/usr/bin/env ruby
def index_of_first_uniq(array)
counts = Hash.new(0)
puts counts
array.each{|i| counts[i]+= 1}
array.each_with_index do |number,index|
return index if counts[number] == 1
end
return nil
end
array = [2, 4, 3, 2, 5, 9, 4, 1]
puts index_of_first_uniq(array)
| true |
859e702e1c325cd40686f034a5e539b8530e901e | Ruby | prettymuchbryce/princessfrenzy | /websocketserver/warp.rb | UTF-8 | 252 | 2.953125 | 3 | [] | no_license | class Warp
WARP_UP = "WARP_UP"
WARP_LEFT = "WARP_LEFT"
WARP_RIGHT = "WARP_RIGHT"
WARP_DOWN = "WARP_DOWN"
WARP = "WARP"
attr_accessor :x, :y, :level, :type
def initialize(x,y,level,type)
@x = x;
@y = y
@level = level
@type = type
end
end | true |
1259b626a70d308adaabb820188b85e1c6c409cc | Ruby | sebaquevedo/desafiolatam | /guia_array_hash/ejercicio7.rb | UTF-8 | 220 | 3.203125 | 3 | [
"MIT"
] | permissive | require 'pp'
a = [1,2,3,9,12,31, "domingo"]
b = ["lunes","martes","miércoles","jueves","viernes","sábado","domingo"]
#1 concatenar
p a.concat b
# #2 union
p a | b
# #3 interseccion
p a & b
#4
p a.zip b
| true |
705c0fce8c014657e29a7af4a01933b0f15ff585 | Ruby | rowlandjl/LaunchAcademy-Price_of_Admission | /price_of_admission.rb | UTF-8 | 281 | 2.953125 | 3 | [] | no_license | adultPrice = 12.80
childPrice = 4.00
numAdults = 4.00
numChild = 2.00
totalAdult = adultPrice * numAdults
totalChild = childPrice * numChild
finalTotal = totalAdult + totalChild
perPerson = finalTotal / numAdults
puts "Total: $#{finalTotal}"
puts "Total Per Adult: $#{perPerson}"
| true |
af95295e31a382889e654b74293e9c68701e2eb0 | Ruby | stephr3/library | /spec/book_spec.rb | UTF-8 | 4,143 | 2.890625 | 3 | [
"MIT"
] | permissive | require('spec_helper')
describe(Book) do
describe('#title') do
it "returns the title of the book" do
test_book = Book.new({:id => nil, :title => '19Q4',:author => 'Haruki Murakami', :year_published => '2009'})
expect(test_book.title()).to(eq('19Q4'))
end
end
describe('#id') do
it "retur... | true |
e99e5d876f48b25a7af4a00a980b44dbdb552561 | Ruby | mcgraths7/TeamValor | /app/services/trader.rb | UTF-8 | 346 | 2.609375 | 3 | [] | no_license | class Trader
def initialize(trade_request)
@trade_request = trade_request
end
def execute
user_1 = @trade_request.give.user
user_2 = @trade_request.take.user
@trade_request.give.user = user_2
@trade_request.take.user = user_1
@trade_request.give.save
@trade_reques... | true |
e94c8485653afc42e1f38f5002420602304dd281 | Ruby | RobertoBarros/batch46_cookbook | /cookbook.rb | UTF-8 | 751 | 3.453125 | 3 | [] | no_license | require 'csv'
class Cookbook
def initialize(csv_file)
@recipes =[]
@csv = csv_file
load
end
def all
@recipes
end
def list(index)
@recipes[index]
end
def add(recipe)
@recipes << recipe
save
end
def destroy(index)
@recipes.delete_at(index)
save
end
def save
... | true |
fa1dd434ac84a0ebbc4952f0f866eda832723d40 | Ruby | ngeballe/ls-exercises-challenges | /medium2/other files/other practice/logs.rb | UTF-8 | 898 | 4.0625 | 4 | [] | no_license | def time_to_run
start_time = Time.now
yield
end_time = Time.now
puts "That took #{end_time - start_time} seconds"
end
def average_time_to_run(num_times = 5)
time_recordings = []
num_times.times do
start_time = Time.now
yield
time_to_run = Time.now - start_time
time_recordings << time_to_run... | true |
a4a7a661646b95cb1b4af3bffd5b2d50c16678ba | Ruby | rcm32000/denver_puplic_library | /test/library_test.rb | UTF-8 | 2,944 | 3.078125 | 3 | [] | no_license | require './test/test_helper'
require './lib/library'
require './lib/Author'
class LibraryTest < Minitest::Test
def setup
@dpl = Library.new
@charlotte_bronte = Author.new({first_name: 'Charlotte',
last_name: 'Bronte'})
@charlotte_bronte.add_book('Jane Eyre',
... | true |
9eeb382be73ba35c29b9914e4c8b1f31b8508b51 | Ruby | djblairjones/Cash_Register | /lib/change_functions.rb | UTF-8 | 1,594 | 3.640625 | 4 | [] | no_license | class ChangeMaker
def totalchange(price, payment)
puts ChangeMaker.class
puts payment.class
change = (payment - price)
return "No Change Required!" if change == 0.0
return "Customer payment is insufficient!" if change < 0
return change
end
def changedenom(tot... | true |
311b32a2c43429fd596b6131d5420c8123f0204f | Ruby | hgaard/7-languages | /ruby/hash-tree.rb | UTF-8 | 660 | 4 | 4 | [] | no_license | #Change of original tree to accept a hash for initialization
class Tree
attr_accessor :children, :node_name
def initialize(tree)
tree.each_pair{|name,children| @node_name = name, @children = children}
end
def visit_all(&block)
visit &block
children.each { |c| c.visit_all &block}
end
def visi... | true |
f972a476c1b59d09bc74dbba71342c79da455bfb | Ruby | lesliehawk/RB109 | /Small_Problems/Easy_4/05.rb | UTF-8 | 551 | 4.46875 | 4 | [] | no_license | # Multiples of 3 and 5
# Write a method that searches for all multiples of 3 or 5
# that lie between 1 and some other number,
# and then computes the sum of those multiples.
# For instance, if the supplied number is 20,
# the result should be 98 (3 + 5 + 6 + 9 + 10 + 12 + 15 + 18 + 20).
# You may assume that the numbe... | true |
6ba86bb6a5265dea7513c2f04632fe975d842065 | Ruby | Hitaishini/ananth-bajaj-backend | /app/models/booking_time_control.rb | UTF-8 | 2,115 | 2.65625 | 3 | [] | no_license | class BookingTimeControl < ApplicationRecord
def self.book_time_control_method(params)
#for Category and Day
date = params[:date].to_datetime
week_day = params[:date].to_datetime.strftime("%A").downcase.capitalize
#for time
#days = Time.days_in_month(m, y)
time = DateTime.parse(params[:time]).s... | true |
8e89145c7f9446b8d2f66da026a918f06e567701 | Ruby | DeUsman/object-relations-assessment-web-031317 | /app/models/customer.rb | UTF-8 | 926 | 3.15625 | 3 | [] | no_license | class Customer < Review
attr_accessor :first_name, :last_name, :reviews
@@ALL = []
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
@reviews = []
@@ALL.push(self)
end
def full_name
"#{first_name} #{last_name}"
end
def self.all
return @@ALL
... | true |
db8254009089c6fabb69d08c472db643e49503e0 | Ruby | mmanousos/ruby-small-problems | /ruby_basics/user_input/ten.rb | UTF-8 | 4,023 | 4.75 | 5 | [] | no_license | # 10. Opposites Attract
=begin
Write a program that requests two integers from the user, adds them together, and then displays the result. Furthermore, insist that one of the integers be positive, and one negative; however, the order in which the two integers are entered does not matter.
Do not check for positive/nega... | true |
ca0a28bb21723c64a091369e53bf6f6a1509a8da | Ruby | TylerMcKenzie/phase-0 | /errors.rb | UTF-8 | 6,929 | 4.3125 | 4 | [
"MIT"
] | permissive | # Analyze the Errors
# I worked on this challenge [by myself, with: ].
# I spent [#] hours on this challenge.
# cartmans_phrase = "Screw you guys " + "I'm going home."
# This error was analyzed in the README file.
# def cartman_hates(thing)
# while true
# puts "What's there to hate about #{thi... | true |
4d3d88d5c12a4d506fe739ad62d558633395ef48 | Ruby | NickEdwin/b2-mid-mod | /spec/models/park_spec.rb | UTF-8 | 674 | 2.5625 | 3 | [] | no_license | RSpec.describe Park do
describe 'validations' do
it { should validate_presence_of :name }
it { should validate_presence_of :admission_price }
end
describe 'relationships' do
it { should have_many :rides }
end
describe 'helper method test' do
it 'uses #avg_thrill_rating to find average thrill... | true |
f34cdf63463143e52a53588c6b9110f79cfd1325 | Ruby | dcousette/learn_to_program | /old_roman_numerals.rb | UTF-8 | 455 | 4.09375 | 4 | [] | no_license | #old_roman_numerals.rb
def numeralizer number
i = 1
v = 5
x = 10
l = 50
c = 100
d = 500
m = 1000
if number > 0 && number <= 3000
puts "This is a start"
number % divisor == 0
if
else
end
# take number in
# do something
# get to numeral_value
# numeral_nu... | true |
dabbfafc6cbe74b020167ca09f03054387177bd5 | Ruby | alexmcbride/futureprospects | /app/helpers/decisions_helper.rb | UTF-8 | 1,709 | 2.53125 | 3 | [] | no_license | # * Name: Alex McBride
# * Date: 24/05/2017
# * Project: Future Prospects
# Module for decision controller helpers. These are functions that can be called in views.
module DecisionsHelper
# Displays a decision stage sidebar item.
#
# @param text [String] the text of the stage.
# @param selected [Boolean] whethe... | true |
3c727e08c0eada08dacb1a4472566946e3a155d9 | Ruby | ddcunningham/RnGG | /lib/RnGG/game_turn.rb | UTF-8 | 490 | 3.03125 | 3 | [] | no_license | require_relative 'player'
require_relative 'die'
require_relative 'treasure'
module RnGG
module GameTurn
def self.take_turn(player)
die = Die.new
case die.roll
when 1..2
player.blam
when 3..4
puts "#{player.name} was skipped."
when 5..6
player.heal
el... | true |
a9435c6484b477f56a4723900f4d30413e654e42 | Ruby | ByrneGR/projects | /W3D2/memory_puzzle/game.rb | UTF-8 | 992 | 3.65625 | 4 | [] | no_license | require_relative "board.rb"
class Game
def initialize(player, size=4)
@board = Board.new(size)
@board.populate
@player = player
@previous_guess = nil
end
def make_guess(pos)
if @previous_guess.nil?
@previous_guess = pos
@board.reveal(pos)
... | true |
be8bf8429e0f3d89099d10a0d000281252945965 | Ruby | arunshariharan/trello-cards-search | /start_search.rb | UTF-8 | 1,702 | 2.90625 | 3 | [] | no_license | require 'pp'
require 'trello'
require 'stopwords'
require 'net/http'
require 'amatch'
require_relative 'Configuration/trello_configuration'
require_relative 'Configuration/user_configuration'
require_relative 'Input/input'
require_relative 'Populator/populator'
require_relative 'Curator/curator'
require_relative 'Mat... | true |
73d7cf8a73ff18f5329470303d8ea4c6726f0473 | Ruby | DJCarlosValdez/curso-web | /ruby/challenges-custom/c1.rb | UTF-8 | 1,672 | 4.0625 | 4 | [] | no_license | # def find_duplicates(array)
# array2 = []
# array3 = []
# array.each do |x|
# if !array2.include?(x)
# array2 << x
# elsif array2.include?(x)
# array3 << x
# end
# end
# p array3
# end
# numbers = [1,2,2,3,4,5]
# find_duplicates(numbers)
#----------... | true |
5bc0b8ca88ba822b0c69d3300e8ee2bce20ca442 | Ruby | wooisland/LRHW | /ex4.rb | UTF-8 | 544 | 3.171875 | 3 | [] | no_license | cars = 100
spance_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_dirven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * spance_in_a_car
average_passenger_per_car = passengers /cars_driven
puts "There are #{cars} available."
puts "There are only #{drivers} drivers available."
puts "There w... | true |
df6fc5ff9fa8d323ad5d4d5d4de05bcd97b2a8dd | Ruby | carusocr/bcast | /streaming/twitter/harvest_tweet_by_id.rb | UTF-8 | 692 | 3.125 | 3 | [] | no_license | # given a single tweet ID, collect associated text
# prints Twitter error message if tweet isn't available
require 'twitter'
abort "Enter numeric Tweet ID." unless ARGV[0] =~ /^[0-9]+$/
tweet_id = ARGV[0]
client = Twitter::REST::Client.new do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consu... | true |
075520b3fee1e6e15254a2affcadfc264309b558 | Ruby | smoip/wamibrew | /app/services/hops_arrays.rb | UTF-8 | 480 | 3.3125 | 3 | [] | no_license | class HopsArrays
attr_accessor :hops
def initialize(hops)
@hops = hops
end
def hops_to_array
hop_ary = []
unless @hops[:aroma].nil?
@hops[:aroma].each do |aroma_hash|
hop_ary << aroma_hash.to_a
end
hop_ary = hop_ary.flatten(1)
end
hop_ary.unshift(@hops[:bittering... | true |
fcd0d994bbaf406c175b35a574c3d3fcc6f98528 | Ruby | chriskuck/aoc2020 | /day18/main.rb | UTF-8 | 452 | 3.15625 | 3 | [] | no_license | require 'pry'
require './bad_equation.rb'
require './mult_dom_equation.rb'
exit(1) unless !ARGV[0].nil? && File.exist?(ARGV[0])
eqs = File.read(ARGV[0]).split("\n")
ans = eqs.map do |eq|
puts "#{eq} = #{BadEquation.new(eq).eval}"
BadEquation.new(eq).eval
end
puts "Part 1: #{ans.inject(:+)}"
binding.pry
ans = eq... | true |
1895d845a5358de5710fbf6c94222d0191cf5f5f | Ruby | ethanpoole/Linguistic-Explorer | /app/models/search_results/comparisons.rb | UTF-8 | 1,588 | 2.609375 | 3 | [
"MIT"
] | permissive | module SearchResults
module Comparisons
attr_reader :search_comparison
def result_rows=(result_rows)
self.result_groups = result_rows.group_by { |row| row.parent_id }
self.result_groups.values.map! { |row| row.map! { |r| r.child_id }.compact! }
@search_comparison = true
end
def res... | true |
245969379f1b87faa4ef3bc43fe196d2a5b1cdbb | Ruby | factcondenser/leetcode_solutions | /014_longest_common_prefix.rb | UTF-8 | 642 | 3.375 | 3 | [] | no_license | # @param {String[]} strs
# @return {String}
def longest_common_prefix(strs)
return '' if strs.nil? || strs.length == 0
prefix = strs.first
i = 1
while i < strs.length do
while strs[i].index(prefix) != 0 do
prefix = prefix[0..-2]
end
i += 1
end
prefix
end
# @param {String[]} strs
# @retur... | true |
7397b1d0c410d295541512fefd6ee7ed848bfebd | Ruby | delosiliana/thinknetica | /lesson_9/main.rb | UTF-8 | 9,850 | 3.453125 | 3 | [] | no_license | require_relative './lib/accessors'
require_relative './lib/manufacturer'
require_relative './lib/validation'
require_relative './lib/instance_counter'
require_relative './lib/route'
require_relative './lib/station'
require_relative './lib/train'
require_relative './lib/passenger'
require_relative './lib/cargo'
require_... | true |
49d27b0bb9c5633a110366fb7954e463e58466c2 | Ruby | PhilipVigus/oystercard-weds | /lib/oystercard.rb | UTF-8 | 1,081 | 3.34375 | 3 | [] | no_license | class Oystercard
attr_reader :balance, :min_balance, :entry_station
STARTING_BALANCE = 0
CARD_LIMIT = 90
MINIMUM_BALANCE = 1
def initialize(balance = STARTING_BALANCE)
@balance = balance
@journeys_taken = []
@current_journey = nil
end
def top_up(num)
raise "you cannot top up #{num} as ... | true |
cff4ca59e2e01c3eaf43e5e4ecf6722439b55d00 | Ruby | amihays/aa-materials | /w1d2/sudoku/board.rb | UTF-8 | 1,214 | 3.578125 | 4 | [] | no_license | require_relative "tile.rb"
class Board
def initialize(grid)
@grid = grid
end
def self.from_file(file_path)
lines = File.readlines(file_path).map { |line| line.chomp }
values = lines.map { |line| line.split('') }
grid = values.map { |row| row.map { |value| Tile.new(value) } }
Board.new(grid)
... | true |
61895d1614f74c87ca1932619c9b7aea37476675 | Ruby | mviceral/IceSlotController | /BBB_Sampler/DutObj.rb | UTF-8 | 9,623 | 2.53125 | 3 | [
"MIT"
] | permissive | # require_relative 'AllDuts'
require_relative '../lib/SharedMemory'
require_relative '../lib/SharedLib'
# ----------------- Bench mark string length so it'll fit on GitHub display without having to scroll ----------------
SetupAtHome_DutObj = false # So we can do some work at home
class DutObj
FaultyTcu = "Faulty... | true |
7d15de8847b801b628b6680d9c848b23fed27c16 | Ruby | kromoser/my-each-v-000 | /my_each.rb | UTF-8 | 187 | 3.421875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def my_each(array) # put argument(s) here
i = 0
while i < array.length
yield array[i]
i += 1
end
array
end
collection = [1,2,3,4]
my_each(collection) do |i|
i
end | true |
252e4cdad722ddc3a486b9cdc777f5ccd25ec2a5 | Ruby | jordan-creyelman/ruby-morpion | /lib/app/board.rb | UTF-8 | 2,227 | 3.203125 | 3 | [] | no_license | require 'bundler'
Bundler.require
require_relative 'boardCase.rb'
class Board
attr_accessor :array
def initialize
boardcase = Boardcase.new
@array = boardcase.case
end
def placement_pions(position,symbole)
@array[position] =symbole
end
def win
if @array[0]=="x"&& @array[1]=="x"&... | true |
e7052ed70d20ab7a50d0895d6bc466a360340c2f | Ruby | mochnatiy/loc-invite | /loc-invite.rb | UTF-8 | 527 | 2.875 | 3 | [
"MIT"
] | permissive | require File.expand_path('../lib/hash.rb', __FILE__)
require File.expand_path('../app/point.rb', __FILE__)
require File.expand_path('../app/processes/customers/select_nearest.rb', __FILE__)
# Dublin office location
office_location = Point.new(53.339428, -6.257664)
# Required distance in kilometers
preferred_distance ... | true |
757a096188b92dd3bf07761bf7648d62f412762a | Ruby | mariomanzoni/Enterprise-Recipes-with-Ruby-and-Rails | /code/testing/rspec/rspecsample/vendor/plugins/rspec_on_rails/spec_resources/helpers/explicit_helper.rb | UTF-8 | 696 | 2.859375 | 3 | [
"MIT"
] | permissive | #---
# Excerpted from "Enterprise Recipes for Ruby and Rails",
# 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... | true |
b808ecd919c26ca7ad387d031e77061f57df275e | Ruby | TotallyBullshit/metatrader-multilang | /ruby/order.rb | UTF-8 | 1,097 | 2.703125 | 3 | [] | no_license | class Mql
class Order
Types = [:buy, :sell, :buylimit, :buystop, :selllimit, :sellstop]
BUY, SELL = *(0..1)
attr_reader :ticket
def initialize s, ticket
@s, @ticket = s, ticket
end
def lots
@s.send(108, @ticket).first
end
def profit
@s.se... | true |
8555025d92967b85e6a6dac7cb6efcf0ffd624f7 | Ruby | NahueFaluotico/Rubot | /company.rb | UTF-8 | 966 | 3.265625 | 3 | [] | no_license | require_relative 'Robots/flyer'
require_relative 'Robots/humanoid'
require_relative 'Robots/miner'
require_relative 'person'
puts "Construyendo robots...\n\n"
flyer_robot_1 = Flyer.new('Flyer Robot One')
humanoid_robot_1 = Humanoid.new ('Humanoid Robot One')
miner_robot_1 = Miner.new ('Miner Robot One')
flyer_robot_... | true |
52193327f8cca1498cb673c1cdcaf110467fe1cc | Ruby | compose-ui/megatron.rb | /app/helpers/megatron/docs_helper.rb | UTF-8 | 3,325 | 2.65625 | 3 | [
"MIT"
] | permissive | module Megatron
module DocsHelper
DEMO_DEFAULTS = {
type: :slim,
class: 'demo',
tag: :div
}
def demo(title=nil, options={}, &block)
if title.is_a? Hash
options = title
title = nil
end
options = DEMO_DEFAULTS.merge(options)
content_tag options[... | true |
8054f0f3baca07b5a9cad48add2cdc9cd9277f30 | Ruby | m1kshay/Alina | /Lessons/Lesson_9/train.rb | UTF-8 | 2,058 | 3.375 | 3 | [] | no_license | require_relative 'company_manufacturer'
require_relative 'instance_counter'
require_relative 'validation'
class Train
include CompanyManufacturer
include InstanceCounter
include Validation
attr_reader :number, :type, :speed, :route, :wagons
@@trains_number = {}
TRAIN_NUMBER = /^\w{3}-?\w{2}$/
def init... | true |
f72322bb5db558b5d3fe474ba794a191b881e24b | Ruby | soilman/soilt | /lib/tasks/import_trucks.rake | UTF-8 | 479 | 2.671875 | 3 | [] | no_license | require 'csv'
namespace :csv do
desc "Import CSV Data"
task :import_trucks => :environment do
csv_file_path = 'db/fixtures/trucks.csv'
CSV.foreach(csv_file_path) do |row|
truck_count = 1
Truck.create!({
:company_id => row[0],
:number => row[1],
:plate => row[2]... | true |
f707a071f8248353a87b26828cce967d344d7637 | Ruby | deguzman22/premierespeakers_exam | /xml_parser.rb | UTF-8 | 2,120 | 2.625 | 3 | [] | no_license | require 'xmlsimple'
# there have no b029 and b041 on XML file
class XmlParser
def call
parse_xml
end
private
def parse_xml
xml = File.read 'ACdelta20061pt2.xml'
data = XmlSimple.xml_in xml
data['product'].each do |product|
@text = <<-TEXT
isbn: #{product['productidentifier'][3]['b... | true |
9a82f886726ac063456a57d62747868e74e24dcf | Ruby | gf3/celluloid | /lib/celluloid/tasks.rb | UTF-8 | 1,165 | 2.84375 | 3 | [
"MIT"
] | permissive | module Celluloid
# Asked to do task-related things outside a task
class NotTaskError < StandardError; end
# Trying to resume a dead task
class DeadTaskError < StandardError; end
# Tasks are interruptable/resumable execution contexts used to run methods
class Task
class TerminatedError < StandardError;... | true |
e7a339de6c4fe735eb76e0ade7e61449bf685341 | Ruby | denza/workers | /test/pool_test.rb | UTF-8 | 1,149 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class PoolTest < Minitest::Test
def test_basic_usage
pool = Workers::Pool.new
successes = []
pool.size.times do
pool.perform { successes << true }
end
assert(pool.dispose(5))
assert(Array.new(pool.size, true), successes)
end
def test_exception_during_perform... | true |
cc25c1fca47f1766075d825bd3a8e00bcad70fcd | Ruby | Dfelix02/ruby-oo-object-relationships-has-many-through-lab-nyc04-seng-ft-071220 | /lib/genre.rb | UTF-8 | 341 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Genre
attr_reader :name
@@all = []
def initialize(song_genre)
@name = song_genre
@@all << self
end
def songs
Song.all.select{|song_info|song_info.genre == self}
end
def self.all
@@all
end
def artists
songs.map{|artist_info| artist_inf... | true |
ea7118f625c6d2491d32b4fcc66461e4aae7a226 | Ruby | agarcher/fight-engine | /fighters/assassin.rb | UTF-8 | 113 | 2.703125 | 3 | [] | no_license | require_relative 'fighter'
class Assassin < Fighter
def attack_power
(@attack_power * 1.7).ceil
end
end
| true |
c5939e0487d00c4cba192076cc87ddae6b04a118 | Ruby | davidmjiang/assignment_sinatra_basics | /modules/helpers.rb | UTF-8 | 408 | 3.578125 | 4 | [] | no_license | module Helpers
def win?(input)
input = input.downcase
win = { 'rock' => 'scissors', 'paper' => 'rock', 'scissors' => 'paper' }
game_move = win.keys.sample
if input == game_move
"Tie. Computer chose #{game_move}"
elsif win[input] == game_move
"Win. Computer chose #{game_move} "
els... | true |
ef7270b2a1e515796d94d5ff48292d8beaec3b90 | Ruby | mathieujobin/isrubyfastyet | /Rakefile | UTF-8 | 1,465 | 2.703125 | 3 | [] | no_license | require File.expand_path('../isrubyfastyet', __FILE__)
require 'simple_stats'
desc "Is the benchmark producing consistent ouput? Show how different the last result vs. the median of the 5 previous results for stable rubies"
task :variability do
offset = (ENV['OFFSET'] ? ENV['OFFSET'].to_i : 0)
previous_count = (... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.