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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
62280142080ff0caf4b89a140e1a1215cba1291b | Ruby | ajrussellaudio/record_store | /models/stock.rb | UTF-8 | 2,847 | 3.328125 | 3 | [] | no_license | require_relative "../db/sql_runner"
class Stock
attr_accessor :album_id, :format, :buy_price, :sell_price, :current_stock_level, :reorder_threshold
attr_reader :id
def self.all()
sql = "SELECT * FROM stocks;"
Stock.map_items(sql)
end
def self.delete_all()
sql = "DELETE FROM stocks;"
SqlRun... | true |
881b84f9af4ae172956a304bd310ef204942518b | Ruby | codedomo/log_parser | /lib/log_parser/data_loader.rb | UTF-8 | 458 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module LogParser
class DataLoader
attr_accessor :results
def initialize(file)
@file = file
@results = Hash.new { |hash, key| hash[key] = [] }
end
def call
load_content
results
end
private
def load_content
File.foreach(file) d... | true |
ed21fd19a3537500413477d60baececb8bd3fdd6 | Ruby | manuelorantes/Napakalaki-Ruby | /Examenes/Prueba_Napakalaki.rb | UTF-8 | 7,145 | 3.296875 | 3 | [] | no_license | require './Prize.rb'
require './TreasureKind.rb'
require_relative 'Monster'
require './BadConsequence.rb'
require_relative 'EstadisticaTesorosGanados'
#Comprueba y mete en un array os monstruos que tienen mas de diez niveles estrictamente.
#Primera forma de hacer bucles en ruby a la vez que se introducen en un vecto... | true |
0f37c024f6050603951788f98f14770db0db5751 | Ruby | fuzoh/POO2 | /algorithmic/recursion/1findByName.rb | UTF-8 | 1,116 | 3.171875 | 3 | [] | no_license | # Search a filename matching a needle
def find_files_by_needle (basePath, needle)
array = []
# Iterates all folders
Dir.foreach(basePath) do |element|
# Ingnore . and .. pseudo files
unless element == '.' || element == '..'
# Joins the full path
path = File.join(basePath, element)
# Chec... | true |
959e209ec11db4d835655c5cc38a78d89a2ffb29 | Ruby | diasbandeira/cucumberTests | /features/step_definitions/steps.rb | UTF-8 | 622 | 2.828125 | 3 | [] | no_license | Dado("que eu tenha {int} laranjas novas") do |int|
@laranjasEstoque = int
end
Quando("eu vender {int} laranjas") do |int|
@laranjasVendidas = int
@totalLaranjas = @laranjasEstoque - @laranjasVendidas
end
Então("subtraio as laranjas sobraram") do
expect(@totalLaranjas).to eq 8
end
Quando("eu compra... | true |
872d542e7fc64379b6ab532ec7b97e6f43009975 | Ruby | eregon/Classes | /tree.rb | UTF-8 | 10,070 | 3.53125 | 4 | [] | no_license | =begin
Waow: this is beautiful
def printTree(tree,indent)
if (Array === tree)
tree.map { |child| printTree(child,indent+"| ") }
else
puts(indent.gsub(/\s+$/,"--")+tree.to_s)
end
end
printTree([1,2,[11,22,[111,222,333,444],33],3,4],"")
this give :
|--1
|--2
| |--11
| |--22
| | |--111
| | |--22... | true |
aacb0bd484a412d8d81eb2aa0ac885412ccf7f59 | Ruby | pravn/ipm_mongo | /lib/parse_file.rb | UTF-8 | 1,679 | 2.765625 | 3 | [] | no_license | $LOAD_PATH << '.'
require 'Parsedefs'
require 'find_loc'
require 'mongo_ops'
def parse_file(file_handle, dbname)
banner=Dataset::Banner.new("banner")
base=Dataset::Base.new("base")
# no_region=NoRegion.new
#create the mongodb object
Mongo_ops.initialize(dbname)
Mongo_ops.coll("collection")
h=Hash.new
... | true |
7a1c3d4a4a0e2815190446edde6cb1a4254b1234 | Ruby | puyo/exercises | /ruby/stereogram/test_stereogram.rb | UTF-8 | 816 | 2.875 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative './stereogram'
require 'test/unit'
class StereoGramTest < Test::Unit::TestCase
FIXTURES = [
['pyramid', 'the t reesareouttog e tyouandbreakyo urbabieswiththeirbranches'],
['tree', 'the t reesareouttog e tyouandbreakyo urbabieswiththeirbranches'],
].freeze
def test... | true |
589450701b17dcdd66e996b24b196406df13b4e6 | Ruby | scooternk/AppAcademy | /battleship_project/procs_project/lib/part_1.rb | UTF-8 | 706 | 3.734375 | 4 | [] | no_license | def my_map(array, &block)
a = []
array.each do |e|
a << block.call(e)
end
return a
end
def my_select(array, &block)
a = []
array.each do |e|
a << e if block.call(e)
end
return a
end
def my_count(array, &block)
cnt = 0
array.each do |e|
cnt += 1 if block.... | true |
10ff181702887f6b58d32973bc9c5273d434956e | Ruby | DataDog/datadog-api-client-ruby | /lib/datadog_api_client/v1/models/search_slo_query.rb | UTF-8 | 3,504 | 2.59375 | 3 | [
"GPL-2.0-or-later",
"Artistic-2.0",
"WTFPL",
"MIT",
"BSD-3-Clause",
"Apache-2.0",
"BSD-2-Clause"
] | permissive | =begin
#Datadog API V1 Collection
#Collection of all Datadog Public endpoints.
The version of the OpenAPI document: 1.0
Contact: support@datadoghq.com
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator
Unless explicitly stated otherwise all files in this repository are licensed ... | true |
caf9c09d05c258f93986a341e3d9c1ae1d7103cb | Ruby | sulton78x/cli_hangman_game-ruby | /play.rb | UTF-8 | 2,756 | 4.0625 | 4 | [] | no_license | class Hangman
def initialize
@letters = ('a'..'z').to_a
@word = words.sample
@lives = 7
@correct_guesses = []
@word_teaser = ""
@word.first.size.times do
@word_teaser += "_ "
end
end
def words
[
["c... | true |
35d1aea81a1f553e13151c7a96a3d748436e53d4 | Ruby | BioBoost/gitlabhq | /lib/gitlab/commits_calendar.rb | UTF-8 | 724 | 2.53125 | 3 | [
"MIT"
] | permissive | module Gitlab
class CommitsCalendar
attr_reader :timestamps
def initialize(repositories, user)
@timestamps = {}
date_timestamps = []
repositories.select(&:exists?).reject(&:empty?).each do |raw_repository|
commits_log = raw_repository.commits_per_day_for_user(user)
date_tim... | true |
bab66c0c252959aa1bbab54b0324caa38d16a137 | Ruby | reichardn/deli-counter-v-000 | /deli_counter.rb | UTF-8 | 488 | 4.15625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def line(kd)
size = kd.size
ans = "The line is currently"
if size == 0
ans << " empty."
else
ans << ":"
kd.each_with_index do |p, i|
ans << " #{i+1}. #{p}"
end
end
puts ans
end
def take_a_number(kd, name)
kd << name
puts "Welcome, #{name}. You are number ... | true |
5e4ef567028cedf634593d0467eb1caa68e6867e | Ruby | swipswaps/anyscp | /app/models/file_transfer.rb | UTF-8 | 2,002 | 2.78125 | 3 | [] | no_license | require 'net/scp'
require 'net/ftp'
class FileTransfer
@queue = :file_transfer
TMP_LOCATION = '/tmp'
FTP = 'ftp'
SCP = 'scp'
def self.perform(source_hostname, source_file, dest_hostname, dest_file, source_mode, dest_mode)
puts "Performing file transfer from #{source_hostname}:#{source_file} to #{de... | true |
83b1f4a8c428a3c4725587fcb8de9c9af3eed76c | Ruby | kevinday/project-euler | /27.rb | UTF-8 | 557 | 3.59375 | 4 | [] | no_license | require_relative "helpers"
maxA = 999
maxB = 999
@sieve = getSieve(100000)
def consecutivePrimes(a, b)
n = 0
while true
result = n ** 2 + a * n + b
break if @sieve[result] == 0
n += 1
end
n
end
maxPrimes = 0
product = nil
(maxA * -1).upto(maxA) do |a|
1.upto(maxB) do |b|
#b h... | true |
01a7181aafe804b4e0825d17aa239d016792fcf2 | Ruby | kentakodama/aa_prep | /Time Class.rb | UTF-8 | 179 | 3.390625 | 3 | [] | no_license |
time = Time.new
puts time
bday = Time.new(1987, 12, 30, 1, 38)
puts bday
bday2 = Time.mktime(1987, 12, 30, 1, 38)
puts bday2
years = (time - bday) / (60*60*24*365)
puts years | true |
1fba4fccec1d25668860a391955a91125e0d452c | Ruby | carbonfive/smarty | /lib/smarty/search_results.rb | UTF-8 | 754 | 2.6875 | 3 | [] | no_license | module Smarty
class SearchResults
include Enumerable
extend Forwardable
def_instance_delegators :@results, :each, :size, :length, :empty?
attr_reader :query, :source
def initialize(query, response)
@query = query
@source = response
@results = SearchResults.build_results(@sourc... | true |
48b14509b0c65ebed0aeb2f9f6d7c9a3f8023792 | Ruby | hubertwwong/ruby_scrape_zip_01 | /src/mechanize_wiki.rb | UTF-8 | 9,031 | 3 | 3 | [] | no_license | require 'rubygems'
require 'mechanize'
require_relative 'sql_util'
require_relative 'scrape_util'
require_relative 'state_util'
require_relative 'yaml_util'
class MechanizeWiki
# instance variables for the db.
attr_accessor :url, :user, :password, :db_name, :table_name, :web_url, :user_agent
... | true |
025475496517dc47b8a4d14867462e2acc477a99 | Ruby | katheroine/languagium | /ruby/functions/default_arguments.rb | UTF-8 | 311 | 3.453125 | 3 | [] | no_license | #!/usr/bin/ruby2.7
def function_with_default_argument(argument = 3)
argument * 2
end
result = function_with_default_argument()
puts("Result of calling function with default argument: #{result}")
result = function_with_default_argument(4)
puts("Result of calling function with default argument: #{result}")
| true |
bd1152fc79cc3d242f0b3becc8c6f54a8c1496f9 | Ruby | acmesquita/exampleStoreRuby | /order.rb | UTF-8 | 400 | 3.390625 | 3 | [] | no_license | class Order
def initialize (options = {})
@id = options[:id]
@product = options[:product]
@quantity = options[:quantity].to_i
end
attr_accessor :quantity, :product, :id
def to_s
"ID:" + @id.to_s + " - Product:" +@product.titulo + " - Quantity:" + @quantity.to_s
end
def add_quantity(quantity = 1)
@qu... | true |
6e1f3b58d21c0dc5afdb59669cf9e1e1745032fa | Ruby | jodag/ScheRuby | /lib/scheruby/evaluator.rb | UTF-8 | 7,850 | 3.0625 | 3 | [] | no_license | class Object
def eval!(binding = Kernel,env_frame = EnvFrame.new)
self
end
def teval!(binding = Kernel,env_frame = EnvFrame.new, tail_call = false)
eval!(binding, env_frame)
end
end
class Symbol
def eval!(binding = Kernel, env_frame = EnvFrame.new)
case symbol_type
when :local, :dotmeth... | true |
98846bac6c1f0f91c7a9686f599eb285874a784e | Ruby | SLP-KBIT/c3l | /spec/lib/card_spec.rb | UTF-8 | 522 | 2.515625 | 3 | [] | no_license | require 'spec_helper'
require 'card'
describe Card do
subject(:blue) { Card.new(Card::COLOR_BLUE) }
subject(:red) { Card.new(Card::COLOR_RED) }
describe ".red?" do
context "blue cell" do
it { expect(blue.red?).to be_false }
end
context "red cell" do
it { expect(red.red?).to be_true }
... | true |
e2b672f8f36b2e12cc03a74c015c87f7291679b0 | Ruby | b1nary/ws2801 | /test/color_testing.rb | UTF-8 | 1,532 | 2.75 | 3 | [] | no_license | #
# Testing the user-space driver (ws2801)
# with wonderful colors <3
#
require_relative '../lib/ws2801.rb'
WS2801.generate # generate empty strip (Would happen from alone if you just start setting colors)
WS2801.length 25 # default
WS2801.device "/dev/spidev0.0" # default
WS2801.autowrit... | true |
bea695833f6f0982a272ede08a32db0033e5a4b0 | Ruby | iroshiva/exo_ruby | /exo_16.rb | UTF-8 | 494 | 3.78125 | 4 | [] | no_license | #Le programme exo_15.rb est cool, mais on peut l'améliorer. Écris un programme exo_16.rb qui va demander son âge à l'utilisateur,
puts "Balance ton age!"
age = gets.chomp.to_i
ann_actuelle = 2019
ann_naiss = ann_actuelle - age
age_naiss = 0
while ann_naiss <= ann_actuelle
puts " #{ann_naiss} Il y a #{ann_actuelle ... | true |
c3d108f0c30e9aeb8d452cd0960abc1dc8202db6 | Ruby | LimitToInfinity/jukebox-cli-denver-web-060319 | /lib/jukebox.rb | UTF-8 | 1,641 | 3.796875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # def say_hello(name)
# "Hi #{name}!"
# end
# puts "Enter your name:"
# users_name = gets.chomp
# puts say_hello(users_name)
songs = [
"Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted"... | true |
b4c00ab601843e4d39d11def7a5b539745709bc9 | Ruby | dlandy1/upveil | /app/models/concerns/votes_manager.rb | UTF-8 | 1,163 | 2.625 | 3 | [] | no_license | class VotesManager
attr_reader :user, :product
def initialize(user, product)
@user = user
@product = product
end
def up_vote!
REDIS.multi do
REDIS.incr product_vote_key
REDIS.sadd product_up_voters_key, user.id
end
true
end
def down_vote!
REDIS.multi do
REDIS.... | true |
370ca29e26e2a11ee1db542fcd44b212f282d3ad | Ruby | annejohnson/ruby-data-structures | /dictionary/splay_tree.rb | UTF-8 | 4,312 | 3.078125 | 3 | [] | no_license | module Dictionary
class SplayTree
attr_reader :size
POS_INF = 10000000000000
def initialize
@root, @size = nil, 0
end
def insert(key, value)
@root = splay(key, @root)
return nil if @root && @root.key == key
@size += 1
if @root.nil?
@root = Node.new(key, ... | true |
d32560fbb43cc4e4ac65fe8b155d6e89edbdca1c | Ruby | bitland/hexwrench | /lib/hexwrench/stringslist.rb | UTF-8 | 2,871 | 2.546875 | 3 | [
"MIT"
] | permissive | ### DEPRECATED by stringsvlist.rb
require 'rbkb/extends'
module Hexwrench
class StringsFrame < Wx::Frame
attr_reader :strings_list
def initialize(parent, editor, strings_opts=nil)
unless @editor = editor
Kernel.raise "#{self.class}.new() requires an editor window parameter"
end
su... | true |
8b2191b644ccf9b65b42444b3bf212942af5bdae | Ruby | rickenharp/thirteenth_age | /lib/thirteenth_age/monster.rb | UTF-8 | 530 | 2.875 | 3 | [
"MIT"
] | permissive | require_relative 'monster/base'
require_relative 'monster/normal'
require_relative 'monster/mook'
require_relative 'monster/large'
require_relative 'monster/huge'
module ThirteenthAge
module Monster
MONSTER_TYPES = {
"normal" => Normal,
"mook" => Mook,
"large" => Large,
"huge" => Huge,
... | true |
d61c78b9d1ef90c2a19628ddc45e7b8c128b683f | Ruby | AJ8GH/makers-side-projects | /greetings.rb | UTF-8 | 1,457 | 4.5625 | 5 | [] | no_license | # A client is asking us for the following program:
# I hate my mate Steve: so much so that my hatred spills over to anyone with a first name beginning with 'S'.
# I want a program that, when anyone types their name in, shouts at them if their name begins with an 'S'.
# Anyone else should just get a friendly greeting.
#... | true |
09fcffc6733504d1b20507beb0f2bb7b119d54b3 | Ruby | mathildell/iye | /test/unit/test_translation.rb | UTF-8 | 1,552 | 2.75 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require "test_helper"
require "i18n_yaml_editor/translation"
class TestTranslation < Minitest::Test
def test_text
translation = Translation.new(text: "Some string")
assert_equal "Some string", translation.text
end
def test_empty_text_is_nil
translation = Translation.new(text: "")
... | true |
fdeeb713a7a95f856e70b698c92dc54eafec7d75 | Ruby | duffydduffyd/backcourt_dribble | /app/models/user.rb | UTF-8 | 774 | 2.6875 | 3 | [] | no_license | require 'bcrypt'
class User < ActiveRecord::Base
has_many :scores
#how to get user.questions
has_many :questions, through: :scores, source: Question
include BCrypt
# same as null false in migrations
validates :email, :password_hash, presence: true, uniqueness: true # if this isn't true active rocord creat... | true |
b365ac3f74584ae0701118a2279628a58bf85761 | Ruby | innervisions/small-problems | /06_easy_5/08.rb | UTF-8 | 483 | 4.125 | 4 | [] | no_license | # 08 - Alphabetical Numbers
NUMBER_WORDS = %w[zero one two three four five six seven eight
nine ten eleven twelve thirteen fourteen
fifteen sixteen seventeen eighteen nineteen]
def alphabetic_number_sort(numbers)
words = numbers.map { |number| NUMBER_WORDS[number] }
words.sort.m... | true |
f53f2b9d814a95edbb9dd598e90a6eca0425d453 | Ruby | TecnoSigma/NutriSigma | /spec/models/gender_spec.rb | UTF-8 | 1,704 | 3.125 | 3 | [] | no_license | require 'rails_helper'
describe Gender do
describe "#description" do
it "should be masculino when M" do
gender = Gender.from_letter('M')
expect(gender.description).to eq "masculino"
end
it "should be feminino when F" do
gender = Gender.from_letter('F')
expect(gender.description).t... | true |
d591e333cd89c890684be723db0fac6f30a0cb4e | Ruby | olvap/learnosity-sdk-ruby | /lib/learnosity/sdk/request/init.rb | UTF-8 | 6,543 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | require 'digest'
require 'json'
require 'learnosity/sdk/exceptions'
require 'learnosity/sdk/utils'
module Learnosity
module Sdk
module Request
class Init
# XXX: Needs to be public for unit tests
attr_reader :security_packet, :request_string
# Keynames that are valid in the security_packet, the... | true |
4ae7884678cf276ef81c0d7b8ab7227ded93b646 | Ruby | bdurand/lumberjack | /lib/lumberjack/formatter/pretty_print_formatter.rb | UTF-8 | 616 | 3.078125 | 3 | [
"MIT"
] | permissive | # frozen_string_literals: true
require "pp"
require "stringio"
module Lumberjack
class Formatter
# Format an object with it's pretty print method.
class PrettyPrintFormatter
attr_accessor :width
# Create a new formatter. The maximum width of the message can be specified with the width
# p... | true |
066b78be11b0677c3ed4153f7559b156443fb369 | Ruby | liquidconcept/gcalmapper | /spec/mapper/simple_spec.rb | UTF-8 | 1,264 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'spec_helper'
describe GcalMapper::Mapper::Simple do
before :all do
class User2
include GcalMapper::Mapper::Simple
attr_accessor :id, :first_name, :name
end
@base = GcalMapper::Mapper::Simple::Simple.new(User2)
end
it "should create a new object and save it" do
@base.create... | true |
329f714b2cd9d6f5c7ffc8adbda8dfcd7ccb514a | Ruby | BrandonTat/Practice-Problems | /leetcode/problems/path_sum.rb | UTF-8 | 1,026 | 4.15625 | 4 | [] | no_license | # Given a binary tree and a sum, determine if the tree has a root-to-leaf
# path such that adding up all the values along the path equals the
# given sum.
#
# For example:
# Given the below binary tree and sum = 22,
# 5
# / \
# 4 8
# / / \
# 11 13 4
# ... | true |
e3ee224ff57db05939b1162fd6e6326094827c23 | Ruby | javierbotero/Scraper-bot | /bin/main.rb | UTF-8 | 2,862 | 3.09375 | 3 | [] | no_license | require_relative '../lib/scraper_audio.rb'
require_relative '../lib/scraper_video.rb'
require_relative '../lib/scraper_gps.rb'
SessionVideo.new
SessionAudio.new
SessionGps.new
puts "\n---------------Bot-Page---------------\n
This is a Bot to check all the products and
prices offered on the Colombian technology
woocom... | true |
3d47dfe6e31220a1ac2ec361bd6e585efcb680b5 | Ruby | andrzejkrzywda/advent-of-code-2019 | /run_test_diagnostic_code_5.rb | UTF-8 | 165 | 2.53125 | 3 | [] | no_license | require_relative 'optcode'
array_of_numbers = File.open('./input5.txt').read.split(",").map(&:to_i)
Optcode::Computer.new(STDIN, STDOUT, array_of_numbers).execute
| true |
0611ffb0bc9fccf1c592e698b30f3c72bc771993 | Ruby | lukei8ii/mtg_online | /app/models/library.rb | UTF-8 | 429 | 3.25 | 3 | [] | no_license | class Library
attr_accessor :owner
attr_reader :deck
attr_reader :cards
def initialize(owner, deck)
@owner = owner
@deck = deck
@cards = []
@deck.deck_cards.each do |deck_card|
deck_card.amount.times do
card = deck_card.card
card.owner = @owner
card.original_owne... | true |
3646f5f339af415b6b6bc30b18f2195dac175ca8 | Ruby | chn-challenger/one_maths | /app/helpers/lessons_helper.rb | UTF-8 | 676 | 2.515625 | 3 | [] | no_license | module LessonsHelper
def visible?(lesson)
lesson.status != 'Test'
end
def lesson_button(lesson)
button = nil
status = nil
case lesson.status
when "Published"
button = 'Test'
status = 'Test'
when 'Test'
button = 'Publish'
status = 'Published'
end
return ... | true |
2091b9534d63ae9a8c187fe5d9e929e96dd11802 | Ruby | CristianCristea/launch_school | /exercises/ruby/small_problems/easy_7/01_combine_two_lists.rb | UTF-8 | 744 | 4.40625 | 4 | [] | no_license | # Combine Two Lists
# Write a method that combines two Arrays passed in as arguments, and returns a new Array that contains all elements from both Array arguments, with the elements taken in alternation.
# You may assume that both input Arrays are non-empty, and that they have the same number of elements.
# each with... | true |
33c63722b81302780ab15248c9cdbd10916f835e | Ruby | Albin-Willman/proj-euler | /3/largest-prime.rb | UTF-8 | 133 | 3.15625 | 3 | [] | no_license | #!/usr/bin/env ruby
require './utils/prime-factor'
n = 600851475143
primes = factor(n)
puts "Here's your number: #{primes.keys.max}" | true |
84f7085498acdfea85d84d4c6a763b7b92dffe59 | Ruby | Trombed/RHood | /app/models/user.rb | UTF-8 | 3,244 | 2.546875 | 3 | [] | no_license | # == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# username :string not null
# password_digest :string not null
# session_token :string not null
# email :string not null
# funds :float ... | true |
cbc81e0971cd890176f4a10a5247edab5893b973 | Ruby | dbpatnode/ruby-oo-relationships-practice-auto-shop-exercise-sea01-seng-ft-060120 | /app/models/mechanic.rb | UTF-8 | 670 | 3.3125 | 3 | [] | no_license |
class Mechanic
attr_reader :name, :specialty
@@all = []
def initialize(name, specialty)
@name = name
@specialty = specialty
@@all << self
end
def self.all
@@all
end
# - `Mechanic#cars` Get a list of all cars that a mechanic services
def cars
Car.all.select {|car|car.mechanic =... | true |
0eea8b28ee9ba0fe0ac333ab91fb2c3978055d52 | Ruby | simon-engledew/stone | /models/application.rb | UTF-8 | 1,053 | 2.609375 | 3 | [] | no_license | module EngineFactory
# @cache = Cache.new
class << self
def load(root, filename)
source = File.open(File.join(root, filename), 'r').read
case extension = File.extname(filename)[1..-1]
when 'haml' then Haml::Engine.new(source)
when 'sass' then Sass::Engine.new(source, :load_paths =>... | true |
92237d2c86823856b13d1e1680dcce6546ec0da5 | Ruby | deepigarg/rubyx | /test/risc/interpreter/calling/test_minus.rb | UTF-8 | 1,665 | 2.765625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require_relative "../helper"
module Risc
class InterpreterMinusTest < MiniTest::Test
include Ticker
def setup
@preload = "Integer.minus"
@string_input = as_main("return 6 - 5")
super
end
def test_minus
#show_main_ticks # get output of what is
check_main_chain [LoadCon... | true |
6f4466f34e2fbe9257d3271e619f6b436ca605d8 | Ruby | zduci/design-patterns-in-ruby | /builder/desktop_computer_builder.rb | UTF-8 | 483 | 2.625 | 3 | [] | no_license | class DesktopComputerBuilder < ComputerBuilder
def initialize
reset
end
def display=(display)
computer.display = display
end
def add_cd(writer = false)
@computer.drives << Drive.new(:cd, 760, writer)
end
def add_dvd(writer = false)
@computer.drives << Drive.new(:dvd, 4000, writer)
end... | true |
dee0fa76e903e53134d676e8a62874206dd72c53 | Ruby | willfowls/prepcourse | /ruby_books/intro_to_ruby/end_of_book_exercises/10_thru_19/10.rb | UTF-8 | 299 | 4.15625 | 4 | [] | no_license | # Can hash values be arrays? Can you have an array of hashes? (give examples)
# Hash values can be arrays - see example below
# Array of hashes is possible
numbers = { odd: ["1", "3"], even: ["2", "4", "6"]}
p numbers[:even]
numbers = [{name: 'will'}, {name: 'eaton'}, name: 'elliot']
p numbers | true |
1bee02a3e67d69e457f30889504aa6d9a3494562 | Ruby | taw/cryptopals | /lib/chal42.rb | UTF-8 | 345 | 2.6875 | 3 | [] | no_license | class Chal42
def hack(public_key, msg)
hash = Digest::SHA1.hexdigest(msg)
# padding size doesn't really matter
prefix = "0001" + "ff" * 1 + "00" + hash
min = (prefix + "0" * (public_key.signature_size*2 - prefix.size)).to_i(16)
# 1 to n^(1/3) actually
(1..public_key.n/2).bsearch{|x|
x **... | true |
f68ed19407217f2537f96eb375bc6635c834e221 | Ruby | 0xddom/cobaya-old | /lib/cobaya/generator/literal.rb | UTF-8 | 3,109 | 3.359375 | 3 | [
"MIT"
] | permissive | module Cobaya
module Literals
end
##
# Implements a method that generates the true keyword
class Literals::True
def generate
[:true]
end
end
##
# Implements a method that generates the false keyword
class Literals::False
def generate
[:false]
end
end
##
# Implem... | true |
b5d967c32d98617ee9d974c0d6a1276deafaafa3 | Ruby | Pelletier-Bertrand/Bertrand-Vendredi | /exo_13.rb | UTF-8 | 132 | 3.375 | 3 | [] | no_license | puts "Quel est ton année de naissance ?"
a = gets.chomp.to_i
age = 2018-a
(age+1).times do |i|
puts "#{i+a}"
end
| true |
c37dc28df9828ca6e84b4873d62f1a7a78e743ea | Ruby | CLOSER-Cohorts/archivist | /lib/exporters/xml/ddi/instruction.rb | UTF-8 | 1,322 | 2.609375 | 3 | [
"MIT"
] | permissive | module Exporters::XML::DDI
# DDI 3.2 XML Exporter for {::Instruction}
#
# {::Instruction} is a direct alias of DDI 3.2 InterviewerInstruction.
#
# === Example
# doc = Nokogiri::XML::Document.new
# instruc = Instruction.first
# exporter = Exporters::XML::DDI::Instruction.new doc
# xml_node = ex... | true |
783d928ad7a0caebe296b39cf1d6e491347621a0 | Ruby | kira5281/ejerciciosruby | /vectornumerosrandom.rb | UTF-8 | 166 | 3.34375 | 3 | [] | no_license | print "Ingrese numero de elementos random: "
ele = gets.chomp.to_i
va = []
for i in 0..ele - 1
va[i] = rand(1000)
end
puts "Numeros aleatorios entre 1 y 1000 #{va}" | true |
d7a5914ae7abda57e7bdf88989352e75b0ef44dc | Ruby | chrisaugust/Launch-School-Intro-to-Programming | /final_exercises/exercise_4.rb | UTF-8 | 108 | 3.703125 | 4 | [] | no_license | ## final_exercises/exercise_4.rb
array = [1,2,3,4,5,6,7,8,9,10]
array.shift(0)
array.push(11)
puts array
| true |
3d8584c63e5c354fbb9cbff846230cf6b26ea54b | Ruby | chrislsavage/RubyCoderbyteEasy | /AdditivePersistence.rb | UTF-8 | 689 | 4 | 4 | [] | no_license |
# Using the Ruby language, have the function AdditivePersistence(num)
# take the num parameter being passed which will always be a positive
#integer and return its additive persistence which is the number of
#times you must add the digits in num until you reach a single digit.
# For example: if num is 2718 then your p... | true |
b4f025e9688809b2ce0e98430dd08f9e6489be79 | Ruby | CodingDojoDallas/ruby_dec_16 | /Sheikh_Shahzeb/range.rb | UTF-8 | 384 | 4.03125 | 4 | [] | no_license | # range assignemnt in Ruby Fundamentals #2
a = ["Ruby","PHP","C++","Python","Java"]
# .member?(val) method on an array
# puts a.member?("Ruby")
#.include?(val) method on an array, returns tru if parameter exists
# puts a.include?("Ruby")
# .last method on an array, returns last object
# puts a.last
# .max method ... | true |
6020ed65cba83d90a61f24e19bdfc930531326f6 | Ruby | Tomy8s/learn_to_program | /ch13-creating-new-classes/extend_built_in_classes.rb | UTF-8 | 279 | 3.625 | 4 | [] | no_license | class Integer
def factorial
self == 0 ? 1 : self * (self - 1).factorial
end
def to_roman
'M' * (self/1000) + 'D' * (self % 1000 / 500) + 'C' * (self % 500 / 100) + 'L' * (self % 100 / 50) + 'X' * (self % 50 / 10) + 'V' * (self % 10 / 5) + 'I' * (self % 5)
end
end | true |
275e77325f231dc298bf5978d454e6b3966d17b8 | Ruby | Origen-SDK/origen | /lib/origen/generator/stage.rb | UTF-8 | 2,466 | 3.390625 | 3 | [
"MIT"
] | permissive | module Origen
class Generator
# The stage provides a way to store objects in named banks for later retrieval.
# This is typically used during pattern generation to generate header, body and
# footer elements of a pattern in non-sequential order, allowing them to be
# combined at the end into the logic... | true |
0aab1dc8e5e3ea47f0a1ad7e453a8402e1726bc0 | Ruby | andrewlidong/aA_interview_questions | /look_and_say/look_and_say.rb | UTF-8 | 976 | 4.53125 | 5 | [] | no_license | # look_and_say
# Implement the 'look and say' function. 'Look and say' takes an input array and outputs an array that describes the count of the elements in the input array as they appear in order.
#
# Example:
#
# # there is one '1' in the input array
# look_and_say([1]) == [[1, 1]]
# # there are two '1's in the inpu... | true |
be6fe3905e131b7369d96a2a888f8140ab85beb5 | Ruby | JoshCheek/Conway-s-Game-of-Life | /spec/spec.rb | UTF-8 | 7,561 | 3.15625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'game_of_life'
describe GameOfLife do
context 'when initialized with [0,0], [1,1]' do
subject { GameOfLife.new [0,0] , [1,1] }
it { should be_alive_at(0,0) }
it { should_not be_alive_at(0,1) }
it { should_not be_alive_at(1,0) }
it { shou... | true |
d9085ee5433e720a79aa7616b2ad30efe4ba8949 | Ruby | jnunemaker/adapter | /lib/adapter/spec/an_adapter.rb | UTF-8 | 4,968 | 2.71875 | 3 | [
"BSD-3-Clause"
] | permissive | shared_examples_for "an adapter" do
it "can read the client" do
expect(adapter.client).to eq(client)
end
let(:key) { 'key' }
let(:key2) { 'key2' }
let(:unavailable_key) { 'foo' }
let(:attributes) {
{
'one' => 'one',
'three' => 'three',
}
}
let(:attributes2) {
{
... | true |
d5bcb97a6880cf6bc69b09981490647b96d1b194 | Ruby | therubymug/hitch | /lib/hitch/ui.rb | UTF-8 | 870 | 2.640625 | 3 | [
"MIT"
] | permissive | HighLine.track_eof = false
module Hitch
class UI
def self.prompt_for_group_email
Hitch.group_email = highline.ask("What is the group email? e.g. dev@hashrocket.com will become dev+therubymug+leshill@hashrocket.com") do |q|
q.case = :down
q.validate = /\A[a-zA-Z0-9_\.\-\+]+@[a-zA-Z1-9\-]+\.... | true |
990f4561dd8ebe252342f29a6b4e27ae17aee36a | Ruby | billperegoy/netlister | /lib/Inst.rb | UTF-8 | 614 | 3.125 | 3 | [] | no_license | # This class represents an instantiated module.
#
class Inst
attr_reader :name, :ports
def initialize(opts)
@name = opts[:name]
@mod = opts[:mod]
@ports = {}
check
create_inst_ports
end
def port_count
@ports.length
end
def mod_name
@mod.name
end
def find_port(name)
@... | true |
41a3496c3374be7d701005f35d41a4895418a158 | Ruby | K80Git/ruby | /paiza/c_rank/1_3.rb | UTF-8 | 1,320 | 3.703125 | 4 | [] | no_license | puts "問題--------------"
=begin
下記の問題をプログラミングしてみよう!
整数 n と n 個の整数 a_1, ..., a_n が改行区切りで与えられるので、 a_1, ..., a_n を与えられた順に、改行区切りで出力してください。
▼ 下記解答欄にコードを記入してみよう
入力される値
入力は以下のフォーマットで与えられます。
n
a_1
...
a_n
1 行目には整数 n が与えられ、2 行目から (n+1) 行目にかけては n 個の整数 a_1, ..., a_n が改行区切りで与えられます。
入力値最終行の末尾に改行が1つ入ります。
文字列は標準入力から渡されます。 標準入力から... | true |
025f74b083fa83745be71cae2b26c6f863985d9f | Ruby | jonzingale/Ruby | /geocoding/region.rb | UTF-8 | 1,487 | 3.296875 | 3 | [] | no_license | class Region
require 'matrix'
JACKRABBIT = [35.689054,-105.946113]
MY_HOUSE = [35.680067,-105.962163]
ST_JOHNS = [35.671955,-105.913378]
BUCKMAN = [35.698446,-105.9832] # default
COORDS = [BUCKMAN,MY_HOUSE,ST_JOHNS].freeze
def initialize(lat,long) ; @point = [lat,long] ; end
def jordan(miles) ; coord_dist(J... | true |
dec5bd0ddf3c3ef1dad78b65a37f245f7ffee089 | Ruby | newtheatre/history-project | /_plugins/smugmug_image.rb | UTF-8 | 4,058 | 2.5625 | 3 | [
"MIT"
] | permissive | # SmugImage
# Author: Will Pimblett, March 2016
#
# Get a single SM image in many sizes with liquid support
require_relative 'smugmug'
Struct.new("CustomSize", :name, :size)
class SmugImage < Smug
# See http://help.smugmug.com/customer/portal/articles/93250
SIZES = [
'ImageSizeTiny',
'ImageSizeThumb',
... | true |
7ea564c093a50646cee20f49bf1ad13d2248ff90 | Ruby | yangliyi/ruby-exercise | /hashes/ex3.rb | UTF-8 | 151 | 3.5 | 4 | [] | no_license | hash1 = {a: 1, b: 2, c: 3}
hash1.each_key do |k|
puts k
end
hash1.each_value {|v| puts v }
hash1.each do |k, v|
puts "key: #{k} value: #{v}"
end | true |
7941872cfd5ed83cf08e5c0bba9af3a34e9ae0e4 | Ruby | DirectXMan12/UJS-Utils | /config.ru | UTF-8 | 2,766 | 2.671875 | 3 | [] | no_license | require 'json'
module Rack
class DefaultPage < Directory
def default_pg_path
return @default_pg_path
end
def default_pg_path=(p)
unless (path =~ /^\//)
@default_pg_path = '/'+p
else
@default_pg_path = p
end
end
def initialize(root, default_path)
@default_pg_path = '[default]'
s... | true |
d5d05ea4b904d645be97f7c0dea8247c987ea826 | Ruby | halo/satellite | /lib/satellite/network/remote.rb | UTF-8 | 724 | 2.5625 | 3 | [] | no_license | require 'ipaddr'
require 'satellite/extensions/core/object/blank'
module Satellite
module Network
class Remote
attr_reader :id, :endpoint, :port
def initialize(options={})
@id = options[:id].to_s.strip.presence
self.endpoint = options[:endpoint]
self.port = options[:port]
... | true |
0bad3988425ab7228de695e6fb20252e567cfe95 | Ruby | zenx1521/soap_test | /app/mappers/xml_to_hash_params_mapper.rb | UTF-8 | 351 | 2.625 | 3 | [] | no_license | class XmlToHashParamsMapper
ATTRIBUTES = {
integer_to_string: ["value"].freeze,
concat: ["value_1", "value_2"].freeze
}.freeze
def self.map(operation:, xml:)
result = {}
ATTRIBUTES[operation.to_sym].each do |attribute|
result[attribute.to_sym] = xml.search("#{operation} #{attribute}").text... | true |
99491edc7e7e9fdca13edfe52f638a4fa337b3f3 | Ruby | dominictarr/practice | /tools/tool_state.rb | UTF-8 | 605 | 3.21875 | 3 | [] | no_license | class ToolState
def initialize
@current = :shelf
@all_transitions = {
:shelf => [:misplaced,:borrowed,:in_use],
:borrowed => [:shelf, :lost],
:misplaced => [:lost, :shelf],
:lost => [:shelf],
:in_use => [:shelf, :borrowed, :misplaced]
}
end
def possible_states
[:shelf,:in_use,:borrowed,:misplaced,:lost]... | true |
a3da46eb1142a7a078ed935e1e7baa49fb59ecff | Ruby | i2bskn-sandbox/tagged-gist | /spec/models/gist_spec.rb | UTF-8 | 1,742 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Gist do
let(:gist_o) {FactoryGirl.create(:gist)}
describe "#owner?" do
it "should return true if owner" do
expect(gist_o.owner?(gist_o.user)).to be_true
end
it "should return false if not owner" do
other_user = FactoryGirl.create(:user)
expect(gist_o.o... | true |
a30ef1cb23718b705f6b7bf389c0a401a1c32e2d | Ruby | richwblake/ruby-music-library-cli-onl01-seng-pt-110319 | /lib/music_library_controller.rb | UTF-8 | 2,842 | 3.71875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class MusicLibraryController
attr_accessor :path
def initialize(path = './db/mp3s')
importer = MusicImporter.new(path)
importer.import
end
def get_input_from_user
gets.chomp.strip
end
def song_list
Song.all.uniq.sort_by { |song| song.name }
end
def call
puts "Welcome to your musi... | true |
d2888d8e300044fca66f19eb75f62cc6a673843d | Ruby | bchutchison/pub_lab | /specs/pub_spec.rb | UTF-8 | 2,453 | 3.34375 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../pub.rb')
require_relative('../drink.rb')
require_relative('../customer.rb')
require_relative('../food.rb')
class PubTest < MiniTest::Test
def setup()
@customer = Customer.new("Walter", 80, 26, 1)
@customer2 = Customer.new("Walter", 80, ... | true |
eea56bdd8cfa7b6f51b4a1b418e18589ba28091c | Ruby | pmkreppein/sinatra-mvc-lab-v-000 | /app.rb | UTF-8 | 229 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative 'config/environment'
class App < Sinatra::Base
get('/'){
erb :user_input
}
post('/piglatinize'){
x = PigLatinizer.new
@answer = x.piglatinize(params[:user_phrase])
erb :answer
}
end | true |
b94c06d9b6ed878b7ac937a3612a7d8c1a5c2168 | Ruby | AllanTamdem/sync_server | /app/helpers/users_helper.rb | UTF-8 | 2,369 | 2.5625 | 3 | [] | no_license | module UsersHelper
include PathHelper
include ContentProvidersHelper
#
# FILE REPOSITORY STUFF
#
# check that the s3_key starts with the path in user.content_provider.technical_name
def user_has_access? user, s3_key
if user.admin == true
return true
end
repository_folders = user_g... | true |
d8fff976934a462ddf9e6667822517b4833e59d7 | Ruby | rrichardsonv/phase-0-tracks | /ruby/game/guessing.rb | UTF-8 | 1,718 | 4.125 | 4 | [] | no_license | class Guessing
attr_reader :game, :remaining_guess, :is_over
def initialize(word)
@is_over = false
@previous = Array.new
@remaining_guess = word.length
@remaining_guess /= 3
@remaining_guess += 1
@game = Hash.new
fudge_factor = 0
word.each_char do |char|
if @game.has_key?(ch... | true |
b69612a2d31975d8094bbde1c83cd52385a4670f | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grains/c7cbd9a3fd5c4a7d99c5e789264ef72b.rb | UTF-8 | 129 | 3.4375 | 3 | [] | no_license | class Grains
def square(num)
(1..num - 1).inject(1) { |grain| grain *= 2 }
end
def total
square(65) - 1
end
end
| true |
caa26737fa0ea3007ae96d5c5a87fc5fbadccac9 | Ruby | honeycomb-tv/ci-analysis | /bin/count-failures-by-test.rb | UTF-8 | 2,639 | 2.734375 | 3 | [] | no_license | #!/usr/bin/env ruby
require "fileutils"
require "nokogiri"
require "json"
require "csv"
require "pp"
class Report
attr_reader :failures
def initialize
@failures = []
end
def analyse_rspec_output(path)
xml = File.read(path)
doc = Nokogiri::XML(xml)
doc.css("testcase failure").each do |failure... | true |
1443afafe3799fdb0a1a260d9ea6ac045e3e6d8e | Ruby | learn-co-students/chicago-se-031521 | /04-oo-relationship-has-many-belongs-to/models/tweet.rb | UTF-8 | 434 | 3.09375 | 3 | [] | no_license | class Tweet
attr_reader :message, :user
@@all_tweets = []
def initialize(message_arg, user_arg)
@message = message_arg
@user = user_arg
@@all_tweets << self
end
def self.all
@@all_tweets
end
def username
self.user.username ## explict use of self
... | true |
6bff54e9d5159505dc0f8c41e853039df1163aa3 | Ruby | ssteeg-mdsol/openapi3-generator | /gems/gems/prawn-2.2.2/manual/images/fit.rb | UTF-8 | 553 | 2.53125 | 3 | [
"GPL-3.0-only",
"GPL-2.0-only",
"Ruby",
"Apache-2.0"
] | permissive | # <code>:fit</code> option is useful when you want the image to have the
# maximum size within a container preserving the aspect ratio without
# overlapping.
#
# Just provide the container width and height pair.
require_relative '../example_helper'
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualB... | true |
c6b05e8f6f0e7852326f6ba4207484f4df956410 | Ruby | davidmcdeavitt/WDI_12_HOMEWORK | /David/wk07/2-tue/warmup/get_squares.rb | UTF-8 | 119 | 2.59375 | 3 | [] | no_license | require "pry"
def get_squared(range)
range.select{|num| Math.sqrt(num) % 1 == 0}.sort.uniq
end
binding.pry
| true |
3abef65b11d5fd2a01469ea664dac2c8fb1771aa | Ruby | chad/rubinius | /kernel/bootstrap/context.rb | UTF-8 | 2,124 | 2.640625 | 3 | [] | no_license | class MethodContext
def self.new
raise TypeError, "MethodContext doesn't support #new"
end
def self.current
cur = Rubinius.asm { push_context }
return cur.sender
end
def activate(val)
Ruby.primitive :activate_context
raise PrimitiveFailure, "primitive failed"
end
def sender
... | true |
f70af64847704fcb515576d878887e4515c5a7a1 | Ruby | cjreitman/Classwork | /W6D5/RSPEC/lib/Towers.rb | UTF-8 | 558 | 3.421875 | 3 | [] | no_license | class Tower
attr_accessor :stacks
def initialize
@stacks = [ [3,2,1], [], [] ]
end
def moving_piece(stack)
unless stack < 0 || stack > 2 || @stacks[stack].empty?
@stacks[stack].pop
else
raise "Must select a valid, non-empty stack"
end
end
def move(o_stack, to_stack)
piece =... | true |
f2a54ff7bb6b03765d2dff185617821cb8dec369 | Ruby | vineethsomanchi/Algorithms-Practice | /General Practice/merge_two_binary_trees.rb | UTF-8 | 389 | 3.390625 | 3 | [] | no_license | #Recursive
def merge_trees(t1, t2)
result = TreeNode.new(0)
if t1.nil? && t2.nil?
result = nil
elsif t1.nil?
result = t2
elsif t2.nil?
result = t1
else
result.val = t1.val + t2.val
result.left = merge_trees(t1.left, t2.left)
result.right = merge_trees(... | true |
6fb3781c8087baf605c9713deba1e56171946778 | Ruby | JRSoftware92/Android-Class-Generator | /AXMLGenerator/src/main/run_sql_generator.rb | UTF-8 | 936 | 2.859375 | 3 | [] | no_license | require_relative 'android_sqlite_generator.rb'
#Indicates if insufficient arguments have been provided
if ARGV.nil? || ARGV.count < 4 then
puts "Insufficient arguments provided."
exit
else
dml_input = ''
ddl_input = ''
output = ''
template = ''
numArgs = ARGV.count
for i in 0..numArgs - 1
case i
when 0
... | true |
7b8de5f117e8ffcc1f4bf789c149679197810831 | Ruby | EscapeAD/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 674 | 3.8125 | 4 | [] | no_license |
def echo(phrase)
phrase
end
def shout(phrase)
phrase.upcase
end
def repeat(string, num = 2)
array = []
num.times do |x|
array << string
end
final = array.join(" ")
return final
end
def start_of_word(word, place)
words = word.split(//)
final = words.first(place).join
return final
end
def first_wor... | true |
e6b64935829ce3b396f8d94d3eaad706ac5b872e | Ruby | neanias/lrthw | /bin/ex43.rb | UTF-8 | 6,610 | 3.640625 | 4 | [] | no_license | class Game
def initialize(start)
@quips = [
"You died. You kind of suck at this.",
"Nice job, you died ... twit.",
"Such a loser..",
"I have a small puppy that's better at this.",
]
@start = start
end
def prompt()
print "> "
end
def play()
next_room = @start
... | true |
555cbe3d99deb96b7fe5fefbbc18173d4bbd6e84 | Ruby | sjreich/Exercises-for-Programmers_57-Challenges | /ch7/ex39.rb | UTF-8 | 1,624 | 3.171875 | 3 | [] | no_license |
theData =
{ 1 => { first_name: "John", last_name: "Johnson", position: "Manager", separation_date: "2016-12-31" },
2 => { first_name: "Tou", last_name: "Xiong", position: "Software Engineer", separation_date: "2016-10-05" },
3 => { first_name: "Michaela", last_name: "Michaelson", pos... | true |
4b49ebcd31cb37ddb92d9c57eb060df6c6048cd8 | Ruby | aziks/Week1 | /ShoppingCart.rb | UTF-8 | 1,245 | 3.75 | 4 | [] | no_license | require 'pry'
class Item
attr_reader :name, :price
def initialize(name, price)
@name = name
@price = price
end
end
class Houseware < Item
def price
#Hmmm maybe this changes somehow..
end
end
class Fruit < Item
def initialize(name, price)
super name, price
tim... | true |
685656b1b92ff3ffbc5c0866e3781dd4b7ecd961 | Ruby | learn-co-students/chicago-web-080320 | /freebie-tracker-code-challenge/app/models/company.rb | UTF-8 | 1,733 | 3.453125 | 3 | [] | no_license | class Company
attr_reader :name, :founding_year
@@all = []
def initialize(name, founding_year)
@name = name
@founding_year = founding_year
@@all << self
end
def freebies
# get access to all the freebies
# from that list, filter out the ones that belong to this company (self)
# sel... | true |
8961e6db066627b350b6c6b06561d1cea66ab248 | Ruby | kupolak/codewars | /Ruby/7 KYU/Simple Maths Test.rb | UTF-8 | 90 | 2.90625 | 3 | [] | no_license | require 'prime'
def number_property(n)
n = [Prime.prime?(n), n.even?, n % 10 == 0]
end
| true |
f1a70ebce73e212e1d16a0311b47d31006e808b5 | Ruby | bencornelis/market | /lib/market/checkout.rb | UTF-8 | 720 | 3.0625 | 3 | [] | no_license | class Checkout
def self.with_discounts
discounters = Discounter.types.map(&:new)
new(discounters)
end
attr_reader :basket, :discounters
def initialize(discounters = [])
@basket = []
@discounters = discounters
@printer = Printer.new(self)
end
def scan(item)
@basket << item
end
... | true |
6577a61ebfcb3458f00c54a7a39fb37c1984d9dc | Ruby | iksflow/PS | /ruby/leetcode/problems/P0035.rb | UTF-8 | 447 | 4.0625 | 4 | [] | no_license | # 35. Search Insert Position
# @param {Integer[]} nums
# @param {Integer} target
# @return {Integer}
def search_insert(nums, target)
left = 0
right = nums.size - 1
while left <= right
mid = (left + right) / 2
if nums[mid] == target
return mid
elsif nums[mid] < target
left = mid + 1
el... | true |
0c3e95d6320230da16d11f1b433c2c7e5b92fdd0 | Ruby | jcfischer/signum | /lib/signum.rb | UTF-8 | 689 | 2.734375 | 3 | [] | no_license | require File.expand_path '../signum/signature', __FILE__
require 'digest/md5'
require 'digest/sha2'
module Signum
# create a Signature for a params hash and a secret
# usage: Signum.signature_for :value => params, :secret => 'VeRySeCrEt'
# :method => :sha2
#
# supported methods... | true |
81ede6b72aa55b3fc2429e99b2893ba3450e4db2 | Ruby | jcbalcita/elixir-nba | /util/url_to_endpoint.rb | UTF-8 | 334 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'json'
name = ARGV[0]
full_url = ARGV[1]
split_url = full_url.split("?")
url, query_string = split_url.first, split_url.last
query_keys = query_string
.split("&")
.map { |pair| pair.split("=").first }
endpoint = {
name: name,
url: url,
parameters: query_keys
}
File.write("output.json", JSON.gener... | true |
cde2cb38f5269cd069afb58306120de7b2939967 | Ruby | seenevz/mod3_top_trumps | /backend_top_trumps/app/models/card.rb | UTF-8 | 217 | 2.546875 | 3 | [] | no_license | class Card < ApplicationRecord
def compare (opponent, attribute)
attr = attribute.to_sym
if self[attr] < opponent[attr]
self
else
opponent
end
end
end
| true |
b9f6ca7d3ebe5aebc1e6ed3d69f9da764f066d8d | Ruby | Workday/validate_my_routes | /lib/validate_my_routes/validate/rules/comparable.rb | UTF-8 | 3,454 | 2.609375 | 3 | [
"MIT"
] | permissive | module ValidateMyRoutes
module Validate
module Rules
# List of comparison rules
module Comparable
VR = ValidateMyRoutes::ValidationRules
VR.def_single_param_validator :eql do |expected|
validate { |actual, _| actual == expected }
description { "equal to <#{expected... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.