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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
433d511e32a1471afd4b7bb3f6f507870f4acaba | Ruby | AlexMMcConnell/dpl_2108 | /spec/library_spec.rb | UTF-8 | 3,641 | 3.21875 | 3 | [] | no_license | require 'rspec'
require './lib/book'
require './lib/author'
require './lib/library'
describe Library do
before(:each) do
@dpl = Library.new("Denver Public Library")
@charlotte_bronte = Author.new({first_name: "Charlotte", last_name: "Bronte"})
@jane_eyre = @charlotte_bronte.write("Jane Eyre", "October 16... | true |
72e3e2eb62ad82b6181911645c17342b15d53ef9 | Ruby | dongkai1208/RubyOO | /lib/smarter_parking_boy.rb | UTF-8 | 760 | 3.109375 | 3 | [] | no_license | require_relative '../lib/parkinglot'
require_relative '../lib/receipt'
require_relative '../lib/parking_boy'
class SmarterParkingBoy < ParkingBoy
def initialize ( *parkinglots )
super( *parkinglots )
end
def park(car)
parkinglot = max_car_lot_ratio()
if parkinglot!=nil
receipt = parkinglot.p... | true |
4eb7b2eaef352c268ecfe7be92e9994336f0d39e | Ruby | antonhornquist/grrr-rb | /lib/core_extensions/symbol/setter_getter.rb | UTF-8 | 578 | 3.265625 | 3 | [] | no_license | module CoreExtensions
module Symbol
module SetterGetter
# is_setter? - Answer whether the symbol has a trailing equals sign (equivalent to Symbol:isSetter in SC).
def is_setter?
self.to_s[-1] == ?=
end
# to_setter - Return a symbol with a trailing equals sign added (equivalent to Symbol:asSetter in ... | true |
383c8b00490043e3253d856d3b6c469955412bff | Ruby | fadendaten/six_saferpay | /lib/six_saferpay/models/brand.rb | UTF-8 | 402 | 2.75 | 3 | [
"MIT"
] | permissive | module SixSaferpay
class Brand
attr_accessor(:payment_method, :name)
def initialize(payment_method: nil, name:)
@payment_method = payment_method
@name = name
end
def to_hash
hash = Hash.new
hash.merge!(payment_method: @payment_method) if @payment_method
hash.merge!(nam... | true |
0bc12ee41b0b36e36382c0d2c6300b12538b8835 | Ruby | samuelschoe/RubyPragmaticStudio | /crowdfund.rb | UTF-8 | 913 | 2.796875 | 3 | [] | no_license | require_relative 'container'
cheesenoodles = Project.new(cheesenoodles,4528,225478)
VCLovesme = Container.new("VCLovesme")
VCLovesme.add_project(cheesenoodles)
VCLovesme.request_funding
project1=Project.new("billyball",200,5000)
project2=Project.new("bopaboo",2003,34000)
project3=Project.new("kilopsa",200... | true |
bd70c8650f2c0c02d55090e9f6d0be00ed555027 | Ruby | Absolventa/ereignishorizont | /app/models/expected_event.rb | UTF-8 | 3,500 | 2.515625 | 3 | [] | no_license | class ExpectedEvent < ApplicationRecord
# associations
#
#
belongs_to :remote_side, inverse_of: :expected_events
has_many :alarm_mappings, dependent: :destroy
has_many :alarms, through: :alarm_mappings
has_many :alarm_notifications, dependent: :destroy
has_many :incoming_events
# validations
#
... | true |
7865ba87d382a1af0d951b4cdab23e53f0607a1f | Ruby | digineo/xrechnung | /lib/xrechnung/allowance_charge.rb | UTF-8 | 878 | 2.515625 | 3 | [
"MIT"
] | permissive | module Xrechnung
class AllowanceCharge
include MemberContainer
# @!attribute charge_indicator
# @return [TrueClass, FalseClass]
member :charge_indicator, type: [TrueClass, FalseClass]
# @!attribute amount
# @return [Xrechnung::Currency]
member :amount, type: Xrechnung::Currency
... | true |
8a9299df64a8ad4c24eb765680529a118262ec15 | Ruby | yasuko-sawayama/fumihogo | /app/lib/redcarpet/product_page.rb | UTF-8 | 1,163 | 2.875 | 3 | [] | no_license | # Markdownをカスタマイズ
# ルビとダブルダッシュを処理
# rubocop:disable Metrics/LineLength
class Redcarpet::ProductPage < Redcarpet::Render::HTML
KANJIPAT = "[々〇〻\u3400-\u9FFF\uF900-\uFAFF※ヶ〆]".freeze
def normal_text(text)
replace_ruby(text)
replace_doubledash(text)
end
private
# 青空文庫形式のルビの置換を以下からコード借りて処理
# https://... | true |
d6621e3d1e4df03a28f9eb4ac0c0536213e4da10 | Ruby | ZuhairS/RSPEC-Practice-1 | /lib/02_calculator.rb | UTF-8 | 266 | 3.421875 | 3 | [] | no_license | def add(a, b)
a + b
end
def subtract(a, b)
a - b
end
def sum(arr)
arr.reduce(0, :+)
end
def multiply(arr)
return 0 if arr.empty?
arr.reduce(:*)
end
def power(num, pow)
num**pow
end
def factorial(num)
return 1 if num == 0
(1..num).reduce(:*)
end
| true |
170717cfe1a6a6e22a0d369a44f967f8372b2352 | Ruby | shaurya157/command-line-chess | /chess/chess.rb | UTF-8 | 1,264 | 3.75 | 4 | [] | no_license | require_relative 'board.rb'
require_relative 'player.rb'
require_relative 'display.rb'
require 'byebug'
class Chess
def initialize(name1, name2)
@board = Board.new
@player1 = Player.new(name1, :white)
@player2 = Player.new(name2, :white)
@current_player = @player1
@board.populate
@display = Di... | true |
0078d022ee6008a9c2e85772ef5530ca8eb6b2c3 | Ruby | jrode/projecteuler.net | /17.rb | UTF-8 | 636 | 3.546875 | 4 | [] | no_license | letters = 0
digits = ['','one','two','three','four','five','six','seven','eight','nine',
'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
tens = ['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
hundred, aand = 'hundred', 'and'
(1... | true |
b7991d4890d1aa50378104a5e5d9f9de890f1988 | Ruby | kareemgrant/warmup-exercises | /09-space-age/space_age.rb | UTF-8 | 580 | 3.828125 | 4 | [] | no_license | require 'date'
#ARGV - takes parameters from call to ruby file
# puts "What are you? #{}"
# birthdate = ARGV.map{|arg| arg.to_i}
birthdate = [1977, 06, 17]
# breaks out the array into 3 args required by datetime
date = Date.new(*birthdate)
birth_in_seconds = date.to_time.to_i
today_in_seconds = Date.today.to_time... | true |
55caf5651d48c11f6edac651cbf1f4b30e73c74e | Ruby | robflett/Snakes-and-ladders-practice | /specs/player_specs.rb | UTF-8 | 618 | 3 | 3 | [] | no_license | require('minitest/autorun')
require ('minitest/rg')
require_relative('../gameboard.rb')
require_relative('../die')
require_relative('../player')
class TestPlayer < MiniTest::Test
def setup
@die = Die.new(6)
@player1 = Player.new("Rob", 1, @die)
@player2 = Player.new("Ewen", 1, @die)
end
def test_sta... | true |
37c451f92c84a9d01fa30c50bda88d9cd4c28d34 | Ruby | ivanyshak/import-platform | /app/models/customer.rb | UTF-8 | 917 | 2.734375 | 3 | [] | no_license | class Customer < ApplicationRecord
# relation was implemented to know to which import current customer related
belongs_to :import
validates_length_of :first_name, minimum: 2, allow_blank: false
validates :email, email: { mode: :strict }, uniqueness: true
validates :date_of_birth, presence: true
validate :v... | true |
c2387b019414a9ddf96fdaf745adc9b341854d6c | Ruby | aantix/game_of_life | /lib/game_of_life_engine.rb | UTF-8 | 2,843 | 3.828125 | 4 | [] | no_license | class GameOfLifeEngine
OVERPOPULATED_THRESHOLD = 3
UNDERPOPULATED_THRESHOLD = 2
REPRODUCTIVE_MEASURE = 3
NEIGHBORS = [
[[-1, -1], [0, -1], [1, -1]],
[[-1, 0], [1, 0]],
[[-1, 1], [0, 1], [1, 1]]
]
##
# Two dimensional array; individual cells are boolean... | true |
17e24da7596124b9e51fe232fc4eb8390c0b1272 | Ruby | robinedman/heicharr | /models/employee.rb | UTF-8 | 254 | 2.703125 | 3 | [] | no_license | class Employee < ActiveRecord::Base
validates :name, presence: true
validates :salary, presence: true, numericality: true
def to_s
department = self.department ? self.department : "no department"
"#{self.name} (#{department})"
end
end
| true |
6b295a15c4fde0637f1c9303b9dab171b73bb666 | Ruby | dodzia/nosql | /export.rb | UTF-8 | 552 | 2.859375 | 3 | [] | no_license | require 'rubygems'
require 'couchrest'
require 'json'
file_name = ARGV[0]
dbase = ARGV[1]
port = ARGV[2]
couch = CouchRest.new("http://127.0.0.1:"+port.to_s)
db = couch.database!(dbase)
begin
file = File.open(file_name,"r")
rescue
puts "File error: "+file_name
end
hash_file=[]
file.each_line do |... | true |
48efea4b9358133d57fae9b0c2b6a1a45e406017 | Ruby | rkh/rubinius | /benchmark/tiers/1/bm_array_append.rb | UTF-8 | 87 | 2.828125 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def Bench.run
300_000.times do
ary = []
100.times { |i| ary << i }
end
end
| true |
d85b06be10a4f3e454ab4aaa7d7d090f0471869a | Ruby | trizen/sidef | /scripts/Games/bulls_and_cows_player.sf | UTF-8 | 1,561 | 3.46875 | 3 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
#
## http://rosettacode.org/wiki/Bulls_and_cows/Player#Sidef
#
# Build a list of all possible solutions. The regular expression weeds
# out numbers containing zeroes or repeated digits.
var candidates = (1234..9876 -> grep {|n| !("#{n}" =~ /0 | (\d) .*? \1 /x) }.map{.digits});
# Repeatedly prompt fo... | true |
76e8726206c2ae9028d7029a98624c7572ae246f | Ruby | kunklejr/system-metrics | /lib/system_metrics/nested_event.rb | UTF-8 | 1,388 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'active_support/notifications'
module SystemMetrics
class NestedEvent < ActiveSupport::Notifications::Event
attr_reader :action, :category
def self.arrange(events, options={})
events.sort! { |a, b| a.end <=> b.end } unless options[:presort] == false
while event = events.shift
if... | true |
af4fa8b072a8c0eca207db87d1ced2b7e683831e | Ruby | hlbtyne/oo-cash-register-london-web-career-040119 | /lib/cash_register.rb | UTF-8 | 729 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
attr_accessor :total, :discount, :items
def initialize(discount = 0)
@total = 0
@discount = discount
@employee_discount = 20
@items = []
@last_transaction = 0
end
def add_item(title, price, quantity = 1)
@last_transaction = price * quantity
@total += @last_tran... | true |
899eb6bbfcc842b4dfb22595150946720254fa0f | Ruby | nisayana/programming-univbasics-4-array-simple-array-manipulations-part-2-nyc04-seng-ft-071220 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 403 | 3.40625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_concat(arg1, arg2)
arg1.concat(arg2)
end
def using_insert(array, elem)
array.insert(4, elem)
end
def using_uniq(array)
new_array = array.uniq
end
def using_flatten(array)
array.flatten
end
def using_delete(array, string)
while array.include? (string)
puts array.delete(string)
end
return ... | true |
3fb68a59f9e34042950536ebd96d1c8549a91673 | Ruby | tchen10/ruby-performance-lnl | /calculations-within-iterators.rb | UTF-8 | 776 | 3.4375 | 3 | [] | no_license | require 'benchmark/ips'
# func([1, 2, 3]) => {1 => 1, 2 => 2, 3 => 3}
def without_method(array)
array.inject({}) { |h, e| h[e] = e; h }
end
def with_method(array)
array.inject({}) { |h, e| h.merge(e => e) }
end
array = (0..100).to_a
Benchmark.ips do |x|
x.report("without: ") { without_method(array) }
x.r... | true |
0a92ef065e90f2cc1d452f76ae106b07c4a851c6 | Ruby | LukasMac/BinaryTrees | /src/BinaryTree/node.rb | UTF-8 | 1,643 | 3.421875 | 3 | [] | no_license | class Node
attr_reader :value, :right_leaf, :left_leaf
def initialize(value)
@value = value
unless @value.nil?
@left_leaf = Node.new(nil)
@right_leaf = Node.new(nil)
end
end
def search(value)
return false if @value.nil?
if value > @value
@right_leaf.search(value)
elsif v... | true |
edd36a56eb3d80153d531737889fbfa1c3083fd6 | Ruby | italoadler/xi | /lib/xi/core_ext/numeric.rb | UTF-8 | 795 | 2.515625 | 3 | [
"MIT"
] | permissive | module Xi::CoreExt
module Numeric
def midi_to_cps
440 * (2 ** ((self - 69) / 12.0))
end
def db_to_amp
10 ** (self / 20.0)
end
def degree_to_key(scale, steps_per_octave)
accidental = (self - self.to_i) * 10.0
inner_key = scale[(self - 1) % scale.size]
base_key = ((se... | true |
718ee6b0ef6805d3f02cbbda5e79165bffae7720 | Ruby | ravisraval/AlgoPractice | /LeetCode/Ruby/Inc/167_two_sum_2_sorted_input_array.rb | UTF-8 | 982 | 4.34375 | 4 | [] | no_license | # Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
#
# The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers ... | true |
0f93b1ca251b85370a3fc0763b1290d94fe59026 | Ruby | vinodlala/worldwalker | /worldwalker.rb | UTF-8 | 3,912 | 3 | 3 | [] | no_license | require 'bundler'
Bundler.setup
require 'nokogiri'
require 'open-uri'
require 'pry'
require 'mechanize'
require 'debugger'
require 'sinatra'
require 'sinatra/reloader' if development?
require 'json'
#BASE_URL = "http://stackworld.herokuapp.com"
BASE_URL = "http://stormy-everglades-2242.herokuapp.com"
WORLD_START_URL ... | true |
2829c51e3371f05c0b15098c73dffa7ff19e1154 | Ruby | jonzingale/RubyProcessing | /ode/ode_vector.rb | UTF-8 | 1,204 | 2.859375 | 3 | [] | no_license | require 'matrix'
def setup
size(displayWidth, displayHeight)
colorMode(HSB,360,100,100,100)
@w, @h = width/2.0, height/2.0
frame_rate 60 ; background 0
stroke_width 2
@pts = points 400#00
@del_t = 0.03
@t = 1
end
# def trigs(theta)#:: Theta -> R2
# %w(cos sin).map{|s| eval("Math.#{s} #{theta}"... | true |
0fa3aea6e27d2fb173ee932be1af7330fb133cec | Ruby | SubZero9000/RubyWork | /cooking.rb | UTF-8 | 355 | 3.78125 | 4 | [] | no_license | #Pasta Bake recipe
puts "What recipe would you like to see?"
recipe = gets.chomp
puts "How many people are you serving?"
numberOfPeople = gets.chomp.to_i
pb = 50
m = 125
c = 37.5
def pastaBake(pb, m, c)
#pb is pasta bow, m is milk, c is cheese
pbNeeded = pb*numberOfPeople
mNeeded = m*numberOfPeople
cNeeded ... | true |
d8fa1845de20ae008110d20a6f4a6808240957b7 | Ruby | ugajin/daily-code | /aoj/Volume0/0003_is_it_a_right_triangle.rb | UTF-8 | 931 | 4.65625 | 5 | [] | no_license | # Is it a Right Triangle?
#
#-----------------------------
# Question
#
# Write a program which judges wheather given length of three side form a right triangle.
# Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
#
# -----------------------------
# Input
#
# Input consists of several dat... | true |
4dba4566229604620abe1d8ff34beedcd756060d | Ruby | groupsixtech/tp_plus | /lib/tp_plus/nodes/io_method_node.rb | UTF-8 | 1,374 | 2.625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | module TPPlus
module Nodes
class IOMethodNode < BaseNode
def initialize(method, target,options={})
@method = method
@target = target
@init_options = options
end
def requires_mixed_logic?(context)
true
end
def can_be_inlined?
true
end
... | true |
abe4d8d4f85efdf776e825efd64d647e44f503e5 | Ruby | liuganggang/note | /Evernote/encoding.rb | UTF-8 | 269 | 2.796875 | 3 | [] | no_license | str = str.force_encoding('GBK').encode('UTF-8')
str = str.encode('UTF-8')
当str.encoding == 'ASCII-8BIT'时,
ruby并不知道这个str的编码。
我用其他编辑器得知它的编码是GBK,所以我先强制将它标记为GBK,再转为UTF-8, 就成功了。 | true |
b1eb2a5c04a97ed0a74d5647cbb8e17243b2a88a | Ruby | ikemonn/AOJ | /ALDS1/elementary_data_structures/areas_on_the_cross-section_diagram.rb | UTF-8 | 523 | 3.5 | 4 | [] | no_license | def calc_area(backslash, slash, underscore)
# (上底+下底) * 高さ / 2
(underscore + (slash + backslash + underscore) * (backslash)) / 2
end
areas = gets.chomp.to_s
backslash = 0
slash = 0
underscore = 0
s = []
areas.chars do |char|
case char
when '\\'
backslash += 1
when '/'
slash += 1
when '_'
unde... | true |
279c1d0004eab6237d0f0a97f34934d58b4e61a9 | Ruby | bicyclethief/chess-challenge | /notation.rb | UTF-8 | 753 | 3.484375 | 3 | [] | no_license | require_relative 'coordinate'
require_relative 'square'
class Notation
LETTER_INDEX = { 'a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, 'g' => 6, 'h' => 7 }
LETTERS = ('a'..'h').to_a
RANK_TO_INDEX = { 8 => 0, 7 => 1, 6 => 2, 5 => 3, 4 => 4, 3 => 5, 2 => 6, 1 => 7 }
INDEX_TO_RANK = [8, 7, 6, 5, 4,... | true |
481dbba64580f71d13d42e4f47a9dec3688b037b | Ruby | panchal1992/Ruby_Practice | /iteration.rb | UTF-8 | 63 | 3.0625 | 3 | [] | no_license | fred = [4,5,6,7,8]
fred = fred.map{|x| 2 * x}
print fred.join
| true |
94d1ff8ff5e547d85a0890722996f7368f7f8bbe | Ruby | RileyMKDixon/OldSchoolProjects | /ECE 421/ECE-421-Project1/lib/csrfactory.rb | UTF-8 | 4,464 | 3.03125 | 3 | [] | no_license | require_relative 'csrmatrix.rb'
require_relative 'dokfactory.rb'
require_relative 'dokmatrix.rb'
require "test/unit"
require 'matrix'
include Test::Unit::Assertions
class Csrfactory
def csr_blank(rows, cols)
# pre conditions
# rows, cols, int >= 0
#
# post condition
# cs... | true |
154cc73ac83250f3a7488a850b8457054bb7e59d | Ruby | AskBid/artist-song-modules-online-web-sp-000 | /lib/song.rb | UTF-8 | 257 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Song
extend Memorable::CMethods
include Memorable::IMethods
# include Paramable
attr_accessor :name
attr_reader :artist
@@songs = []
def self.all
@@songs
end
def artist=(artist)
@artist = artist
end
end
| true |
b6ff5249d6aec74875b7486344e5d45d3099d6b8 | Ruby | morganp/finance_scripts | /bin/mortgage_completion_predictor | UTF-8 | 1,650 | 3.328125 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: UTF-8
##
## SCRIPT for calculating outstanding balance on Mortgage
## By altering payment details the effect of
## overpayments can be seen and used to decide how much to overpay
##
##
require 'pp'
require "yaml"
this_folder = File.expand_path('..', __FILE__)
config_file = File.j... | true |
60b31517130825110dc2be01332bf73f63686578 | Ruby | kirubahari76/rubylearning | /exe6.rb | UTF-8 | 268 | 3.28125 | 3 | [] | no_license |
no_of_friends = 4
k = " I have #{no_of_friends} friends"
friends = "frds"
have = "hv"
y = " My #{friends} dont #{have} any kind of attitude"
puts k
puts y
puts " I said #{k}"
puts "I also said #{y}"
lo = " Kiruba "
ve = " karan "
puts lo+ve
| true |
f5aa1647f231ee9788ab8eaa390296c2edf96e24 | Ruby | jacksono/EasyApply1 | /app/models/student.rb | UTF-8 | 860 | 2.9375 | 3 | [] | no_license | class Student < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email_address, :password, :confirm_password
validates_presence_of :first_name, :last_name, :email_address, :password, :confirm_password #to avoid blank fields
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i #gives format for a... | true |
60f5f01ef99819dac978a44b088522fff5551043 | Ruby | tahsin352/airtable-rest-client | /app/services/rest_client.rb | UTF-8 | 2,090 | 2.65625 | 3 | [] | no_license | # frozen_string_literal: true
# Public: RestClient Service
# All methods are controller methods and should be called on the RestClient controller.
class RestClient
# Public: Initialize the RestClient class.
#
# access_token - access token
# api_host - api host
def initialize(access_token:, api_host:)
@ac... | true |
8e60ba866fe376a72035038d1647f9d18c59eccf | Ruby | legalerts/ruby-openstates | /lib/openstates/model.rb | UTF-8 | 1,271 | 2.65625 | 3 | [
"MIT"
] | permissive | module OpenStates
module Model
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def from_hash(hash)
instance = new
instance.populate_from_hash!(hash)
yield instance if block_given?
instance
end
def hash_attr_accessor(*symbol... | true |
60104ac8223fd83cdc9991f4f99ea51e8822f3ed | Ruby | deliapater/Bus_stop | /specs/Bus.specs.rb | UTF-8 | 1,341 | 3.140625 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../Bus")
require_relative("../Person")
require_relative("../BusStop")
class TestBus < MiniTest::Test
def setup
@person1 = Person.new("John", 35)
@person2 = Person.new("Colin", 30)
@bus = Bus.new(22, "Ocean Terminal")
@stop1 = BusStop.new("Buchanan")... | true |
8fa1d7e5f3880d48b2afbcd4ffd222653587cf71 | Ruby | jwachira/leanrepo | /spec/models/timeline_spec.rb | UTF-8 | 3,734 | 2.625 | 3 | [] | no_license | require 'spec_helper'
describe Timeline, '#grouped_items' do
it 'returns notes and completions in a hash grouped by week' do
user = create(:user)
timeline = Timeline.new(user)
completion = create(:completion, user: user, slug: 'whatever')
note = create(:note, user: user)
beginning_of_week = com... | true |
b4bcf273f09aa47be12558998cc65eaebc609cf6 | Ruby | nelbren/my_codes_in_sololearn | /shift_cipher.rb | UTF-8 | 330 | 2.78125 | 3 | [] | no_license | #!/usr/bin/ruby
# shift_cipher_v0.0.4.rb
# nelbren@nelbren.com
# UseBracketSyntaxIn7lines
def shift_str(x,d)
r=''; x.each_byte{|c| r += (c == 32 ? c : (c + d > 90 ? c + d - 26 : c + d)).chr }; r
end
def cipher2text(x)
(0..25).each{|d| p "intento ##{sprintf '%02d', d}: #{shift_str(x,d)}" }
end
cipher2text('PHHW PH D... | true |
d66ad7c72e2996aa7b81de6dca7563be440dbf78 | Ruby | trizen/corvinus2 | /scripts/Introducere/Liste multidimensionale.cv | UTF-8 | 129 | 2.78125 | 3 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
var matrice = [[1,2,3], [4,5,6], [7,8,9]]
spune matrice[1][1]
matrice.fiecare { |linie|
spune linie.suma
}
| true |
f072e234cc2776885c9e3b42dcf478fb990c6d22 | Ruby | maiha/typed | /lib/typed/scala/builder.rb | UTF-8 | 2,486 | 2.859375 | 3 | [
"MIT"
] | permissive | module Typed
module Scala
module Builder
######################################################################
### Build instances
# check hash except arg size. (valid: return hash, invalid: raised)
def check(hash)
build(hash)
return hash
end
# check hash st... | true |
d0a4679327d0e0782c89bea21ef0464f2b639911 | Ruby | ryan-waller/ttsruby | /animal_sounds.rb | UTF-8 | 344 | 4.375 | 4 | [] | no_license | # Dog Says Cat Says:
# ask user to enter 'dog' or 'cat',
# program prints out animal's sound
puts "Choose an animal:"
choice = gets.chomp.downcase
case choice
when "dog"
puts "woof"
when "cat"
puts "meow"
elsif choice == "horse"
puts "neigh"
elsif choice == "pig"
puts "oink"
elsif choice == "cow"
puts "moo"
e... | true |
c02ad99abff34104caceb20c8cab694c9f3c0e25 | Ruby | beckylehmann91/phase-0 | /week-5/gps2_2.rb | UTF-8 | 4,278 | 4.1875 | 4 | [
"MIT"
] | permissive | =begin
Release 1:
INPUT:
- title of list, item, qty
OUPTPUT:
- the list itself
CREATE a new method called create_list that accepts INPUT
CREATE an empty list
END the method
INPUT:
- item, qty
OUPTPUT:
- the updated list
CREATE a method called add_item_qty that adds an item & its quantity to a list
SET the it... | true |
c1d83815d8b807fb454cebfe8f778df111351917 | Ruby | veruca-salt/gds-cta-svc-proto | /app/models/system_link.rb | UTF-8 | 3,005 | 2.578125 | 3 | [] | no_license | class SystemLink < ApplicationRecord
belongs_to :system_a, :class_name => 'System', inverse_of: :system_links
belongs_to :system_b, :class_name => 'System'
validates :system_b_id, presence: true #removed :system_a_id as it is returned from system create
validate :same_system_validation
before_save :duplicate_link
... | true |
ae89dc1a17adeeeabbb75f1dd69697f3bde68277 | Ruby | alethiaQ/ruby-enumerables-generalized-map-and-reduce-lab-online-web-prework | /lib/my_code.rb | UTF-8 | 423 | 3.453125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def map(source_array)
i = 0
new_arr = []
while i < source_array.length
new_arr.push(yield(source_array[i]))
i += 1
end
new_arr
end
def reduce(source_array, starting_point=nil)
if starting_point
total = starting_point
i = 0
else
total = source_array[0]
i = 1
end
... | true |
642f660accade748e172c840a6d7e3084516e810 | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz152_sols/solutions/James Koppel/cardcounting.rb | UTF-8 | 1,850 | 3.546875 | 4 | [
"MIT"
] | permissive | ####Usage: ruby cardcounting.rb <time in s> <num cards to display at once> <num decks>
COUNT_QUERY_CHANCE = 0.2
CARDS = %w[Deuce Three Four Five Six Seven Eight Nine Ten
Jack Queen King Ace]
SUITS = %w[Hearts Clubs Spades Diamonds]
def cartesian_product(first, *rest)
return first if rest == []
r... | true |
0904ef4a1edebcf5b5c497d6a0a53bef61becdad | Ruby | pwinning1991/testingruby | /splat.rb | UTF-8 | 632 | 3.78125 | 4 | [] | no_license |
#method can take as many arguments as possible ver scalable
def roster *players
puts players
end
roster "Phil","Dave","Jeff","Joe"
#taking key values as args to methods
def roster2 **players_with_postions
players_with_postions.each do |player, position|
puts "Player: #{player}"
puts "Position: #{positi... | true |
f3b811a6af86c9cf5e5372e48f94ff244f6c664b | Ruby | jonathanbouren/LS_Ruby | /RB101/Lesson4_ruby_collections/l4_a11_9.rb | UTF-8 | 102 | 2.875 | 3 | [] | no_license | words = "the flintstones rock"
words = words.split.map { |word| word.capitalize! }.join(' ')
p words
| true |
8705e740435fa64f790163e76364fd1a10fd99e6 | Ruby | JeffGebert/ar-exercises | /exercises/exercise_4.rb | UTF-8 | 825 | 3.078125 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
puts "Exercise 4"
puts "----------"
# Your code goes here ...
storesData = Store.create(
name: "Surrey",
annual_revenue: 224000,
mens_apparel: false,
womens_apparel: true
)
storesData = Sto... | true |
4bcc234f5504a9d2eeba5eec756e4b12b250eb83 | Ruby | derekb123/ruby_math_game | /question.rb | UTF-8 | 381 | 3.875 | 4 | [] | no_license | module Question
def question?(player)
num1 = rand(1...20)
num2 = rand(1...20)
sum = num1 + num2
puts "#{player.name} what is #{num1} + #{num2}?"
answer = gets.chomp
if answer == sum
puts "Great! You're not an idiot!"
return true;
else
puts "Sorry, you're an idiot."... | true |
90d61fd9558470f5da73801092a1d577c32ca64b | Ruby | casonye/BEWD-NYC | /chidinma_asonye/class5_a/apt_mgmt/main.rb | UTF-8 | 432 | 2.984375 | 3 | [] | no_license | require_relative 'lib/apartment'
require_relative 'lib/person'
a = Apartment.new("Bed-Stuy", 700, 600)
b = Apartment.new("Cobble Hill", 500, 900)
c = Apartment.new("Brooklyn Heights", 900, 400)
d = Person.new("chidinma", "beauty maven", "180000", "33")
apartments = [a, b ,c]
apartments.each do |apt|
if apt.rent_to... | true |
20bc1a81b0072282a2c1cd02d0bee5d74550f871 | Ruby | eneagoe/spoj | /ruby/test/add_reversed_numbers_test.rb | UTF-8 | 282 | 2.78125 | 3 | [] | no_license | # encoding: utf-8
require "test_helper"
require "add_reversed_numbers"
describe ".solve" do
it "returns the reversed sum of reversed numbers" do
with_stdin("3\n24 1\n4358 754\n305 794\n") do
-> { AddReversedNumbers.solve }.must_output "34\n1998\n1\n"
end
end
end
| true |
49b19fa072608ba9d470a7128d82f5444fb4b10c | Ruby | alanthewelsh/cc-week4-day2-pizzaHTML | /pizza_controller.rb | UTF-8 | 560 | 2.65625 | 3 | [] | no_license | require( 'sinatra' )
require( 'sinatra/contrib/all' )
require( 'pry-byebug' )
require_relative('./models/pizza.rb')
#RESTFUL ROUTE = path + method + action
#INDEX
get '/pizzas/?' do
@pizzas = Pizza.all
erb(:index)
end
#NEW
get '/pizzas/new' do
erb(:new)
end
#CREATE
post '/pizzas' do
new_pizza = Pizza.new(p... | true |
1d24f840cba83bea7137827a03824bbdbc7ad2ea | Ruby | briankim419/Codility | /Lesson4/scoreboard_player.rb | UTF-8 | 310 | 3.296875 | 3 | [] | no_license | require 'pry'
class Player
attr_reader :id
attr_accessor :scores
def initialize(id)
@id = id
@scores = []
end
def avg_score
sum = 0.00
return 0.00 if @scores.empty?
@scores.each do |score|
sum += score
end
avg = (sum / @scores.length).round_to(2)
end
end
| true |
06f3f2491cb1080ec87296abeebc3837f188abee | Ruby | otakumaa/ruby-objects-has-many-through-lab-onl01-seng-ft-081720 | /lib/genre.rb | UTF-8 | 343 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Genre
attr_accessor :name, :song, :artist
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def new_song(name, artist)
Song.new(name, artist, song)
end
def songs
Song.all.select {|song| song.genre == self}
end
def artists
songs.collect {|song| son... | true |
417667e0cdd4688aa4e0eb83bc6c906c3b58736f | Ruby | ianfixes/prism_qa | /gem/lib/prism_qa/imageset.rb | UTF-8 | 3,540 | 3.046875 | 3 | [
"Apache-2.0"
] | permissive |
module PrismQA
# A container for sets of images, with basic sanity checking
class ImageSet
# The container for all the images in the set
# @return [Array] of PrismQA::Image objects
attr_reader :images
def initialize
@images = []
@cache_valid = false # cache invalidation is so easy
... | true |
624ff940bf1784f7f5727c7ff1626644593081d3 | Ruby | sadooghi/jungle-rails | /app/models/user.rb | UTF-8 | 552 | 2.53125 | 3 | [] | no_license | class User < ActiveRecord::Base
has_secure_password
validates :email, uniqueness: true
validates :password, length: {minimum: 5}
validates :first_name, :last_name, :email,:password, :password_confirmation, presence: true
def self.authenticate_with_credentials(email,password)
usable_email = email.delet... | true |
8d2e40511183da54e19485f094ca597185f7f39f | Ruby | berkshelf/berkshelf | /lib/berkshelf/resolver.rb | UTF-8 | 4,096 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | module Berkshelf
class Resolver
require_relative "resolver/graph"
extend Forwardable
# @return [Berksfile]
attr_reader :berksfile
# @return [Resolver::Graph]
attr_reader :graph
# @return [Array<Dependency>]
# an array of dependencies that must be satisfied
attr_reader :deman... | true |
9cb341f1c40df71c33ae0b896d74e53dad8cf0e8 | Ruby | hawx/dapi | /examples/static | UTF-8 | 1,389 | 2.59375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'fileutils'
require 'redcarpet'
require 'sass'
require 'sinatra/base'
require 'slim'
require_relative '../lib/dapi'
opts = {
no_intra_emphasis: true,
fenced_code_blocks: true,
disable_indented_code_blocks: true,
strikethrough: true,
space_after_headers: true
}
Markdown = Redcar... | true |
0eddb252ab1ba8af674749fbe16a95495ae216d2 | Ruby | devnorris/chatty_duck | /rails_api/db/seeds.rb | UTF-8 | 2,550 | 2.8125 | 3 | [] | no_license | Chatroom.destroy_all
User.destroy_all
Message.destroy_all
Trip.destroy_all
Location.destroy_all
TripsUser.destroy_all
ChatroomsUser.destroy_all
puts "Creating chatrooms"
3.times do Chatroom.create!({
name:Faker::GameOfThrones.city,
})
end
puts 'Creating trips'
3.times do Trip.create!({
name:Faker::StarWars.plane... | true |
999c767ca4499490c0be454a0f27238a73efbe39 | Ruby | ElaErl/Intro-to-programming | /intro_to_prog/variables_2/2_3.rb | UTF-8 | 171 | 2.890625 | 3 | [] | no_license | #The first prints 3, while the second gives an error "undefined local variable or method",
# because x is not available (it is created only within the scope of the block). | true |
d9884117ad1e3566ab27c75a2e0bb2d37d5442f5 | Ruby | Maulkee/ruby_training_1 | /exo_15.rb | UTF-8 | 302 | 3.59375 | 4 | [] | no_license | puts "Salut, quelle-est ton année de naissance ?"
print ">"
annee = gets.chomp.to_i
today = 2020
age = 0
if annee > 2020
puts "Menteur!!!"
else
while annee <= 2020
print annee
puts " L'année de tes #{age} ans"
age = age +1
annee = annee +1
end
end | true |
842c554148864d531a46340fa185bdb7065eab2d | Ruby | yltsrc/warder | /lib/warder/runner.rb | UTF-8 | 1,295 | 2.875 | 3 | [
"MIT"
] | permissive | module Warder
# abstract class for command runners
class Runner
SCORE = 30
FAILURE_THRESHOLD = 0
def initialize(stdout, options = {})
@stdout = stdout
@options = options
@issues = 0
end
def perform
run_command do |line|
@issues += number_of_issues(line)
... | true |
40adbc959f448f260ac60ba6f8ab89564d45915c | Ruby | Jrive-cs/Ruby-Basics---Launch-School | /Ruby Basics/Loops 1/Loop on command.rb | UTF-8 | 365 | 3.953125 | 4 | [] | no_license | #loop do
# puts 'Should I stop looping?'
# answer = gets.chomp
#end
# Modify the code below so the loop stops iterating when the user inputs 'yes'.
i=1
loop do
puts 'Should I stop looping?'
answer = gets.chomp
if answer == 'yes'
break
else
i+=1
puts "incorrect answer. Please... | true |
ffa4fcf710429cd65905a7ed9a104e89ba38e4e3 | Ruby | bolek/ruby-algorithms | /evaluate_reverse_polish_notation.rb | UTF-8 | 854 | 3.734375 | 4 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Reverse Polish Notation parser
module RPN
@operations = {}
def self.register(operation, procedure)
@operations[operation] = procedure
end
def self.eval(tokens)
stack = []
tokens.each do |token|
stack.push(parse(token, stack))
end
stack.pop
end
private
d... | true |
69f087dec90623a61835f3bcc60174a7806bc18d | Ruby | mlan080/tea-shops | /app/models/shop.rb | UTF-8 | 1,534 | 3.078125 | 3 | [] | no_license | require_relative '../../config/database'
class Shop
attr_accessor :id, :name, :description #instance methods
attr_reader :id, :errors
def create
id = DB[:shops].insert(name: self.name, description: self.description) #self refers to the object calling the create method
Shop.find(id) #return the shop obje... | true |
e7bad979236ff80e140c8c34305db234b02d2f6a | Ruby | ShiLi007/square_array-v-000 | /square_array.rb | UTF-8 | 115 | 3.328125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
mapped = []
array.each do |num|
mapped.push(num*num)
end
return mapped
end | true |
04fe813aaefc9e0162177028e209212ed28b0d59 | Ruby | micko45/ruby_code | /num_2_digits.rb | UTF-8 | 227 | 3.296875 | 3 | [] | no_license | amount = $stdin.gets.chomp.to_i
def get_digets(num)
a = []
while num != 0
a.push(num % 10)
num = num / 10
end
end
(1..amount).each do
$stdin.gets.chomp.split.map(&:to_i)
get_digets(a[0] * a[1] + a[2])
end
| true |
350e26b96b81230c2253b16294f134599086e42e | Ruby | iamajvillalobos/LS_Exercises | /dog.rb | UTF-8 | 149 | 2.875 | 3 | [] | no_license | require_relative 'animal'
class Dog < Animal
def speak
'bark!'
end
def swim
'swimming!'
end
def fetch
'fetching!'
end
end
| true |
a7e26b66a0ae9077954e02163b5a749ec2eebc52 | Ruby | trondiz/aoc2017 | /day10p2.rb | UTF-8 | 1,029 | 3.1875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
n = Array.new
i = 0
sum = 0
File.open("data", "r") do |f|
f.each_line do |l|
l.split(//).each_with_index do |v,b|
next if v.ord == 10
n[b] = v.ord
end
end
end
n << 17 << 31 << 73 << 47 << 23
list = Array.new
curr_pos = 0
skip_size = 0
# Init list
for i in 0..255 do
list[i] =... | true |
51403d899acd6f8488cdad504676a800dfc23015 | Ruby | fureigh/confidential-survey | /spec/models/question_spec.rb | UTF-8 | 1,433 | 2.59375 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | require 'rails_helper'
describe Question do
describe '#initialize' do
let(:survey_id) { 'survey1' }
let(:hash) do
{ 'key' => 'race',
'text' => 'What is your racial identity?',
'type' => 'exclusive',
'values' => [
'indian|American Indian or Alaska Native',
'as... | true |
235f0f2065ba03ed285accdc020c0cb2db500f81 | Ruby | thebravoman/software_engineering_2015 | /hm_count_words/A_22_Pavel_Kostadinov.rb | UTF-8 | 678 | 2.734375 | 3 | [] | no_license |
require './A_22_Pavel_Kostadinov/word_counter.rb'
require_relative './A_22_Pavel_Kostadinov/word_counter/result'
filename = ARGV[0]
xml_json = ARGV[1]
def fileOrLink(filename)
protocol = filename.split('/').first
return protocol == 'http:' || protocol == "https:"
end
def result(filename,command)
if File.file? fi... | true |
f172436e76690236212711c3f6fdc9e57be5be87 | Ruby | ky-workspace/auto_sftp | /lib/autosftp/cli.rb | UTF-8 | 2,793 | 2.9375 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
require 'thor'
require 'autosftp/monitor'
require 'autosftp/file_access'
require 'autosftp/connection'
module Autosftp
class CLI < Thor
desc "start [remote name]", "Automatic monitoring start"
def start(word)
if false == Autosftp::FileAccess.exist?
puts "is not .autosft... | true |
e77b95a58da501788ab3d1736a406207be87d410 | Ruby | kristenkinnearohlmann/study-ruby | /Flatiron Code-Alongs/_Early Work/abstract-3-each-apples.rb | UTF-8 | 188 | 3.234375 | 3 | [] | no_license | basket = ["apple 1","apple 2","apple 3","apple 4","apple 5","apple 6","apple 7","apple 8","apple 9","apple 10"]
# Step 1,2,3,4,5
basket.each do |apple|
puts "Taking out #{apple}"
end | true |
11bfc5917e40e046196e2bf1a20e2b16a82a162e | Ruby | dannycho7/Ruby_Apps | /public_m.rb | UTF-8 | 176 | 3.203125 | 3 | [] | no_license | class User
WIDTH = 1
HEIGHT = 2
def initialize(w,h)
@width = w
@height = h
end
def self.print
puts "width is #{WIDTH} and height is #{HEIGHT}"
end
end
User.print
| true |
05bf2abec829cd67eccbeb5be6adcbe3850b56e9 | Ruby | cekynda/chapter12 | /task4.rb | UTF-8 | 360 | 3.671875 | 4 | [] | no_license | # frozen_string_literal: true
arr = [[[1, 2], 3], [4, 5, 6], [7, [8, 9]]]
def walk(array, &block)
case array
when Array
array.each do |i|
case i
when Array
i.each { |array| walk(array, &block) }
when Integer
block.call(i)
end
end
when Integer
block.call(arr... | true |
471b9cfc3ff25b51cd741563e752cb248b9d869b | Ruby | mtrovo/t-championsleague | /app.rb | UTF-8 | 2,914 | 2.53125 | 3 | [] | no_license | require 'em-twitter'
require 'json'
require 'colorize'
require 'chronic_duration'
require 'yaml'
require './aggregator'
require './web'
CONFIG = YAML.load_file('config.yml')
OPTIONS = {
path: '/1.1/statuses/filter.json',
params: { track: 'ChampionsLeague' },
oauth: CONFIG['oauth']
}
def format_colored_tweet(t)... | true |
7d9d15cb53d92fc561c0505fec7a5c82ec1439a6 | Ruby | noragrossman/thrift-shop-docs | /app/models/thrift_enum.rb | UTF-8 | 2,147 | 3.359375 | 3 | [] | no_license | class ThriftEnum
attr_reader :name, :members, :comment
def initialize(name:, members:)
@name = name
@members = members
end
def add_comment(comment)
@comment = comment
end
def to_s
enum_string = "enum #{name} {" + '\n'
@members.each do |m|
enum_string += " " + m.to_s + ","
e... | true |
39648e9e354ec1b653ed5a1d6080982dc871d4c3 | Ruby | m-onofri/intro-to-programming | /learn_to_program/chapter_12-8/ex_b.rb | UTF-8 | 1,648 | 4.125 | 4 | [] | no_license | # Write a program to read in names and birth dates from a text file.
# It should then ask you for a name.
# You type one in, and it tells you when that person’s next birthday will be
# (and, for the truly adventurous, how old they will be).
list = Dir["/Users/manuele/Documents/launch_school/learn_to_program/chapter... | true |
69dbffce5d03f1c6c17bed355c854bf784450fdf | Ruby | ntakahashi016/numberplacesolver | /src/HiddenSubsetsStrategy.rb | UTF-8 | 2,703 | 2.78125 | 3 | [] | no_license | # coding: utf-8
class HiddenSubsetsStrategy < Strategy
def initialize(n)
@n = n
end
def solve(board)
# Hidden pair 同じ領域で2種類の数字が配置できるマスが同じ2マスに限られる場合、その領域から他の候補を排除する
result = false
constraints = board.get_unsolved_constraints
constraints.select do |constraint|
cells = constraint.get_empty_... | true |
24f2294936f61375c626c4d24ee8f31a94fd40a4 | Ruby | e-fisher/vim-tracker | /tracker_cli/linux-x86_64/lib/app/lib/tracker/project.rb | UTF-8 | 741 | 2.671875 | 3 | [
"BSD-3-Clause"
] | permissive | require 'find'
module Tracker
class Project
attr_reader :file
def initialize(path)
@file = path
end
def name
File.basename(project_root) if project_root
end
def branch
return unless name
head = File.open("#{project_root}/.git/HEAD", "rb").read
head[/^ref:.*\/(.... | true |
e20ffe86d507ac528ac537fa800553aa38981429 | Ruby | mkyaw/ruby-basics | /perform_again.rb | UTF-8 | 132 | 3.5625 | 4 | [] | no_license | # perform_again.rb
# do/while loop
begin
print "Do you want to do that again? : "
answer = gets.chomp
end while answer == 'Y'
| true |
67f0819847961caca04bf4fe4c81b238ed3827d0 | Ruby | theoluyi/ruby-oo-relationships-practice-auto-shop-exercise-dumbo-web-010620 | /app/models/car.rb | UTF-8 | 638 | 3.359375 | 3 | [] | no_license | # join class
class Car
attr_reader :owner, :mechanic, :classification, :make, :model
@@all = []
def initialize(owner, mechanic, classification, make, model)
@owner = owner
@mechanic = mechanic
@classification = classification
@make = make
@model = model
@@all << self
end
def self... | true |
bc0ade2d80a298536764abf0bda15684477be489 | Ruby | twmills/date-casually | /test/test_calculator.rb | UTF-8 | 1,858 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'helper'
class TestCalculator < Test::Unit::TestCase
def test_last_week_range
sunday = Date.today.wday == 0 ? Date.today : parse('last Sunday')
sunday -= 7
saturday = sunday + 6
assert_equal sunday..saturday, DateCasually::Calculator.last_week_range
end
def test_last_sunday
sund... | true |
b3a6d96045744ea9e53ddc9c013d7e3e0bfe9df8 | Ruby | mattjang96/Chess | /Chess/slideable.rb | UTF-8 | 1,026 | 3.296875 | 3 | [] | no_license | module Slideable
HORIZONTAL_DIRS = [[-1,0], [0,-1], [0,1], [1,0]]
DIAGONAL_DIRS = [[-1,-1], [-1,1], [1,-1], [1,1]]
def horizontal_dirs
HORIZONTAL_DIRS
end
def diagonal_dirs
DIAGONAL_DIRS
end
def moves
possible = []
move_dirs.each do |dir|
poss... | true |
bebf668d65ff753a6eccc443df0363268ce37355 | Ruby | ipcrm/pem | /lib/pem/utils.rb | UTF-8 | 625 | 2.84375 | 3 | [] | no_license | module Pem
module Utils
require "#{File.dirname(__FILE__)}/utils/config"
require "#{File.dirname(__FILE__)}/utils/setup"
require "#{File.dirname(__FILE__)}/utils/modules"
require "#{File.dirname(__FILE__)}/utils/envs"
# Merge (recursive) two hashes
#
# Shameless robbed from SO
# http... | true |
5a38eb5010dfff95c5713ac4770cee0f6d7e9a27 | Ruby | John-Hayes-Reed/bottled_services | /spec/bottled_services_spec.rb | UTF-8 | 9,117 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe BottledService do
describe '::att' do
subject do
class FirstServiceObject
include BottledService
att :test_string, type: String, required: true
att :test_array, type: Array
def call
success
end
end
FirstServiceOb... | true |
81b976db54898fdc9e13eb5c87f8a71253c3fc02 | Ruby | ilona-st/capybara-rspec-example | /spec/archive/examples/fleet__check_car_with_special_price__spec.rb | UTF-8 | 1,790 | 2.546875 | 3 | [] | no_license | describe 'fleet', type: :feature do
context 'click on Viev Our Fleet button' do
it 'Fleet page is opened and it shows cars' do
visit('http://staging.realcar.nyc')
page.driver.browser.manage.window.resize_to(1500,1500)
click_on('view our fleet')
cars = page.all('a.booking__car.booking-c... | true |
8ddc8e9787691d90933c7b641d1f0e7439cedd94 | Ruby | alexm/refactoring-book | /ruby/page_033/rental.rb | UTF-8 | 310 | 2.921875 | 3 | [] | no_license | class Rental
attr_reader :movie, :days_rented
def initialize(movie, days_rented)
@movie, @days_rented = movie, days_rented
end
def charge
movie.charge(days_rented)
end
def frequent_renter_points
(movie.price_code == Movie::NEW_RELEASE && days_rented > 1) ? 2 : 1
end
end
| true |
578271c3e52ca71e6f4126d7f98111eaff8ecca7 | Ruby | nikodegtyaryov/binary-tree | /lib/binary_tree.rb | UTF-8 | 645 | 3.671875 | 4 | [] | no_license | class BinaryTree
attr_accessor :value, :right, :left
def initialize(value = nil)
@value = value
@right = nil
@left = nil
end
def insert(node)
return self.value = node.value if value.nil?
if node.value < value
self.left = BinaryTree.new if left.nil?
left.insert(node)
elsif ... | true |
ccbcce64ab55b6787f38e152759896744dd1d6b9 | Ruby | enjareyes/RubyPractice | /ruby-exercises/profile_class_part2.rb | UTF-8 | 2,610 | 4.0625 | 4 | [] | no_license | =begin
Write a new class called Kim that has 3 methods,
happy_birthday, change_job, and name_change. Initialize this
new class with an instance of class Profile and use your methods
that you created with attr_ to change the values of the instance variables.
Now, make a new class called Kim that initializes an inst... | true |
fadcc51864942dc22822585db0e2502173af3b7f | Ruby | sronga/kwk-t1-ttt-7-valid-move-teachers-l1 | /lib/valid_move.rb | UTF-8 | 471 | 3.265625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def position_taken?(board, index)
if board[index] == " "
false
elsif board[index] == ""
false
elsif board[index] == nil
false
elsif board[index] == "X"
true
elsif board[index] == "O"
true
end
end
def valid_move?(board, index)
if position_taken?(board, index) == tru... | true |
5c431250dc41ecc6e7f23bac819b02f04005a756 | Ruby | alexandre-petit-pas/exercices-ruby | /exo_12.rb | UTF-8 | 94 | 3.203125 | 3 | [] | no_license | puts "Donne moi un nombre"
nb = gets.chomp.to_i
i = 0
while i <= nb
puts i
i += 1
end
| true |
74e1e81d297063e52409e055169f01841666f1e1 | Ruby | catimm/quaff | /app/controllers/concerns/drink_descriptors.rb | UTF-8 | 1,651 | 2.59375 | 3 | [] | no_license | module DrinkDescriptors
extend ActiveSupport::Concern
def drink_descriptors(this_drink, how_many)
# create empty array to hold top descriptors list for beer being rated
@this_beer_descriptors = Array.new
# find all descriptors for this drink
@this_beer_all_descriptors = Beer.find_by_id(this_drink.i... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.