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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6a6b2c45395fb27e1a34e97e85199fec453b5112 | Ruby | fcce/router | /docker/text_replace.rb | UTF-8 | 2,055 | 2.90625 | 3 | [] | no_license | require 'yaml'
require 'erb'
require 'logger'
require 'fileutils'
@replace_mark = '-replace-'
@config_file_name = "replace_config.yml"
@log_name = "replace.log"
@path = ARGV[0]
@path ||= Dir.pwd
# Logger.new(STDOUT).info @path
@backup_path = "#{@path}/backup"
@config_file_path = "#{@path}/#{@config_file_name}"
@log_... | true |
7e4267b4ab82af85be480983ce27f97f9b833710 | Ruby | nicholasstano/ruby-objects-has-many-lab-nyc-web-062419 | /lib/artist.rb | UTF-8 | 773 | 3.484375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'pry'
class Artist
attr_accessor :name, :songs, :song
def initialize(name)
@name = name
@songs = []
end
def songs
Song.all.select do |song_instance|
song_instance.artist == self
end
end
def add_song(song)
@songs << song
song.artist = self
end
def add_song_by_name(song)
song = Son... | true |
a9d2fbf957e6ba39ae97a229837560aa97ac72af | Ruby | yozaru/macbookpro | /ruby-study/ruby_ex/ex514.rb | SHIFT_JIS | 192 | 2.84375 | 3 | [] | no_license | #! ruby -Ks
# -*- coding: Windows-31J -*-
require 'date'
puts Date.new( 2009,5,5 ).to_s
# ϐĂꍇ
hinamatsuri = Date.new( 2009,3,3 )
puts hinamatsuri.to_s
| true |
5a52811f2653cd02c0c0cde19a6d4fc88374b25e | Ruby | al-lo-co/ruby-exercises | /HackerRank/convert_temp.rb | UTF-8 | 1,043 | 3.359375 | 3 | [] | no_license | def convert_temp(temp, **scales)
val = temp.to_i
if scales[:output_scale]
case scales[:input_scale]
when "celsius"
case scales[:output_scale]
when "fahrenheit"
val = (val * 8/5) + 32
when "kelvin"
... | true |
2fc275f5a180310dc2ca26d6ee85a90cc848fc7f | Ruby | dreyks/cashtrails | /spec/models/record_spec.rb | UTF-8 | 845 | 2.625 | 3 | [] | no_license | require 'rails_helper'
describe Record do
describe 'custom setters' do
it 'set correct local and gmt date/time' do
record = Record.new(date: '22.10.2015 21:01'.in_time_zone('Europe/Kiev'))
expect(record.localDate).to eq 20151022
expect(record.localTime).to eq 210100
expect(record.gmtDate)... | true |
973d760961c6b8f65e132324046923e867479388 | Ruby | Axeia/aA-homeworks | /W2D4/chess/lib/pieces/slideable.rb | UTF-8 | 1,458 | 3.421875 | 3 | [] | no_license | module Slideable
def moves
possible_moves = []
move_dirs.each do |move_dir|
case move_dir
when :vertical
possible_moves += vertical_moves
when :horizontal
possible_moves += horizontal_moves
when :diagonal
... | true |
50d5530ee498c8cbabf593b8fa649cc7b1aded94 | Ruby | kinushu/minitest_to_rspec | /lib/minitest_to_rspec/input/subprocessors/base.rb | UTF-8 | 3,222 | 2.765625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'minitest_to_rspec/sexp_assertions'
module MinitestToRspec
module Input
module Subprocessors
# Parent class of "sub-processors". There is one sub-processor for each
# `sexp_type` that `Processor` knows how to process.
#
# For example, `Subprocessors:... | true |
ca700c5178df138d1171f717137319bcfb28f051 | Ruby | alexgont1/Ruby25 | /hash4.rb | UTF-8 | 371 | 3.78125 | 4 | [] | no_license | @hh = {}
def set_age name, age
puts 'Already exists!' if @hh[name]
@hh [name] = age
end
def show_hash
@hh.each_key do |key|
puts "Name is #{key} and age is #{@hh[key]}"
end
end
loop do
print 'Enter name or press [Enter] to exit: '
name = gets.strip.capitalize
if name == ''
break
end
print 'Enter age: '
... | true |
06a2dd3ae94b57e44bfd327de8e37d427f69ed47 | Ruby | ymm2110/pokemon-scraper-online-web-ft-112618 | /lib/pokemon.rb | UTF-8 | 819 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pokemon
attr_accessor :id, :name, :type, :db, :hp
@@all = []
def self.all
@@all
end
def initialize (id: nil, name: nil, type: nil, hp: 60, db: nil)#makes hp optional
@id = id
@name = name
@type = type
@db = db
@hp = hp
@@all << self
end
def self.save(name, type, db)
... | true |
19f7c4f9bfdfd00e3dad700e4957193dc42ca45e | Ruby | phoebehugh/battleships-web-test | /lib/board.rb | UTF-8 | 1,521 | 3.46875 | 3 | [] | no_license | class Board
attr_reader :grid
def initialize(content)
@grid = {}
[*"A".."J"].each do |l|
[*1..10].each {|n| @grid["#{l}#{n}".to_sym] = content.new}
end
end
def place(ship, coord, orientation = :horizontally)
coords = [coord]
ship.size.times{coords << next_coord(coords.last, orientati... | true |
b6ef9eced3c38ab69dc2f6aed13d6257a826bc55 | Ruby | EAGLE12/ruby_novice | /lib/koki/chap7.rb | UTF-8 | 553 | 4.21875 | 4 | [
"MIT"
] | permissive | # 第7章
def times_with_param
5.times do |i|
puts "#{i}回目の繰り返しです。"
end
end
def hello_with_name
def hello(name)
puts "Hello, #{name}."
end
hello("Ruby")
end
def hello_with_default
def hello(name="Ruby")
puts "Hello, #{name}."
end
hello() # 引数を省略して呼び出す
hello("Newbie") # 引数を指定して呼び出す... | true |
411dd5bb5fabbeb9f0bb38e83a22b20e0b75d936 | Ruby | papapabi/project-euler | /19.rb | UTF-8 | 874 | 3.75 | 4 | [] | no_license | require 'benchmark'
time = Benchmark.measure do
year = 1901
sundays = 0
cur_day = 6 # Every 7th day is a Sunday, start from the first sunday of the year 1900.
# Sun, January 6, 1901
first = true
while year <= 2000
(1..12).each do |i| # 1 for January, 2 for Feb, etc
days =
if ... | true |
a9932564da248982b3d81d1c71c4df120c88c9a1 | Ruby | robbi5/kleineanfragen | /test/extractors/brandenburg_pdf_extractor_test.rb | UTF-8 | 5,153 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class BrandenburgPDFExtractorTest < ActiveSupport::TestCase
# testcases:
PREFIX = 'Namens der Landesregierung beantwortet '
SUFFIX = ' die Kleine Anfrage wie folgt:'
test 'normal ministry' do
paper = Struct.new(:contents).new(
PREFIX + 'die Ministerin für Wissenschaft, Forschun... | true |
6c0de78552292faacea57263ca1d4de3e5d49017 | Ruby | Paxa/jruby_tests_java | /tests/first_spec.rb | UTF-8 | 1,244 | 2.765625 | 3 | [] | no_license | require 'java'
require "../jars/first.jar"
import org.beeing_tested.First;
java_import 'java.io.PrintStream'
java_import 'java.io.ByteArrayOutputStream'
java_import 'java.lang.System'
describe "First" do
before do
@first = First.new
end
def capture_stdout
sys_out_stream = System.out
my_output_... | true |
8494e5e4e3177c971a7e828ccfa90cf0fe36174e | Ruby | dianajohnson13/appacademy-prep | /w1/w1d5_bonus/largest_prime_factor.rb | UTF-8 | 286 | 3.6875 | 4 | [] | no_license | # The prime factors of 13195 are 5, 7, 13, and 29.
# What is the largest prime factor of the number 600851475143 ?
num = 600851475143
factor = 2
until factor == num
if num % factor == 0
num = num / factor
factor = 2
else
factor += 1
end
end
puts num
# Answer = 6857 | true |
ca5e1a3141ab7bce5e6abf27a554fc2ecf6998a2 | Ruby | aespidol/coding_dojo_0622 | /Ruby Exercises/tdd/string/string_spec.rb | UTF-8 | 376 | 3.265625 | 3 | [] | no_license | require_relative "string"
describe String do
it "has a my_reverse! method that alters the receiver" do
string = "hello"
expect(string.my_reverse!).to eq("olleh")
expect(string).to eq("olleh")
end
it "has a my_reverse method that returns new String reversed" do
string = "hello"
expect(string.my_reverse)... | true |
c47c3cefe44b8e5f8528fad8a412997fb185ad7d | Ruby | haleylikesrocks/RB101-programming-foundations | /lesson_4/practice_problems.rb | UTF-8 | 1,686 | 3.9375 | 4 | [] | no_license | # Problem 1 #
flintstones = ["Fred", "Barney", "Wilma", "Betty", "Pebbles", "BamBam"]
flint_hash = {}
flintstones.each_with_index{ |name, index| flint_hash[name] = index }
puts flint_hash
# Problem 2 #
ages = { "Herman" => 32, "Lily" => 30, "Grandpa" => 5843, "Eddie" => 10, "Marilyn" => 22, "Spot" => 237 }
sum_of_... | true |
54d22873d8c73f9e0a12bb9c7b9204ac5dedf6d3 | Ruby | Ssenkowski/ruby-objects-has-many-through-lab-v-000 | /lib/artist.rb | UTF-8 | 235 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Artist
attr_accessor :name, :songs, :genres
def initialize(name)
@name = name
@songs = []
end
def add_song(song)
@songs << song
song.artist = self
end
def genres
self.songs.map do |song|
song.genre
end
end
end
| true |
62675bd08f518eb22cbd0708e8fc3dc2c39be577 | Ruby | sofiegraham/odin | /ruby/project_advanced_ruby/bubble_sort.rb | UTF-8 | 736 | 3.953125 | 4 | [] | no_license | def bubble_sort list
list.length.times do
list.each_with_index do |item, index|
if index == list.length-1
break
elsif item > list[index+1]
list[index], list[index+1] = list[index+1], list[index]
end
end
end
return list
end
puts bubble_sort([3,9,4,2,7,4,0,2])
def bubble_sort_by list
list.leng... | true |
2eaa59d9164529cc99a694334f7962a87c0aca2a | Ruby | dischglv/thinknetica-training-assignment | /quadratic_equation.rb | UTF-8 | 656 | 3.546875 | 4 | [] | no_license | def show_D_and_roots(a, b, c)
roots = []
d = b ** 2 - 4 * a * c
puts "Дискриминант: #{d}"
if d > 0
roots << (-b + Math.sqrt(d)) / (2 * a)
roots << (-b - Math.sqrt(d)) / (2 * a)
elsif d == 0
roots << (-b) / (2 * a)
end
puts "Корней нет" if roots.empty?
roots.each do |root... | true |
5e8ea008d0223ddbbf09c03c6a26e6bcb8b03c49 | Ruby | twill14/lauchschool-challenges | /easy_level_one/odd_words.rb | UTF-8 | 369 | 4.03125 | 4 | [] | no_license | # - Access odd and even words by index
# - Even words read as orignal
# - Odd words are to be reversed
def oddword(string)
array = []
string.scan(/\b[\w']+\b/).each_with_index do |ele, inx|
if inx % 2 != 0
array << ele.reverse
else
array << ele
end
end
... | true |
344919f3d71b39da06879a91362dfbab0bedcf7c | Ruby | fgobbo/ruby-music-library-cli-cb-gh-000 | /lib/artist.rb | UTF-8 | 651 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative './concerns/findable.rb'
class Artist
attr_accessor :name, :songs
extend Concerns::Findable
@@all = []
def initialize(name)
@name = name
@songs = []
end
def self.all
@@all.dup.freeze
end
def save
@genres = []
@@all << self
end
def self.create(name)
new(n... | true |
3ca71c33a7981fd0d591dafc4e8b864f79038029 | Ruby | joshbreault/hw | /wowgame.rb | UTF-8 | 1,739 | 3.78125 | 4 | [] | no_license |
def say(name, statement)
puts(name.nil? ? statement : "#{name.capitalize}: #{statement}")
end
def ask_question(question, options)
say nil, "*" * 50
say nil, question
say nil, "Options: #{options}"
gets.chomp.downcase
end
def handleSidekick(sidekick)
if sidekick == "robin"
say "Robin", "Hol... | true |
fb11d579f723c66e00e44f4a2cb48e4f2d8c82a4 | Ruby | OMGDuke/airport_challenge | /lib/weather.rb | UTF-8 | 254 | 2.703125 | 3 | [] | no_license | require_relative 'plane'
class Weather
def weather_calc(plane)
if rand(20) > 17
fail "Planes cannot take off due to stormy weather" if plane.ground
fail "Planes cannot land due to stormy weather" unless plane.ground
end
end
end
| true |
f45b400cba037dd90bf4c7c01f9e4ee0821dd3b8 | Ruby | maiha/xxx | /spec/provide_helper.rb | UTF-8 | 3,261 | 2.859375 | 3 | [
"MIT"
] | permissive | ######################################################################
### provide matcher
Spec::Matchers.define :provide do |expected|
match do |obj|
!!(obj.method(expected) rescue false)
end
end
module Spec
module Example
module Subject
module ExampleGroupMethods
# == Usage
# d... | true |
7fb84fc31a9c99ca001e7414f8b6d8c89cc5a97f | Ruby | annafractuous/badges-and-schedules-001-prework-web | /conference_badges.rb | UTF-8 | 684 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
"Hello, my name is #{name}."
end
speakers = ["Edsger","Ada","Charles","Alan","Grace","Linus","Matz"]
def batch_badge_creator(speakers)
badge_messages = []
speakers.each do |name|
badge_messages.push(badge_maker(name))
end
badge_messages
end
def assign_rooms(speakers)
room_assig... | true |
0751be05eeaf04645ad340d9db0ee3f45cc54e90 | Ruby | alexpech12/advent-of-code-2020 | /5/part_2.rb | UTF-8 | 820 | 3.90625 | 4 | [] | no_license | require_relative '../read_file.rb'
require_relative 'boarding_pass.rb'
boarding_passes = read_file('input.txt') do |line|
BoardingPass.new(line.chomp)
end
# For this part, we need to find the missing seat number.
# Let's sort by seat number, then do a search to find the gap.
#
# Note on the use of each_cons:
# ea... | true |
79bad64ad1269576346d9091d9b8b8e6227c8b27 | Ruby | monicagonsalves/bonbons | /app/controllers/stacks_controller.rb | UTF-8 | 2,300 | 2.5625 | 3 | [
"MIT"
] | permissive | class StacksController < ApplicationController
include Stackable
before_action :authenticate_user!
def index
@stacks = auto_generated_stacks
make_study_paths
end
def find
@stacks = auto_generated_stacks
unless params[:filter_rules].nil?
unless (params[:filter_rules] & ["1","2", "3"]).empty?
... | true |
67dbc756d0b8017be0017c49150721987e8c671a | Ruby | ykessler/snappconfig | /lib/snappconfig.rb | UTF-8 | 1,017 | 2.515625 | 3 | [
"MIT"
] | permissive | require "snappconfig/railtie"
module Snappconfig
extend self
def config_files
@config_files ||= Dir.entries(Rails.root.join("config").to_s).grep(/(^application)(\.|\..*\.)(yml$)/).sort { |x,y| x.chomp(".yml") <=> y.chomp(".yml") }
end
def merged_raw
if @merged_raw
return @merged_raw
el... | true |
a792ce8ca4a8c482d3ef8ebb625b940773b81ca7 | Ruby | gregpalmier/pastebin | /lib/pastebin/pastebin.rb | UTF-8 | 790 | 2.734375 | 3 | [
"MIT"
] | permissive | require "httparty"
module Pastebin
class API
attr_reader :scrape_url
attr_reader :item_url
attr_reader :post_url
def initialize(limit = 100) # max 250, recommended 100
api_dev_key = ENV['PASTEBIN_API_KEY']
@scrape_url = "https://scrape.pastebin.com/api_scraping.php?api_dev_key=#{api_dev_k... | true |
85c94443e4246ac736bd2a82be6c87c9c905e478 | Ruby | ElizabethKaren/ruby-enumerables-hash-practice-emoticon-translator-lab-nyc-web-033020 | /lib/translator.rb | UTF-8 | 877 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "yaml"
require "pry"
def load_library(file_path)
library = YAML.load_file(file_path)
result = {
:get_meaning => { },
:get_emoticon => { }
}
library.each do | key, value |
result[:get_meaning][value[1]] = key
result[:get_emoticon][value[0]] = value[1]
end
#binding.pry
result
end
... | true |
cd11abcd302340585ad28f8625bddcabb41ad266 | Ruby | Antidale/rails_active_record_assignments | /assignment_2/todolists/app/models/profile.rb | UTF-8 | 701 | 2.640625 | 3 | [
"MIT"
] | permissive | class Profile < ActiveRecord::Base
belongs_to :user
validate :has_at_least_first_or_last_name?
validate :no_men_named_sue
validates :gender, inclusion: { in: %w(male female)}
def has_at_least_first_or_last_name?
unless (first_name.present? || last_name.present?)
errors.add(:first_name, "Both first... | true |
bfb7e73e0a36e2c059976c3bfcc3b12da9207aee | Ruby | taw/rosalind | /bioinformatics_armory/lcsm.rb | UTF-8 | 406 | 2.953125 | 3 | [] | no_license | #!/usr/bin/env ruby
require "./fasta"
require "set"
class String
def substrings(i)
Set[*(0..size-i).map{|j|
self[j,i]
}]
end
end
def find_lcms(data,i)
data.map{|gene| gene.substrings(i)}.inject(&:&)
end
data = FASTA.read_genes
max_possible_size = data.map(&:size).min
(1..max_possible_size).eac... | true |
068e60930f83cf0fbe39f38d5d5101862716d928 | Ruby | virtualforce-nabeelnizami/nanny_app | /app/helpers/application_helper.rb | UTF-8 | 1,662 | 2.53125 | 3 | [] | no_license | module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
def logged_in?
end
# display a message using the JQuery Toast Message plugin
# types available: noti... | true |
bcf0328f088193ec3f449dce822ffac5bea2d1c9 | Ruby | shah743/imdb | /spec/imdb/search_spec.rb | UTF-8 | 1,086 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe 'Imdb::Search with multiple search results' do
before(:each) do
@search = Imdb::Search.new('Star Trek: TOS')
end
it 'should remember the query' do
@search.query.should == 'Star Trek: TOS'
end
it 'should find 14 results' do
@search.movies.size.should eql(14)
end
... | true |
1055444bc5216b47e2dd2c35499dde918b8904eb | Ruby | rn0rno/kyopro | /aoj/ruby/01_ITP/ITP1_3_D.rb | UTF-8 | 107 | 3.0625 | 3 | [] | no_license | a, b, c = gets.chomp.split.map(&:to_i)
cnt = 0
a.upto(b) do |i|
cnt += 1 if (c % i).zero?
end
puts cnt
| true |
52ef14269f11bd9b647c187747a5788f10c54eae | Ruby | fmlharrison/learn_to_program | /ch12-new-classes-of-objects/happy_birthday.rb | UTF-8 | 366 | 3.734375 | 4 | [] | no_license | puts "What year were you born?"
year = gets.chomp
puts "What month were you born in? Please use a number"
month = gets.chomp
puts "What day were you born? Please use a number"
day = gets.chomp
age = Time.new - Time.mktime(year.to_i, month.to_i, day.to_i)
birthdays = ((((age.to_i / 60)/ 60)/ 24)/ 365)
birthdays.to_i.t... | true |
48eaef0268152001711c1a13b492188a93748e77 | Ruby | Anguyen89/RecordRunner | /lib/03_associatable.rb | UTF-8 | 1,852 | 2.640625 | 3 | [] | no_license | require_relative '02_searchable'
require 'active_support/inflector'
class AssocOptions
attr_accessor(
:foreign_key,
:class_name,
:primary_key
)
def model_class
class_name.constantize
end
def table_name
class_name.underscore + "s"
end
end
class BelongsToOptions < AssocOptions
def in... | true |
486d8f854ac886d48a696924b300fd6643ac63a5 | Ruby | VladC24/Oystercard | /lib/oystercard.rb | UTF-8 | 734 | 3.578125 | 4 | [] | no_license | class Oystercard
attr_reader :balance, :station, :start_station
MAXIMUM_LIMIT = 90
MINIMUM_LIMIT = 1
FARE = 3
def initialize
@balance = 0
@start_station = nil
end
def top_up(amount)
raise "Exceeded maximum balance!" if limit_exceeded?(amount)
@balance += amount
end
def touch_in(st... | true |
466b54e16e2eaf98df3a1ecebb87a43d6f3ff974 | Ruby | kelvinjhwong/ruby-exercises | /ruby-small-problems/10_medium_1/10_04.rb | UTF-8 | 1,008 | 3.53125 | 4 | [] | no_license | def lights_on(n)
lights = {}
1.upto(n) { |i| lights[i] = false }
1.upto(n) { |i| i.step(n, i) { |j| lights[j] = !lights[j] } }
lights.keys.select { |idx| lights[idx] }
end
def lights_on(n)
lights = [false]*n
1.upto(n) { |i| i.step(n, i) { |j| lights[j] = !lights[j] } }
lights.each_with_index.with_object(... | true |
048101e73be88c018c7352fb21b1b1ad640c839c | Ruby | jgodoyco/Ironhack | /Curso/Module1/chessValidator/chessValidator.rb | UTF-8 | 8,085 | 3.71875 | 4 | [] | no_license | class ChessBoard
attr_accessor :ChessBoard
# Build and empty Board
def initialize
lineArray = [nil,nil,nil,nil,nil,nil,nil,nil]
columnArray = lineArray.clone
@chessBoard = columnArray
ind = 0
@chessBoard.each do |line|
@chessBoard[ind] = lineArray.clone
ind += 1
end
end
# Place the initial lin... | true |
3f36338c522b7a7abb8dced32ed117244384f791 | Ruby | GautierBlondel/caesar_cipher | /lib/01_multiples_sum.rb | UTF-8 | 418 | 3.609375 | 4 | [] | no_license |
final_number = 0
iterator = 0
def is_multiple_of_3_or_5?(current_number)
case current_number%5 == 0 || current_number%3 == 0
when true
true
when false
false
end
end
def sum_of_3_or_5_multiples?(final_number, iterator)
iterator.times do |i|
is_multiple_of_3_or_5?(i) ? final_number = final_numb... | true |
e44b60a33471d210bfa8b2835960645e4b682963 | Ruby | anandgraves/food-ingredient-parser-ruby | /lib/food_ingredient_parser/cleaner.rb | UTF-8 | 691 | 2.75 | 3 | [
"MIT"
] | permissive | module FoodIngredientParser
module Cleaner
def self.clean(s)
s.gsub!(/(_x005f_|_)x000d_/i, "\n") # fix sometimes encoding for newline
s.gsub!("\u00ad", "") # strip soft hyphen
s.gsub!("\u0092", "'") # windows-1252 apostrophe - https://stackoverflow.com/a/15564279/2866... | true |
78e9d80451f0ff0445305a4f52e02cc0e10ff82c | Ruby | cider-load-test/clieop | /lib/clieop/payment/batch.rb | UTF-8 | 5,862 | 2.6875 | 3 | [
"MIT"
] | permissive | module Clieop
module Payment
class Batch
attr_accessor :transactions, :batch_info
def initialize(batch_info)
raise "Required: :description, :account_nr, :account_owner" unless ([:account_nr, :account_owner] - batch_info.keys).empty?
@transactions = []
@batch_info = batch_inf... | true |
1df0c525cb27ca096cd5ceec56973e5dd4195ddc | Ruby | kungfoo/ruby_lecture | /lecture samples/jukebox/song.rb | UTF-8 | 652 | 3.328125 | 3 | [] | no_license | class Song
attr_reader :title, :artist
def initialize(hash)
@artist = hash["artist"]
@title = hash["title"]
@seconds = hash["length"]
end
def Song.from_attributes(artist, title, seconds)
Song.new({"artist" => artist, "title" => title, "length" => seconds})
end
def minutes
@secon... | true |
e3831a785565df99353ce2ec1602f53c325e5279 | Ruby | runpaint/numb | /lib/numb/lucas2.rb | UTF-8 | 232 | 2.875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # coding: utf-8
class Integer
def lucas2(p, q)
d = (p**2) - (4*q)
raise ArgumentError unless d > 0
d_root = d.sqrt
(Rational(p + d_root, 2)**self + Rational(p - d_root, 2)**self).round
end
memoize :lucas2
end
| true |
eb33ab6c65f0d9532d5325cca8ca6b64a28f4cee | Ruby | hatwell/wk2_day2_lab_homework | /specs/bus_spec.rb | UTF-8 | 964 | 3.03125 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../bus')
require_relative('../person')
class BusTest < MiniTest::Test
def setup
@caroline = Person.new("Caroline Hatwell", 31)
@james = Person.new("James", 25)
@bus_22 = Bus.new(22, "Ocean Terminal")
#@bus_23 = Bus.new(23, "Leith L... | true |
677bc4da4b97c039a04fa0ee330a83ea67d5b408 | Ruby | juggernault/rubyCapybaraProject | /features/step_definitions/predictions_tutorial/predictions_tutorial_verifications_steps.rb | UTF-8 | 2,075 | 2.640625 | 3 | [
"MIT"
] | permissive | require './pages/predictions_tutorial'
Then(/^I will see the pop up Create your own league and the text$/) do
@predictions_tutorial = PredictionsTutorial.new
@predictions_tutorial.page_should_have_content_create_your_own_league
logger.debug "Create your own league modal has been showned to the user"
end
Then... | true |
f435bb25df99005cc8a77e76e7e094c57fa9fca9 | Ruby | sirlolz/advanced-hashes-hashketball-seattle-web-080519 | /hashketball.rb | UTF-8 | 6,338 | 3.078125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
def game_hash
hasketball = {
:home => {
:team_name => "Brooklyn Nets",
:colors => ["Black", "White"],
:players => [
{ :player_name => "Alan Anderson",
:number => 0,
:shoe => 16,
:points => 22,
:rebounds => 12,
:assists => 12,
:steals => ... | true |
3ec03d46b97fa298f9e85d3dbfbd6dd06cfe505c | Ruby | chunyue/ecommerce | /app/models/cart.rb | UTF-8 | 1,136 | 2.796875 | 3 | [] | no_license | class Cart < ApplicationRecord
has_many :cart_items, dependent: :destroy
has_many :products, through: :cart_items
def add_cart_item(product)
existing_item = self.cart_items.find_by( product_id: product)
if existing_item
existing_item.quantity += 1
existing_item.save!
else
cart_item ... | true |
3806bfd2e1a14166c9adce9ae8b2f1cd498b920c | Ruby | pavanetti/concurrent-programming-assignments | /radial_distance/ruby/polar_point.rb | UTF-8 | 767 | 3.1875 | 3 | [] | no_license | class PolarPoint
attr_reader :magnitude, :direction
def initialize(magnitude, direction)
@magnitude = magnitude
@direction = direction
end
include Math
def distance(target)
return sqrt(
(magnitude ** 2) + (target.magnitude ** 2) -
2 * (magnitude * target.magnitude * cos(direction - ta... | true |
7bf936fa3f2f276a5f3aebcd79e179fa494a06f2 | Ruby | theworkinggroup/ec2x-agent | /lib/ec2x/command_delegator.rb | UTF-8 | 1,011 | 2.59375 | 3 | [] | no_license | class Ec2x::CommandDelegator
# == Constants ============================================================
# == Class Methods ========================================================
# == Instance Methods =====================================================
def initialize(config)
@config = config
... | true |
314cbc8cc033395dce609d15ed1b3e01a183d284 | Ruby | yuki-snow1823/Project_Euler | /problem52.rb | UTF-8 | 685 | 3.59375 | 4 | [] | no_license | # 125874を2倍すると251748となる.
# これは元の数125874と順番は違うが同じ数を含む.
# 2x, 3x, 4x, 5x, 6x が x と同じ数を含むような最小の正整数 x を求めよ.
def number_split_check(num)
split_numbers = num.to_s.split("").sort
return num if split_numbers == (2 * num).to_s.split("").sort &&
split_numbers == (3 * num).to_s.split("").sort &&
split... | true |
8040ab0b6fdb71fa8fa21827f76ac5317b9813a0 | Ruby | sebapobletec/E9CP2A1 | /Ejercicio2.rb | UTF-8 | 1,444 | 3.96875 | 4 | [] | no_license | #Methods and class
class Course
attr_accessor :name, :beginning, :ending
def initialize(name, beginning, ending)
@name = name
@beginning = Date.parse(beginning)
@ending = Date.parse(ending)
end
end
def readandcreate
file = File.open('courses.txt', 'r')
data = file.readlines
file.close
@cours... | true |
ae6f716eb4e626372c75db302184d6b8d840b21c | Ruby | ramonjtorres/Universidad | /PDOO-Civitas/CivitasR/pkg/CivitasR-0.0.1/lib/tablero.rb | UTF-8 | 6,030 | 2.875 | 3 | [] | no_license | #encoding: utf-8
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
#require_relative "Casilla"
#require_relative "Mazo_Sorpresas"
#require_relative "Tipo_Sorpresas"
#require_relative "Sorpresa"... | true |
4320110ce6a4228208e3104dfc883e726ac053be | Ruby | santaclauslives/ruby-toy__find-only-unique-elements | /lib/unique_elements.rb | UTF-8 | 342 | 3.375 | 3 | [] | no_license | # This method takes an array of elements (these might be strings, integers, floats, or a
# combination of the above), and returns an array of the elements that appear once and only
# once.
def find_unique_elements(arr)
elements = Hash.new(0)
arr.each{ |e| elements[e] +=1 }
elements.select { |key,value| ... | true |
c5b7b92e49fdc0326f7f99794b006afe0e951492 | Ruby | tacodtripe/ruby-math-linter | /lib/symbols.rb | UTF-8 | 1,572 | 3.140625 | 3 | [] | no_license | require 'strscan'
require 'colorize'
class Symbols
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def self.missing_symbol(string, line) # rubocop:disable Metrics/MethodLength
arr = string.chars
opening = 0
ending = 0
arr.each_with_index do |n, _i|
... | true |
b0c54f74d4182dfe250b0225a0c92ec94502c065 | Ruby | danielribeiro/rubytricks | /biten_by_closures.rb | UTF-8 | 313 | 3.703125 | 4 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Joshua and Neal Gafter block told us about it
class A
end
ar = ['a', 'div', 'lu']
#for name in ar
# A.send(:define_method, name) { name }
#end
#p A.new.a # yes, it is lu
# but
ar.each do |name|
A.send(:define_method, name) { name }
end
p A.new.a # yes, it is a!
p A.new.div # yes, it is ... | true |
d34183e1bb8f49a23dfc605034da3d52901fc222 | Ruby | Archeia/backtrace | /lib/backtrace.rb | UTF-8 | 9,614 | 2.546875 | 3 | [
"MIT"
] | permissive | #--
# Backtrace v1.3 by Solistra
# =============================================================================
#
# Summary
# -----------------------------------------------------------------------------
# This script provides the missing full error backtrace for RGSS3 as well as
# a number of features related to e... | true |
aa74857f2890866ae2f3c9be8343a5b76ef60e73 | Ruby | Macro80-20/my-each-london-web-career-021819 | /my_each.rb | UTF-8 | 273 | 3.4375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | collection = [1,2,3,4]
def my_each(collection)
if block_given?
counter = 0
while counter<collection.length
yield collection[counter]
counter+=1
end # put argument(s) here
collection
else
return
end
end
my_each(collection) do
|element| puts element end
| true |
fae1d3464ca4c81bfcd7100ec220dd1d52297e6f | Ruby | phaedryx/arrangement | /lib/arrangement/schema.rb | UTF-8 | 2,329 | 2.90625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Arrangement
##
# The Arrangement::Schema class is a specialized Hash. The difference is that it returns the call
# value of a value if a value is callable.
class Schema < Hash
##
# This returns the value of a call if it is callable, otherwise the value. This is the ... | true |
480ee1cdc674c97766dbeecbc008cf7ab8ba1f9b | Ruby | collinksmith/ruby-projects | /minesweeper/tile.rb | UTF-8 | 1,619 | 3.578125 | 4 | [] | no_license | require 'colorize'
require 'gemoji'
class Tile
attr_accessor :status ,:bomb
attr_reader :pos, :board
NEIGHBOR_POSITIONS = [[-1,-1], [-1, 0], [-1, 1], [0, 1],
[1, 1], [1, 0], [1, -1], [0, -1]]
def initialize(board, bomb, pos)
@board = board
@bomb = bomb
@status = :hidden
... | true |
f7aacf4a7cafa7efa3690ba1881188705da2a46d | Ruby | ml-snow/exchanger | /lib/exchanger/operations/get_attachment.rb | UTF-8 | 1,399 | 2.515625 | 3 | [
"MIT"
] | permissive | module Exchanger
# The GetAttachment element is the root element in a request to get an attachment from the Exchange store.
#
# https://msdn.microsoft.com/en-us/library/office/aa564204(v=exchg.150).aspx
class GetAttachment < Operation
class Request < Operation::Request
attr_accessor :attachment_ids, :... | true |
c747707f3c5ac3568430d31eaf3a64b8b42e4ca5 | Ruby | Lisa-Sano/FarMar | /lib/product.rb | UTF-8 | 865 | 2.765625 | 3 | [] | no_license | class FarMar::Product
attr_reader :id, :name, :vendor_id
# module mixin
extend FarMar::FarMarMethods
def initialize(info_hash)
@id = info_hash[:id].to_i
@name = info_hash[:name]
@vendor_id = info_hash[:vendor_id].to_i
end
def self.all(file = './support/products.csv')
product_keys = [:id, ... | true |
264a203a16652b71f83a11430dbd8970b9e639e9 | Ruby | charlietag/ruby-script | /ruby_parse_nokogiri.rb | UTF-8 | 656 | 2.90625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open("http://url.here")) do |c|
c.strict.nonet.noblanks
end
now_time = Time.now
target = Hash.new()
#Sample, using css selection
content = page.css('.text-2')
content.each do |c|
#CSS selector sample => target[:id] = c.css('a[href^=... | true |
9b9c72832e35e6d42f59acfff93498d60eb30761 | Ruby | timwut/tim_ruby | /5_loops/until_loop.rb | UTF-8 | 122 | 3.546875 | 4 | [] | no_license | #until_loop.rb
x = gets.chomp.to_i
until x < 0
puts x
x -= 1 #Reminder, it both minuses and prints
end
puts "Done!"
| true |
637e9d73d61ddf3bba011951ea5ba53d25737ddb | Ruby | fleeree2013/ruby-challenges | /always3again.rb | UTF-8 | 204 | 3.453125 | 3 | [] | no_license | def always_3
puts "Can I get a number please?"
number_1 = gets.chomp.to_i
number_2 = ((((number_1 + 5) * 2) -4) / 2)
number_3 = number_2 - number_1
puts "Your new number is #{number_3}"
end
always_3 | true |
589f74a2cd73c1ca2fb9cb0876c8680e68460448 | Ruby | techtronics/actionite | /lib/cropper.rb | UTF-8 | 1,110 | 2.84375 | 3 | [
"MIT"
] | permissive | # Image cropper - used on images when posting and updating campaigns and donations
require "open-uri"
require "RMagick"
require "logger"
class Cropped_image
def initialize(params, image_path)
@x = params['image_x'].to_f
@y = params['image_y'].to_f
@width = params['image_width'].to_f
@height = params... | true |
c985a461f512a02fcf2e2ff616f5a0262caff265 | Ruby | Maihj/anomaly_detection | /data/cal.rb | UTF-8 | 1,990 | 2.90625 | 3 | [] | no_license | u0 = [[32,18],[43,7],[32,18],[41,9],[47,3],[48,2],[50,0],[49,1],[32,18],[43,7],[31,19],[41,9],[47,3],[49,1],[50,0],[48,2],[37,13],[43,7],[32,18],[41,9],[49,1],[50,0],[50,0],[49,1],[38,12],[43,7],[33,17],[41,9],[47,3],[49,1],[50,0],[48,2]]
zz0 = Array.new(8, 0.0)
zf0 = Array.new(8, 0.0)
fz0 = Array.new(8, 0.0)
ff0 = Ar... | true |
429128010291bf3bc2b2411dc55db7e421762279 | Ruby | ollieh-m/ruby-exercises | /clock.rb | UTF-8 | 188 | 3.09375 | 3 | [] | no_license | def clock &hourly_gong
currentHour = Time.now.hour
if currentHour > 12
currentHour = currentHour - 12
end
currentHour.times do
hourly_gong.call
end
end
clock do
puts 'GONG!'
end | true |
a34ae789e3cea172c55108a919c8df4c623fd0bc | Ruby | ccaldarella99/odinproject | /_web101/learn_ruby/03_simon_says/simon_says.rb | UTF-8 | 654 | 3.84375 | 4 | [] | no_license | #write your code here
def echo(words)
words
end
def shout(words)
words.upcase
end
def repeat(words, *args)
allwords = words
if (args.length < 1)
allwords = allwords + " " + words
else
for i in 2..args[0]
allwords = allwords + " " + words
end
end
allwords
# puts allwords
end
def start... | true |
4e1eb3f4a2fa1a2d64410cc39348f1f747908d81 | Ruby | lekan20/school-domain-v-000 | /lib/school.rb | UTF-8 | 1,096 | 4.15625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class School
def initialize(school_name) #allows you to add the school name after creating the class
@school_name = school_name
@roster = {}
end
def roster #method for empty roster we'll fill with students
@roster
end
def add_student(student, grade)
@roster[grade] ||= []
... | true |
a6e3f5a85afd825ae5c97925e713797ee3974972 | Ruby | ArayB/exercism-solutions | /ruby/pangram/pangram.rb | UTF-8 | 230 | 2.9375 | 3 | [] | no_license | class Pangram
ENGLISH_ALPHABET = ('a'..'z').freeze
def self.pangram?(sentence)
sentence = sentence.downcase
ENGLISH_ALPHABET.all? { |letter| sentence.include?(letter) }
end
end
module BookKeeping
VERSION = 3
end
| true |
7b50f58d7e4ab1d0003cf4ef1597a9031801b6f6 | Ruby | martom87/ror_and_ruby_exercises | /ruby_excercises/parser_task/paresr2.rb | UTF-8 | 13,790 | 2.8125 | 3 | [] | no_license | class Parser
def initialize (input)
@input = input
end
def all_views
array = @input.split(' ')
urls = Hash[array.each_slice(2).to_a]
urls_array = []
urls.each do |key, value|
urls_array << key
value
end
pairs = array.each_slice(2).to_a
# unique_pairs = pairs.uniq
... | true |
7fd1f8c201c1efa2d21c43272884e002a4db3393 | Ruby | ErikPeterson/deeponion | /spec/models/tor_scraper_spec.rb | UTF-8 | 1,629 | 2.71875 | 3 | [] | no_license | require_relative '../spec_helper.rb'
describe TorScraper do
describe "#new" do
it "takes a URL string as its single argument" do
expect(TorScraper.new("http://www.google.com").uri).to be_a(URI::Generic)
end
it "rejects urls without a hostname" do
expect{TorScraper.new("/some/path/to/a/file")... | true |
575c9ac2c304f3121dd52bda258d4dd44f79762f | Ruby | pricees/algoruby | /test/searching_test.rb | UTF-8 | 2,161 | 2.78125 | 3 | [
"MIT"
] | permissive | require File.join('.', File.dirname(__FILE__), 'test_helper')
#
# The following is for the binary tree functions
#
class SearchingTest
describe Algoruby::Search do
before do
@max = 99
@ary = begin
s = Set.new
s << rand(@max) until s.length == @max
s.to_a
end
end... | true |
1772076e3315f2f739f0a5c99f8415a5ddd6c9cf | Ruby | EpicDream/shopelia | /lib/prixing/ressource.rb | UTF-8 | 1,885 | 2.5625 | 3 | [] | no_license | module Prixing
class Ressource
protected
def self.post_request(route, data)
request('POST', route, data)
end
def self.get_request(route, options=nil)
request('GET', route, nil, options)
end
def self.put_request(route, data)
request('PUT', route, data)
end
def self... | true |
510ee14067063fcd800849301ce9243c068d253e | Ruby | declarativitydotnet/declarativity | /bud/test/tc_vars.rb | UTF-8 | 807 | 2.859375 | 3 | [] | no_license | # variable design still rather tentative
require 'rubygems'
require 'bud'
require 'test/unit'
class VarBud < Bud
def state
var :x
tmpvar :y
table :tbl, ['k1', 'k2'], ['v1', 'v2']
end
declare
def program
self.x = 4
self.y = 5
end
end
class VarBudDup < Bud
def state
var :x
tm... | true |
d9c8bc8c5aacba27599f914d6cdf25437947eb7d | Ruby | handofthecode/ruby-sinatra | /ruby_foundations/weekly_challenges/roman_numerals.rb | UTF-8 | 774 | 3.578125 | 4 | [] | no_license | class Fixnum
def to_roman
result = []
self.to_s.reverse.chars.each_with_index do |int, pow|
actual = int.to_i * 10**pow
result << case actual
when 1, 2, 3
'I' * actual
when 4
'IV'
when 5, 6, 7, 8
'I' 'V' + 'I' * (actual - 5)
when 9
'IX'
... | true |
731555fb4efb2af9c43cb6ad87e37d13e7b3b5d5 | Ruby | niv/arpie | /lib/arpie/binary/list_type.rb | UTF-8 | 2,880 | 2.796875 | 3 | [
"BSD-2-Clause"
] | permissive | module Arpie
class ListBinaryType < BinaryType
def binary_size opts
if opts[:sizeof]
len_handler = Binary.get_type_handler(opts[:sizeof])
len_handler.binary_size(opts[:sizeof_opts])
elsif opts[:length]
case opts[:length]
when Symbol
opts[:object] ? opts[:... | true |
6640de1cb70f13b64a40f9acd0c8382806ecd15f | Ruby | ToniRib/headcount | /lib/enrollment_repository.rb | UTF-8 | 707 | 3.0625 | 3 | [] | no_license | require_relative 'enrollment'
require_relative 'post_processor'
class EnrollmentRepository
attr_reader :enrollments
def initialize
@enrollments = {}
end
def load_data(options)
post = PostProcessor.new
data = post.get_enrollment_data(options)
data.each_pair do |district_name, district_data|
... | true |
d737731e998d2b1ff25caec4ea58399f50b567c2 | Ruby | mcelis13/nyc-pigeon-organizer-dumbo-web-080618 | /nyc_pigeon_organizer.rb | UTF-8 | 1,115 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def nyc_pigeon_organizer(data)
pigeon_list = {}
data[:gender][:male].concat(data[:gender][:female]).each do |birdName|
if pigeon_list.has_key?("#{birdName}") == false
pigeon_list[birdName] = {:color => [], :gender => [], :lives => []}
if birdName != "Queenie" && birdName != "Ms. K"
... | true |
41e8d7c670534bd72c3dae074e6d6d17ac4ab114 | Ruby | comics-apps/marvel-api | /lib/marvel/api/api_methods.rb | UTF-8 | 1,111 | 2.734375 | 3 | [
"MIT"
] | permissive | module Marvel
class Api
module ApiMethods
METHODS = {
characters: :character,
comics: :comic,
creators: :creator,
events: :event,
series: :serie,
stories: :story
}.freeze
SUBMETHODS = {
characters: %i[comics events series stories],
... | true |
ed37fa841224c7d00ef6ee98b0a3dc4dd56c7cb0 | Ruby | sirsir/PMS-FCT-cms | /- svn/PMS/lib/nil_class_ext.rb | UTF-8 | 314 | 3.046875 | 3 | [] | no_license | class NilClass
# NilClass.to_html -> string
# Return a ' ' tag for all nil values
# nil.to_html #=> ' '
def to_html
' '
end
# NilClass.to_date -> date
# Return a Date#null_date for all nil values
# nil.to_date #=> #2000/01/01#
def to_date
Date.null_date
end
end
| true |
9b3b4b04be0f5bae818170d9c78a8527d8a080a3 | Ruby | dallinbjohnson/coding_folder | /ruby/challenge/homeless_shelter/X-homeless_shelter.rb | UTF-8 | 5,505 | 3.703125 | 4 | [] | no_license | # You have been hired by a homeless shelter to keep track of all the people who check in and stay.
# You need to write a program that keeps track of Names, Age, Any illnesses they need medication for, and if they stayed there within the last 30 days. Print a table that stores this information. Use a gem for the table.... | true |
047805947955c81e785fcc1f2d9c047b07874c3a | Ruby | ottocedeno/pokemon-scraper-online-web-sp-000 | /lib/pokemon.rb | UTF-8 | 549 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pokemon
attr_accessor :id, :name, :type, :db
def initialize(name:, type:, db:, id: nil)
@id = id
@name = name
@type = type
@db = db
end
def self.save(name, type, db)
sql = "INSERT INTO pokemon (name, type) VALUES (?, ?)"
db.execute(sql, name, type)
end
def self.find(id, db)
... | true |
d2d1ebacda79e1acf7eb225f8de3923b41b0ddc4 | Ruby | samuelefabbro/ruby-challenges | /each.rb | UTF-8 | 102 | 2.953125 | 3 | [] | no_license | all_tweets = [
"First",
"Second",
"Third",
"Fourth",
]
all_tweets.each do |tweet|
puts tweet
end | true |
836b6b0ab246e99ad63dd6b80b469327a06fd621 | Ruby | karlwitek/launch_school_rb101 | /lesson1/small_problems/Easy_3/odd_lists.rb | UTF-8 | 1,551 | 4.53125 | 5 | [] | no_license | # Write a method that returns an array that contains every other
# element of an array that is passed in as an argument. The values
# in the returned list should be the 1st, 3rd, etc.. (position , not
# index )
def odd_list(array)
i = 0
array.map do |element|
element[i]
i += 2
end
end
p odd_list([3, 4... | true |
89cdab4451fe1ba39c2d760c6e4f638ec8b8f406 | Ruby | rlb3/fixup_blog | /lib/post_file.rb | UTF-8 | 1,369 | 3.015625 | 3 | [] | no_license | require 'yaml'
require 'stringex'
class PostFile
attr_accessor :path
attr_accessor :headers
attr_accessor :body
def initialize(path)
@path = path
end
def write
IO.write(path, to_text)
end
def parse
text = IO.read(self.path)
matcher = %r{---(.*?)---(.*)}m.match(text)
yaml = ... | true |
2869697e339542e8c7eaa1a46dfaed9ceee435b6 | Ruby | javierrcc522/rock_paper_scissors | /lib/rock_paper_scissors.rb | UTF-8 | 969 | 4.125 | 4 | [] | no_license | #! usr/bin/env ruby
class RockPaperScissors
def initialize(item1)
@item1 = item1
end
def beats?(item)
if @item1 === "rock" && item === "scissors"
puts "rock wins"
return true
elsif @item1 === "rock" && item === "paper"
puts "paper wins"
return false
elsif @item1 === "sci... | true |
a7a032c9d4f979be87f12bc9e22b7293a66f82a8 | Ruby | toothrot/riot | /test/core/assertion_macros/includes_test.rb | UTF-8 | 748 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'teststrap'
context "An includes assertion macro" do
setup do
Riot::Assertion.new("an array") { [1, 6, 42, 7] }
end
assertion_test_passes("when array includes 42", "includes 42") { topic.includes(42) }
assertion_test_fails("when 99 not included in array", "expected [1, 6, 42, 7] to include 99") d... | true |
23876bd9a56c951feddbaf3b4c900f86ddc0af85 | Ruby | raybchoi/rails-pet-lab | /db/seeds.rb | UTF-8 | 1,645 | 2.78125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
# Destroy everything to rebuild
Pet.destroy_all
Owner.destroy_all
Appointment.destroy_all
# Owners
owners_data = []
3.... | true |
a705cbf562612d4717a765256c087a4e47e3fa17 | Ruby | geras998/GildedRose | /lib/backstage.rb | UTF-8 | 386 | 2.78125 | 3 | [] | no_license | require_relative './item_behavior'
class Backstage < ItemBehavior
def update(item)
increase = 1 # AgedBrie, Backstage and Sulfuras increase 1 by default
case item.sell_in
when 0...6
increase = 3
when 6...11
increase = 2
end
update_quality(item, item.quality + increase)
end
de... | true |
c4ec82721f4fb706a45c13644dfb9df9cb25c3e1 | Ruby | appfolio/praxis | /spec/praxis/handlers/xml_spec.rb | UTF-8 | 6,024 | 2.515625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'spec_helper'
describe Praxis::Handlers::XML do
describe '#parse' do
shared_examples 'xml something' do
it 'works' do
expect(subject.parse(parsed.to_xml)).to eq(parsed)
end
end
# XML_TYPE_NAMES = {
# "Symbol" => "symbol",
# "Fixnum" => "integer",
#... | true |
b72ca6b46b760152a6af54da7b19b7e7ad72626a | Ruby | sinefunc/skeleton | /lib/tasks/seed.rake | UTF-8 | 581 | 2.734375 | 3 | [] | no_license | desc "Seeds the database"
task :seed do
require './init'
require 'spawn'
require 'ffaker'
require './test/factories'
puts "Seeding..."
Ohm.flush
# repeat "Users", 1_000 do
# User.spawn
# end
puts "Done!"
end
def repeat(message, count)
chunk = [1, (count/100)].max
count.times do |i|
if ... | true |
079f466751467d7dbae3f71b4c2f5484c5e56da3 | Ruby | rparkerson/launch-school | /RB101/lesson_6_slightly_larger_programs/twenty_one.rb | UTF-8 | 6,192 | 3.546875 | 4 | [] | no_license | VALUES = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
SUITS = ['C', 'D', 'H', 'S']
NUMBER_VALUES = {
'A' => 11, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7,
'8' => 8, '9' => 9, '10' => 10, 'J' => 10, 'Q' => 10, 'K' => 10
}
PLAYER = 'Player'
DEALER = 'Dealer'
SCORE_LIMIT = 21
HIT... | true |
8a8a8b1bc94b59b9c1901a939f700002ffee332a | Ruby | aliyamerali/backend_mod_1_prework | /section2/exercises/c3_methods_and_variables.rb | UTF-8 | 1,940 | 4.59375 | 5 | [] | no_license | # Learn Ruby the Hard Way: Exercise 19: Functions and Variables
# Defines a new method called cheese_and_crackers that takes in two parameters
def cheese_and_crackers(cheese_count, boxes_of_crackers)
# Method body: prints different strings that interpolate the parameters
puts "You have #{cheese_count} cheeses!"
... | true |
e6377a73d4833746996cf76210b7a1bed85dbb66 | Ruby | Tumbles/magic-search-engine | /search-engine/lib/condition/condition_color_indicator.rb | UTF-8 | 1,096 | 2.875 | 3 | [
"MIT"
] | permissive | class ConditionColorIndicator < ConditionSimple
def initialize(indicator)
@indicator = indicator.downcase.gsub(/ml/, "").chars.to_set
@indicator_name = color_indicator_name(@indicator)
end
# Only exact match
# For "has no color indicator" use -in:*
def match?(card)
card.color_indicator and @indic... | true |
fbbe849d0692ed85aa1c8ad190b7b9e7b68a1a8a | Ruby | FBH037/Ruby-programs | /CH5_EX5.6_Fullname_Greeting.rb | UTF-8 | 279 | 3.5625 | 4 | [
"Unlicense"
] | permissive | #Asks the user their full name then greats them
puts 'What is your first name?'
first = gets.chomp
puts 'What is your middle name?'
middle = gets.chomp
puts 'What is your last name?'
last = gets.chomp
puts 'Well what a fabulous name ' + first + ' ' + middle + ' ' + last + '!'
| true |
2e50e445f31a518ab13e8b8be79324706d7a6981 | Ruby | JDittles/intro-to-ruby-book | /6_loops_and_iterators/recursion_countdown.rb | UTF-8 | 217 | 4.03125 | 4 | [] | no_license | def countdown(number)
if number > 0
puts number
countdown(number-1)
else
puts "0"
end
end
puts "enter a number and I'll countdown to zero from it."
user_input = gets.chomp.to_i
countdown(user_input) | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.