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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c4e8a018929703faf321781bf3430d18f2c7b54b | Ruby | polyfox/moon-packages | /lib/moon/packages/std/state_manager.rb | UTF-8 | 2,147 | 3.1875 | 3 | [
"MIT"
] | permissive | module Moon
class StateManager
# @return [Moon::Engine]
attr_reader :engine
# List of all States on the stack
# @return [Array<State>]
attr_reader :states
# @param [Moon::Engine] engine
def initialize(engine)
@engine = engine
@states = []
setup_input
end
def s... | true |
c2e65b6d5e70bb9d4ac3f22fcf6cd08692f5594f | Ruby | androse/epl-api | /lib/epl_api/match.rb | UTF-8 | 2,139 | 2.6875 | 3 | [] | no_license | module EplApi
class Match < Fetcher
def initialize(week, id, options = {})
super(options)
@week = week
@id = id
end
def details(force = false)
if !@details || force
options = {
match_day_id: @week,
match_id: @id
}
@details = self.cla... | true |
8574c617ef84c594b3bd59360aba109c4e8b7f1c | Ruby | SumOfUs/champaign-ak-processor | /lib/actions_cache.rb | UTF-8 | 1,017 | 2.6875 | 3 | [
"MIT"
] | permissive | module ActionsCache
def self.append(payload)
@store ||= ActionsCache::Store.new(ENV['ACTIONS_CACHE_SIZE'].to_i)
@store.append(payload)
end
# ActionsCache::Store can
class Store
attr_accessor :redis
attr_accessor :cache_size
attr_accessor :namespace
def initialize(cache_size = 100, nam... | true |
da541a47a5d5709549142852d5e6480582a09f26 | Ruby | microsoftgraph/msgraph-sdk-ruby | /lib/models/sharing_detail.rb | UTF-8 | 8,322 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'date'
require 'microsoft_kiota_abstractions'
require_relative '../microsoft_graph'
require_relative './models'
module MicrosoftGraph
module Models
class SharingDetail
include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable
##
... | true |
83dab805018ad58a7b0769a9df0fb0cb3dfbbd68 | Ruby | tkzic/WebAudio | /osctest/wapOSCserver-ping.rb | UTF-8 | 3,865 | 2.546875 | 3 | [] | no_license | #!/usr/bin/env ruby
# file: wapOSCserver.rb
#
#
# serve osc messages from the touch-osc sample template for testing
# this will eventually be linked with websockets to provide a touchOsc
# hardware interface for web clients
#
#
#
# this version is combined with domain-ping so it does domain requests
# from google an... | true |
fb36288a2131dcb8a979534387cea00a90c623f7 | Ruby | llcepick/mailsend | /scripts/print_date.rb | UTF-8 | 305 | 2.71875 | 3 | [
"BSD-3-Clause"
] | permissive | #!/usr/bin/env ruby
# print the date in debian changelog format
# Example: Wed, 28 Mar 2012 20:45:31 -0400
# muquit@muquit.com Mar-28-2012
require 'date'
offset = DateTime.now.zone.to_s
offset = offset.sub(/:/,'')
t = Time.new
d = t.strftime("%a, %d %b %Y %H:%M:%S #{offset}")
puts " -- Muhammad Muquit <muquit@muqui... | true |
71dae13c4af8317b9dee98043778e2cf7caf25a8 | Ruby | kcarter80/advent-of-code | /day 11/2.rb | UTF-8 | 1,090 | 2.765625 | 3 | [] | no_license | serial_number = 3999
power_levels = Hash.new
1.upto(300) do |x|
1.upto(300) do |y|
rack_id = x + 10
power_level = rack_id * y
power_level += serial_number
power_level *= rack_id
power_level = power_level.digits[2] ? power_level.digits[2] : 0
power_level -= 5
if !power_levels[x]
power_levels[x] = Has... | true |
e466dcb63fe329dbaf51d79a6803aa0c3fc9d3b1 | Ruby | tovemercer/phase-0-tracks | /ruby/hamsters.rb | UTF-8 | 775 | 3.890625 | 4 | [] | no_license | puts "What is the hamsters name?"
name = gets.chomp
puts "Volume level? (1-10)"
volume = gets.to_i
puts "Fur color?"
fur = gets.chomp
puts "Adoptable? (Y/N)"
adoptable = gets.chomp
if (adoptable == "Y")
adoptable = true
elsif (adoptable == "N")
adoptable = false
else
puts "You entered incorrectly you dummy!"
end
put... | true |
ffc09b3cb6dd43e354dd192441e0ad9813aa33b5 | Ruby | gichelli/caseflow | /app/services/virtual_hearing_user_alert_builder.rb | UTF-8 | 2,016 | 2.609375 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
class VirtualHearingUserAlertBuilder
attr_accessor :changed_to_virtual, :virtual_hearing_attributes, :veteran_full_name, :hearing_time_changed
def initialize(changed_to_virtual:, virtual_hearing_attributes:, veteran_full_name:, hearing_time_changed: nil)
@changed_to_virtual = cha... | true |
ad8a69aac89e6a9a8f2c2e0f01a0d1f5d7591360 | Ruby | ajgosling/App_Academy_Review | /Ruby/W1D2_Reference/computer_player.rb | UTF-8 | 1,972 | 3.46875 | 3 | [] | no_license | class ComputerPlayer
def ComputerPlayer.generate_pos_arr
# create array of all positions from [0, 0] to [2, 3]
pos_arr = []
3.times {|i| 4.times {|j| pos_arr << [i, j]}}
pos_arr
end
attr_accessor :known_cards, :unknown_pos_arr, :prev_guess_pos
def initialize
@known_cards = Hash.new {|h, k| ... | true |
95fcb1b383e4130bd7f4ba0e5b8a708a72e0582a | Ruby | ChrisGoodson/learn_ruby | /04_pig_latin/pig_latin.rb | UTF-8 | 542 | 3.375 | 3 | [] | no_license | def translate(word)
words = word.split(" ")
latin = []
vowels = ["a", "e", "i", "o", "u"]
words.each do |i|
if vowels.include?(i[0])
latin.push(i + "ay")
else
total = i.split("")
start = 1
while !(vowels.include?(total[start]))
start += 1
end
if i[(start - 1).... | true |
7f62d7ba0d6375abd64ce98c9ab12732cde12047 | Ruby | joesiewert/gCamp | /app/controllers/pages_controller.rb | UTF-8 | 1,946 | 2.703125 | 3 | [] | no_license | class PagesController < PublicController
def index
quote1 = Quote.new
quote1.text = "Work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do."
quote1.author = "-Steve Jobs"
... | true |
5b2cc8ef1481c3e00a4a16b9e9167a20a5d94e60 | Ruby | oriff/multiplier | /goat_latin.rb | UTF-8 | 1,565 | 4.5 | 4 | [
"MIT"
] | permissive |
# Goat Latin is a made-up language based off of English, sort of like Pig Latin.
# The rules of Goat Latin are as follows:
# 1. If a word begins with a consonant (i.e. not a vowel), remove the first
# letter and append it to the end, then add 'ma'.
# For example, the word 'goat' becomes 'oatgma'.
# 2. If a word ... | true |
7e57be04d1e74b4a2baa2f7abd1b1dba93e8867e | Ruby | guiferrpereira/gohiring-challenge | /lib/go_hiring/documentation/finder.rb | UTF-8 | 1,284 | 2.78125 | 3 | [] | no_license | # frozen_string_literal: true
module GoHiring
# Public: Module responsible to get and format documentation
module Documentation
# Public: Finder will find documentation calling
# Ri command on system
#
# command - Ruby command to send Ri
#
# Examples
#
# GoHiring::Documen... | true |
63ff7fc400dd1e8ea30e5fd7c0a0f79c0a316a7b | Ruby | januszm/combthedesert-tmp | /app/services/scrape_page_url.rb | UTF-8 | 671 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'open-uri'
require 'nokogiri'
class ScrapePageUrl
def initialize(url)
@url = url
@content = { url: url, h1: [], h2: [], h3: [], links: [] }
end
def call
html = open_url
return html if html.is_a?(Hash) && html.has_key?(:error)
doc = Nokogiri::HTML(html)
%i(h1 h2 h3).each do |head... | true |
65925674a9d19974543bac210baafa7fdd50333f | Ruby | excellence/nebula | /app/helpers/application_helper.rb | UTF-8 | 338 | 2.625 | 3 | [] | no_license | # Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
# All top-level headings on pages should use this helper like so:
# %h1=title "Some Title"
# This sets the <title> tag appropriately in the head of the page.
def title(text)
@title = text
retur... | true |
7350449a7cba390f49b8ab5ddd12757b7441c9dd | Ruby | vasi/icq-mac-export | /icq-mac-export.rb | UTF-8 | 11,927 | 2.578125 | 3 | [
"BSD-2-Clause"
] | permissive | #!/usr/bin/ruby
require 'iconv'
require 'pathname'
require 'pp'
require 'time'
require 'rubygems'
require 'bit-struct'
require 'builder'
# Based on ICQ data format as documented Miranda's import-ICQ_Db_Specs.txt
# But it doesn't quite cover the Mac version, so many changes are made.
module ICQ
class FormatError < E... | true |
dea625db7e92ef774deec33163ea4fd887ecf7eb | Ruby | ngpestelos/misc-ruby | /basic/song.rb | UTF-8 | 637 | 4.09375 | 4 | [] | no_license | # See Programming Ruby, p. 23
class Song
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
def to_s
"Song: #@name -- #@artist (#@duration)"
end
end
class KaraokeSong < Song
def initialize(name, artist, duration, lyrics)
super(name, artist, dura... | true |
206b1a8f8bc872252b36b367e281932a1afd08bb | Ruby | keithrbennett/mock_dns_server | /lib/mock_dns_server/history.rb | UTF-8 | 1,408 | 2.734375 | 3 | [] | no_license | module MockDnsServer
# Handles the history of events for this server.
class History
def initialize(context)
@context = context
@records = ThreadSafe::Array.new
end
def size
@records.size
end
def add(entry_hash)
entry_hash[:time] ||= Time.now
@records << entry_hash
entry_hash
en... | true |
e55d62d04f7b59cafb691e0cb5d78b31ca889270 | Ruby | shiveshdewangan/LaunchSchool | /password.rb | UTF-8 | 196 | 3.078125 | 3 | [] | no_license | PASSWORD = "SecreT"
puts "Please enter your password:"
password = gets.chomp!
while password != PASSWORD
puts "Please enter your password:"
password = gets.chomp!
end
puts "Welcome" | true |
adefd285e11e9e171734d92e3493631d022b36b5 | Ruby | AndreaCrotti/code-kata | /kata2/kata2.rb | UTF-8 | 1,391 | 3.265625 | 3 | [] | no_license | #!/usr/bin/env ruby -w
$VERBOSE = true
$DEBUG = true
require 'rubygems'
require 'test/unit'
def mid_point(first, last)
first + ((last - first) / 2)
end
def chop(idx, arr)
false if arr.empty?
puts "arr = #{arr.to_s}"
mid = mid_point(0, arr.length)
puts mid
val = arr[mid]
mid if val == idx
if val >... | true |
8f2e42b5abb0f19e5f7607f4d0de088daaf528e8 | Ruby | r3ap3rpy/Ruby | /Restaurant.rb | UTF-8 | 313 | 2.75 | 3 | [] | no_license | require '.\\MetaProgramming'
cook "chickensoup"
cook "chickensoup" do
puts "Preparing to cook chichen soup!"
end
before "chickensoup" do
puts "Some slicing and preparation"
end
after "chickensoup" do
puts "Some cleaning and serving"
end
puts "The whole as one! --------------------"
run('chickensoup')
| true |
3a2dd362c506dbe0f135c37071fe8377f40ef64f | Ruby | ikappas/php-composer | /lib/composer/package/link.rb | UTF-8 | 1,791 | 3.0625 | 3 | [
"MIT"
] | permissive | #
# This file was ported to ruby from Composer php source code file.
# Original Source: Composer\Package\Link.php
#
# (c) Nils Adermann <naderman@naderman.de>
# Jordi Boggiano <j.boggiano@seld.be>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this sourc... | true |
248b278a0e82ba43c27d26db55d1f8111db933e0 | Ruby | FotoVerite/box-score-temp | /db/seeds.rb | UTF-8 | 4,967 | 2.53125 | 3 | [] | no_license | require 'factory_girl_rails' # so it can run in development
SCHOOL_NAMES = ['Trinity', 'Southville', 'Lexington', 'Eastern Catholic', 'Westminster',
'Northern', 'Lakeland', 'Bishop Kelly', 'Rexburg', 'Southern', 'Eastminster', 'Western Catholic'].freeze
ASSOCIATION_NAMES = %w(PSAL CHSAA NYSAISAA).freez... | true |
6743b7fe0acd90581b29d084e231dd84d0583794 | Ruby | aalokdevk29/vehicles_epic | /app/models/record.rb | UTF-8 | 1,025 | 2.65625 | 3 | [] | no_license | require 'csv'
class Record < ApplicationRecord
belongs_to :user
belongs_to :vehicle
belongs_to :nationality
scope :data, -> { includes(:user, :vehicle, :nationality) }
def self.search(search)
if search
Record.data.where('users.name LIKE ? OR vehicles.model LIKE ?', "%#{search}%", "%#{search}%").r... | true |
ec007931ce5c0dfb996be69914cb66bdbd6b56f2 | Ruby | jkopczyn/AssortedSnippets | /ring_buffer.rb | UTF-8 | 1,080 | 3.796875 | 4 | [] | no_license | class RingBuffer
attr_reader :length, :start, :items, :arr
def initialize(length)
@length = length
@arr = Array.new(10)
@start = 0
@items = 0
end
def append(*items)
items.each do |item|
self.push(item)
end
end
def push(item)
@arr[(@start+@items)% @length] = item
if @... | true |
60cb1edbde1a8b6df40b96a751811b1f8abb288a | Ruby | leoru/justy | /lib/justy/finder.rb | UTF-8 | 891 | 2.75 | 3 | [
"MIT"
] | permissive | # encoding: UTF-8
require 'justy/parser'
require 'justy/commands/find_command_factory'
require 'justy/commands/find_command'
module Justy
class Finder
attr_reader :parser
attr_reader :find_command
def initialize
super
@parser = Parser.new
end
def run(args)
options = @parser.p... | true |
6015a061335bd792bf9b62c45cb82bedbeec08f1 | Ruby | abrennec/sose20_mc | /code/ruby_language_nutshell/23_read_from_file.rb | UTF-8 | 557 | 3.75 | 4 | [] | no_license |
# first way to handle a file
File.open("employees.txt", "r") do |file|
#puts file
#puts file.read()
#puts "<<<<<"
# puts file.readline()
# puts file.readline()
#puts file.readlines() # this call puts each line in an array
#puts file.readlines()[index]
for line in file.readlines()
... | true |
e649a2b44417949e8e9e09c0911e341d84cd1727 | Ruby | Mindful/blog | /app/models/category.rb | UTF-8 | 794 | 2.53125 | 3 | [] | no_license | class Category < ActiveRecord::Base
belongs_to :tag, :class_name => 'ActsAsTaggableOn::Tag'
#all tags are forced lowercase before saving, so we should search for them by lowercase
before_validation :downcase_and_associate_tag #before_save is after validation
before_destroy :can_destroy? #if can_destroy? retu... | true |
51b15013c6c8d554839d5c05330414426a8e8e7e | Ruby | jliclaire/ruby-practice | /roll_dice.rb | UTF-8 | 971 | 4.4375 | 4 | [] | no_license | # 2.
# Write a method that simulates rolling two 6 sided dice and calculating the sum of the numbers
# You program should roll the dice 36,000 times
# Use an array to tally the number of times each possible sum appears
# Display the results
def dice_one()
return rand(1..6)
end
def dice_two
return rand(1..6)
end
... | true |
fac3f25c5bd73e72b5c0befd04fa5975bbfdd507 | Ruby | zacharycohn/finalproject | /test/models/habit_test.rb | UTF-8 | 2,255 | 2.734375 | 3 | [] | no_license | require 'test_helper'
class HabitTest < ActiveSupport::TestCase
test "#countColor" do
create_old_checkins
countGreens = @habit1.count_color("green")
countYellows = @habit1.count_color("yellow")
countReds = @habit2.count_color("red")
assert_equal 1, countGreens
assert_equal 7, countYellows
assert_equa... | true |
580b731e51a13aa43c12bd257e252742a4239b8b | Ruby | PerlaAvila/learning_ruby | /preparacion - 2/martes/prueba1.rb | UTF-8 | 410 | 2.71875 | 3 | [] | no_license | variable = ["<", ">", "!", "*", "'", "'", "#"]
hash_waka = {
'<' => 'Waka',
'>' => 'waka',
'!' => 'bang',
"'" => 'tick',
'#' => 'hash',
'^' => 'Caret',
'"' => 'quote',
'`' => 'back-tick',
'$' => 'dollar',
'-' => 'dash',
'=' => 'equal',
'@' => 'at',
'_' => 'underscore... | true |
ad6a3ed3b043db33996f5422d7ce34ddd3e134ba | Ruby | marciojg/my-notes | /ruby/alias_method.rb | UTF-8 | 666 | 3.53125 | 4 | [
"Apache-2.0"
] | permissive | # Heranca = Herdar comportamento (Pessoa1 < Pessoa2)
# Polimorfismo = multiplas formas (name sobrescrevendo name)
class Pessoa1
def name
puts 'Marcio'
end
end
class Pessoa2 < Pessoa1
def name
puts 'Sr. Marcio'
end
end
# Usando alias_method
# alias_method serve para trocar o nome de uma metodo da clas... | true |
c2225dcbf9b37f118bb664d76bf6d09b28c96b6a | Ruby | mediasp/hold | /lib/hold/sequel/property_mapper.rb | UTF-8 | 6,677 | 2.546875 | 3 | [] | no_license | module Hold
module Sequel
# Abstract superclass.
#
# Responsibility of a PropertyMapper is to map data for a particular
# property of a model class, between the instances of that model class, and
# the database
class PropertyMapper
def self.setter_dependencies_for(_options = {})
... | true |
f5e8e80821513f86fe7624d8cb98eaf43fe15a61 | Ruby | andoshin11/twterm | /lib/twterm/tweetbox.rb | UTF-8 | 2,764 | 2.75 | 3 | [
"MIT"
] | permissive | require 'twterm/publisher'
module Twterm
class Tweetbox
class EmptyTextError < StandardError; end
class InvalidCharactersError < StandardError; end
class TextTooLongError < StandardError; end
include Singleton
include Readline
include Curses
include Publisher
def compose(in_reply_to... | true |
75cc33a86203245fe553aa2f89027e7a980a01ad | Ruby | JonTurner/celluloid-eventsource | /lib/celluloid/eventsource/response_parser.rb | UTF-8 | 698 | 2.609375 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] | permissive | require 'http/parser'
module Celluloid
class EventSource
class ResponseParser
extend Forwardable
attr_reader :headers
delegate [:status_code, :<<] => :@parser
def initialize
@parser = Http::Parser.new(self)
@headers = nil
@chunk = ""
end
def heade... | true |
01b3c0406fde92f6ab235cf9c44db9372bda95f9 | Ruby | manjushareddy27/minesweeper_ruby | /lib/minesweeper_error.rb | UTF-8 | 1,040 | 2.8125 | 3 | [] | no_license | class MinesweeperError < StandardError; end
class InvalidInteger < MinesweeperError
def initialize(msg = 'Invalid integer.\n')
super
end
end
class InvalidDifficultyOfGame < MinesweeperError
def initialize(msg = 'Invalid difficulty parameter.\n')
super
end
end
class OutOfRange < MinesweeperError
def... | true |
52df510818f3281f6bc6510cc93470039b2ba5ba | Ruby | HereticSight/phase-0-tracks | /ruby/arrays_drill.rb | UTF-8 | 2,577 | 4.34375 | 4 | [] | no_license | #Build method that takes 3 items as parameters and returns an array with the 3 items as objects.
def build_array(a, b, c)
newarray = [a, b, c]
return newarray
end
#build a method that takes an array and an item as parameters. Adds the item to the array and returns the array with the newly added item.
def ad... | true |
bf01a7f547813d5988da39f8b7ba04387242678d | Ruby | linda-le1/monster_shop_part_1 | /app/models/order.rb | UTF-8 | 1,006 | 2.578125 | 3 | [] | no_license | class Order <ApplicationRecord
validates_presence_of :name, :address, :city, :state, :zip, :current_status
has_many :item_orders
has_many :items, through: :item_orders
has_many :merchants, through: :item_orders
belongs_to :user
enum current_status: %w(pending packaged shipped cancelled)
def grandtotal... | true |
71010b304e06c70fdaf88051c6f43e9cab584772 | Ruby | wogri/inki | /app/models/menu.rb | UTF-8 | 2,550 | 3.0625 | 3 | [
"MIT"
] | permissive | # implements the menu, able to build recursive stuff
class Menu
attr_accessor :klass, :icon, :parent, :depth, :menu_string, :submenu, :url_for_path, :root, :menu_elements
def initialize(menu_config, depth = 0)
self.depth = depth
if self.depth == 0
self.menu_string = :root
self.root = true
end
depth +... | true |
4244ad085797ea1a3bb7973aada913cda623cb01 | Ruby | marcandre/scheherazade | /lib/scheherazade/log.rb | UTF-8 | 843 | 2.703125 | 3 | [
"MIT"
] | permissive | module Scheherazade
class Logger
EVENTS = [:saving, :building, :fixing_errors, :final_value, :setting_assocation, :setting, :additional_character].to_set.freeze
def off
@events = []
end
def on
only
end
def only *events_and_characters
events_and_characters = events_and_char... | true |
f876584436ebf6f319264d6c6cb5ab01640f5b85 | Ruby | samrose/Answer-Factory | /spec/factory/factory_spec.rb | UTF-8 | 1,684 | 2.515625 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../spec_helper'
class FakeWorkstation < Workstation; end
describe Factory do
describe "adding a workstation" do
before(:each) do
Factory.setup do
end
@workstation = Factory.workstation('sample', :FakeWorkstation)
end
it "adds it to the list of work... | true |
913d517ea4b8c7de3ab4c89bf2900b7ae356f04f | Ruby | JEC1100/oyster_card | /spec/station_spec.rb | UTF-8 | 382 | 2.75 | 3 | [] | no_license | require 'station'
describe Station do
let(:station) { Station.new }
it "Given station name set when require name then return name" do
station.name("bank")
expect(station.station_name).to eq("bank")
end
it "Given station zone set when require zone then return zone" do
station.zon... | true |
63e080f682a222139351b4ab593e1d80698d4923 | Ruby | SidharthNambiar/Launch-School | /backend_prep/ruby_basics/reading_documentation_2/ex_6.rb | UTF-8 | 465 | 4.03125 | 4 | [] | no_license | # Ruby Basics
# Ruby Documentation 2
# Exercise 6: Multiple Signatures
# What do each of these puts statements output?
a = %w(a b c d e)
puts a.fetch(7)
# Answer: Index only goes up to 4; therefore IndexError exception thrown
# IndexError: index 7 outside of array bounds: -5...5
puts a.fetch(7, 'beats me')
# An... | true |
cd09f7e1d9f21578cb94f24742e3328939fd3d18 | Ruby | komaji/kachikachi | /lib/kachikachi/git_hub.rb | UTF-8 | 1,221 | 2.625 | 3 | [
"MIT"
] | permissive | require 'octokit'
require 'kachikachi/pull_request'
module Kachikachi
class GitHub
attr_accessor :client
def initialize(options)
@options = options
end
def pull_requests
pull_request_numbers = @options['pull-request-numbers']
return pull_request_numbers.map { |number| PullRequest.... | true |
0a25929e4a479b40ecef7a4a56c71f61b250fa4c | Ruby | bguids91/jungle-rails | /spec/models/user_spec.rb | UTF-8 | 2,806 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe "Validations" do
subject { described_class.new(first_name: "Name", last_name: "Name", email: "email@email.com", password: "password", password_confirmation: "password") }
it "is valid with valid attributes" do
expect(subject).to be_va... | true |
681de1ca2b45f643cae980b1ccabc6d8ec9b6307 | Ruby | vp932712/ruby-objects-has-many-through-lab-web-010818 | /lib/doctor.rb | UTF-8 | 346 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Doctor
attr_accessor :name, :appointments
def initialize (name)
@name = name
@appointments = []
end
def add_appointment(name)
self.appointments << name
name.doctor = self
end
def appointments
@appointments
end
def patients
self.appointments.collect do |appObj|
appO... | true |
068a7a1a8d583a823270d5b5368654b1f3310f97 | Ruby | TannerEady/Contact-List | /contact.rb | UTF-8 | 1,440 | 3.34375 | 3 | [] | no_license | require 'csv'
class Contact
attr_accessor :name, :email
def initialize(name, email)
# TODO: assign local variables to instance variables
@name = name
@email = email
end
def to_s
# TODO: return string representation of Contact
end
## Class Methods
class << self
def create(name, em... | true |
94dce39025cfdd7398e50e31642bcf1aae21009d | Ruby | ksherlock/mdbasicxx | /lib/MiniAssembler.rb | UTF-8 | 15,181 | 2.78125 | 3 | [] | no_license |
require_relative 'Instructions'
require_relative 'Expression'
class Literal < String
end
class MiniAssembler
# applesoft has a limit of 236 chars / line. 236/4 = 59.
CHUNK_SIZE = 50
M6502 = 0
M65C02 = 1
M65816 = 2
EQU = :'.equ'
ORG = :'.org'
MACHINE = :'.machine'
LONG = :'.long'
SHORT = :'.short'
POKE... | true |
8b479f993118546881c3f54a938ce7212e85fb8a | Ruby | takatoshiH/AtCoder | /ABC/ABC177A.rb | UTF-8 | 80 | 3.15625 | 3 | [] | no_license | a,b, c = gets.chomp.split(" ").map(&:to_i)
puts a.to_f / c > b ? 'No' : 'Yes' | true |
04323d98bbe11e0c661e02fa4622970ff53335e2 | Ruby | dainmiller/wishlist-app | /spec/models/product_spec.rb | UTF-8 | 1,966 | 2.5625 | 3 | [] | no_license | describe Product do
context "validations" do
context "fail" do
it "refuses to save without URL" do
product = Wishlist.new.products.new
product.valid?
expect(product.errors.errors.map(&:attribute)).to eq([:url])
end
it "refuses to save without a wishlist" do
prod... | true |
f556d52cf3fb714c16a2528d14ee7d30bac2e0b4 | Ruby | tk0358/meta_programming_ruby2 | /chapter5/14singleton_class.rb | UTF-8 | 174 | 3.171875 | 3 | [] | no_license | obj = Object.new
singleton_class = class << obj
self
end
p singleton_class.class
def obj.my_singleton_method; end
p singleton_class.instance_methods.grep(/my_/) | true |
6691c85c2a89414a647e5a1f9b339d7ecc3d0b62 | Ruby | mhl/unicode-poster | /generate-output-multi-page | UTF-8 | 6,614 | 2.984375 | 3 | [] | no_license | #!/usr/bin/ruby -w
def usage_and_exit
STDERR.puts <<EOUSAGE
Usage: <paper> [ <dpi> ]
... where <paper> is A4 or A0, and <dpi> is probably 300 or 600. The
value of <dpi> defaults to 600, and the script will generate .pcl and
.pjl output if it\'s 600.
EOUSAGE
exit(-1)
end
unless (((ARGV.length == 1) || (ARGV.len... | true |
e9c7c8f387491b3f1dd9a316ce776bf58758dec5 | Ruby | Pignataro67/pokemon-scraper-v-000 | /lib/pokemon.rb | UTF-8 | 716 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pokemon
attr_accessor :id, :name, :type, :hp, :db
@@all = []
def initialize(opts)
@id = opts[:id]
@name = opts[:name]
@type = opts[:type]
@hp = opts[:hp]
@db = opts[:db]
@@all << self
end
def self.all
@@all
end
def self.save(name, type, db)
db.execute("INSERT I... | true |
8ffd37a924f0f68c3dec43a4aff491c3b2749120 | Ruby | Tkam13/atcoder-problems | /abc057/c.rb | UTF-8 | 124 | 2.796875 | 3 | [] | no_license | n = gets.to_i
ans = 10**18
(1..Math.sqrt(n)).each do |i|
if n % i == 0
ans = [ans,(n/i).to_s.size].min
end
end
puts ans | true |
f349fec5b9473fff0ad8a36fcfa53eb377ad3ecd | Ruby | stegrial/analyzer-testing | /pages/amazon/deals_page.rb | UTF-8 | 3,041 | 2.5625 | 3 | [] | no_license | require_relative '../page_extension'
class DealsPage < PageExtension
DEALS_AND_PROMOTIONS_PAGE_IL = "//h1/*[text()='Deals and Promotions']"
DEALS_AND_PROMOTIONS_PAGE_TA = "amazon:deals_page:deals_and_promotions_page"
FASHION_CHECKBOX_IL = "(//label/span[contains(text(), 'Fashion')])[1]"
FASHION_CHECKBOX_TA ... | true |
de9660f466819d5e105ca8c3e3e371e66728faf2 | Ruby | elma635/badges-and-schedules-nyc-web-051319 | /conference_badges.rb | UTF-8 | 545 | 4 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
return "Hello, my name is #{name}."
end
def batch_badge_creator(attendees)
attendees.collect do | name |
badge_maker(name)
end
end
def assign_rooms(attendees)
attendees.collect.each_with_index do |name, index|#set for iteration, way to access each element in array
"Hello, #{name}!... | true |
c0ea1eeaa2b220866778a5b894fa2b7067a42512 | Ruby | Roanmh/ProjectEuler | /test/probability_test.rb | UTF-8 | 168 | 2.796875 | 3 | [] | no_license | res = []
for i in 1..1000000
res << 8*rand(0..1)+4*rand(0..1)+2*rand(0..1)+rand(0..1)
end
#puts res
cnt = {}
for i in 0..15
cnt[i] = res.count(i)
end
puts cnt
| true |
c91c2399b0dc84814051c4e189cb57044757f03e | Ruby | rkhmelyuk/memory | /samples/src/main/ruby/plot.rb | UTF-8 | 1,472 | 2.890625 | 3 | [] | no_license | class Graph
attr_reader :title, :metric, :data_file, :chart_file
def initialize(title, metric, data_file, chart_file)
@title=title
@metric=metric
@data_file=data_file
@chart_file=chart_file
end
end
def plot(report, data_dir, charts_dir)
metrics = report.metrics
if metrics.length == 0 then
... | true |
796d0b9932ad7c63131de64e2d13723eab807d7c | Ruby | GSA/voc_admin | /lib/url_validator.rb | UTF-8 | 1,498 | 2.765625 | 3 | [] | no_license | # URL Validation functionality provided by
# {https://gist.github.com/1051088 Douglas F Shearer}
# and provided here verbatim.
# Require this file, or put this in where Rails will auto load it.
# = Usage
# validates :attribute, :url => true
# Allow nil values
# validates :attribute, :allow_nil => true
# Allow empt... | true |
ba8d5ae64162ac34c36f0c3fe8e32acdf7476456 | Ruby | musta7188/programming-univbasics-4-array-simple-array-manipulations-london-web-012720 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 1,030 | 3.53125 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_push(array, string)
add_to_the_end = array.push(string)
add_to_the_end
end
def using_unshift(array, string)
update_first_element = array.unshift(string)
update_first_element
end
def using_pop(array)
remove_last = array.pop
remove_last
end
def pop_with_args(array)
remove_last_two = array.p... | true |
d5f481eb9660e9f489327d42ba8d94b4942e1ee3 | Ruby | Teeohbee/airport_challenge | /spec/airport_spec.rb | UTF-8 | 3,015 | 3.125 | 3 | [] | no_license | require 'airport'
## Note these are just some guidelines!
## Feel free to write more tests!!
# A plane currently in the airport can be requested to take off.
#
# No more planes can be added to the airport, if it's full.
# It is up to you how many planes can land in the airport
# and how that is implemented.
#
# If th... | true |
f26c3266bac0e7d4e33168b42ff3a2c25ac77c71 | Ruby | hatemogi/gcj_practice | /store_credit/store_credit.rb | UTF-8 | 499 | 3.015625 | 3 | [] | no_license | def solve credit, items
head, *rest = items
if found = rest.find {|p| head[0] + p[0] == credit}
return [head, found]
end
solve credit, rest
end
def eachset credit, items
indexed = items.zip((1..items.length).to_a)
cand = indexed.select {|p| p[0] < credit}.sort {|p| p[0]}.reverse
solve(credit, cand)... | true |
39d13edab380f8227f0b726d44a4eeacfdd81476 | Ruby | suvedhs/ruby_labs | /angry_boss.rb | UTF-8 | 103 | 2.84375 | 3 | [] | no_license | puts 'what do u want dude'
response = gets.chomp
puts 'WHAT DO YOU MEAN, "' + response.upcase + '"?!?'
| true |
5a6a3fb5c0f596a98407e5654d8f4917483fe411 | Ruby | devzmiller/flashcards | /app/models/round.rb | UTF-8 | 434 | 2.828125 | 3 | [] | no_license | class Round < ApplicationRecord
belongs_to :deck
def unanswered_cards
cards = []
self.deck.cards.each do |card|
if card.guesses.length == 0
cards << card
else
correct = false
card.guesses.each do |guess|
if guess.correct == true
correct = true
... | true |
a2fdd35463dd4fe31c15aa818500d44757c11bf0 | Ruby | greendog/clots | /lib/clot/date_tags.rb | UTF-8 | 8,046 | 2.703125 | 3 | [] | no_license | require 'clot/date_tags'
require 'clot/no_model_form_tags'
module Clot
class NumberedTag < ClotTag
def value_string(val)
if val < 10
"0#{val}"
else
val
end
end
def can_show(val)
true
end
def get_options(from_val,to_val, selected_value = nil)
option... | true |
b12201291c6f3acd13b7cab77998cab9b6245fed | Ruby | cedricdlb/csv_2_kml_tour | /lib/progress_status.rb | UTF-8 | 1,088 | 3.03125 | 3 | [] | no_license | class ProgressStatus
attr_accessor :file_size, :threshold_for_new_progress_report, :reporting_increment
attr_reader :file_pos, :progress_percent
DEFAULT_REPORT_EVERY_X_PERCENT = 10.0 # report on progress every 10% of file read
def initialize(size)
@file_size = size
@file_pos = 0
@reporting_increment = DEF... | true |
2b6598534c9a921ddde587234e03f6e543548d83 | Ruby | tailup0/sha256.rb | /sha256.rb | UTF-8 | 6,569 | 2.859375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
class Sha256
# 定数K
# サイズ: 32bit(4Byte) x 8 = 256bit
INT_K = ['428a2f98', '71374491', 'b5c0fbcf', 'e9b5dba5', '3956c25b', '59f111f1', '923f82a4', 'ab1c5ed5',
'd807aa98', '12835b01', '243185be', '550c7dc3', '72be5d74', '80deb1fe', '9bdc06a7', 'c19bf174',
'e49b69c1', 'efbe47... | true |
87c4d5f8489eb2869fe96be8bc74343b4e368827 | Ruby | kyledrake/sammy_davis_jr | /test/lib/extensions/hash_test.rb | UTF-8 | 812 | 2.609375 | 3 | [] | no_license | require_relative '../../config.rb'
describe Hash do
before do
@hash = {:one => 'one', :two => 'two', :three => 'three', :four => 'four'}
end
describe 'symbolize_keys' do
it 'works' do
{'one' => 'two', 'three' => 'four'}.symbolize_keys.must_equal(:one => 'two', :three => 'four')
end
end
... | true |
06450b58bab43f4d2566e5ec566ed01dc4b56827 | Ruby | lucius-m/Ruby | /exercises_solutions/enumerables_and_code_blocks/inject_methods.rb | UTF-8 | 606 | 3.828125 | 4 | [] | no_license | #!/usr/bin/env ruby
# inject/reduce
# "Accumulator"
# Block variable to use for accumulation
# Ruby convention: memo
#Acuumulator Block Variable
print (1..5).map {|n| n}
puts ""
print (1..5).inject {|memo, n| memo + n}
print [1,2,3,4,5].inject {|memo, n| memo + n}
puts
print [1,2,3,4,5].inject {|memo, n| memo * n}... | true |
54743083a03680359dab0caa5ad9c95d6522181d | Ruby | aldrinmartoq/6tajuntaruby | /qsort3.rb | UTF-8 | 631 | 3.34375 | 3 | [] | no_license | #!/usr/bin/env ruby
# quick sort en ruby multihilo principiante
def qsort(list, level = 0)
return [] if list.size == 0
x, *xs = *list
less, more = xs.partition { |y| y < x }
r = []
if (level < 4)
t1 = Thread.new { r[0] = qsort(less, level + 1) }
t2 = Thread.new { r[1] = qsort(more, level + 1) }
... | true |
4a5fd861b22b067658d7fb43ee2a8426de00afe7 | Ruby | MatheusRich/SIGS-GCES | /SIGS/app/models/room_solicitation.rb | UTF-8 | 1,486 | 2.640625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Class t save responder solicitation
class RoomSolicitation < ApplicationRecord
belongs_to :solicitation
belongs_to :responder, class_name: 'User', optional: true
belongs_to :room, optional: true
belongs_to :department, optional: true
# Not null values
validates_presence_of ... | true |
a62922d49d9bdb6024edfdde015123749481b224 | Ruby | rocksolidwebdesign/loldb | /lib/scrape.rb | UTF-8 | 1,319 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'pry'
require 'json'
require 'nokogiri'
require 'open-uri'
class LeagueScraper
def initialize
@host = "leagueoflegends.wikia.com"
@base_url = "http://#{@host}"
@urls = {
champ_list: "#{@base_url}/wiki/List_of_champions"
}
end
def run_champs
html = open(@urls[:cha... | true |
fde9791312f52e439b127a0e0c25c4f0ad895f09 | Ruby | tumes/data-engineering | /challenge/app/models/tab_file_processor.rb | UTF-8 | 326 | 3 | 3 | [] | no_license | class TabFileProcessor
require 'csv'
# This method takes a tab delimited file, disregards the headers, and
# returns an array of arrays that represent the rows of provided data.
def self.process(tab_file)
data = CSV.read(tab_file, { :col_sep => "\t" })
# Disregard the header
data.tap(&:shift)
end... | true |
e65d526203b0a4f99a3d4706c0c8c57738fca591 | Ruby | nj31/CLIProject1 | /lib/services/cli.rb | UTF-8 | 1,862 | 3.484375 | 3 | [] | no_license | require "./lib/services/api"
class Cli
def start
puts "Welcome to recipe menu!!"
Api.loadRecipes
list_Recipes
end
def get_input
puts ""
puts "Select a recipe by the # or exact spelling of name!"
puts "To exit, type exit"
gets.chomp
end
def li... | true |
462a5822c29482f40deb0f5b04239207eead0ba4 | Ruby | guilhermezils/lesson-planner | /app/Scheduler.rb | UTF-8 | 2,879 | 3.203125 | 3 | [] | no_license | class Scheduler
# here will be your CLI!
attr_accessor :age, :siblings, :length_of_lesson, :username
attr_reader :first_name, :last_name, :student_id, :teacher_id, :start_time, :name, :rate_per_hour
def run
welcome
login_or_signup
check_schedule
update_length_of_lesson
cancel_less... | true |
25c0c08747519a046a6cb583a613694f99954f57 | Ruby | checkmates1/Konquer | /app/models/pawn.rb | UTF-8 | 1,018 | 3.5 | 4 | [] | no_license | class Pawn < Piece
def valid_move?(destination_x, destination_y)
x_difference = x_position - destination_x
y_difference = destination_y - y_position if white?
y_difference = y_position - destination_y if black?
return true if vertical_move(destination_y, x_difference, y_difference)
return true if ... | true |
ee0ba9a7b4a3606e4d2ee2d82602470d44045458 | Ruby | owenkelly/RubyWinter2014 | /week7/exercises/features/converter.rb | UTF-8 | 208 | 3.1875 | 3 | [
"Apache-2.0"
] | permissive | class Converter
attr_accessor :num, :type
def initialize num
@num = num.to_f
end
def convert
self.send("#{@type}_conversion")
end
def Fahrenheit_conversion
(@num - 32) * 5 / 9
end
end
| true |
4d0ed82b07a0f2f7e44ffc1b7805808e1575cca2 | Ruby | paulkelly20/codeclan_pda_evidence | /ruby_test/specs/testing_task_specs.rb | UTF-8 | 620 | 3.125 | 3 | [] | no_license | require_relative("../card.rb")
require_relative("../testing_task_2.rb")
require("minitest/autorun")
class TestCard < MiniTest::Test
def setup()
@card1 = Card.new( "Club", 5)
@card2 = Card.new("Heart", 8)
@game = CardGame.new()
end
def test_card_1_name()
assert_equal("Club", @card1.suit)
en... | true |
58f258a53ff895f8d6848f960c4b3556c6378c6e | Ruby | chasejarms/ORM-Practice | /playwrights.rb | UTF-8 | 1,378 | 2.9375 | 3 | [] | no_license | require_relative = 'play_db_connection'
class PlayWright
attr_accessor :id, :name, :birth_year
def self.all
PlayDBConnection.instance.execute(<<-SQL)
SELECT
*
FROM
playwrights
SQL
end
def self.find_by_name(name)
PlayDBConnection.instance.execute(<<-SQL, name)
SE... | true |
5f78141705f5bdbd0e8acbf4604dee4bfdeb0b0c | Ruby | elavretskiy/solidgem.ru | /app/controllers/balancing_controller.rb | UTF-8 | 605 | 2.640625 | 3 | [] | no_license | class BalancingController < ApplicationController
respond_to :js
def balance
string = params[:string]
array = string.split ''
array.delete_if { |a| a != ')' && a != '(' }
@balance = if array.size % 2 != 0
false
else
@balance = 0
ar... | true |
4e15ae2a4e8482a7392e4cb5c5bbfade1029defa | Ruby | IIIIIIIIll/RubyQuizess | /Quiz15/question9.rb | UTF-8 | 282 | 2.984375 | 3 | [] | no_license | # Ruby has singleton methods that function similarly to 'class' or 'static' methods in languages like Java, but the
# implementation is different. Ruby's 'class methods' are really just instance methods defined in the singleton class.
# Ruby doesn't have static methods like Java.
| true |
6d0219c2402557d4fce5312d415b6c0f3050d655 | Ruby | rchavesc/inheritance_polymorphism_models | /exercise_2/abilities.rb | UTF-8 | 445 | 2.796875 | 3 | [] | no_license | module Abilities
module Fly
def taking_off
'Estoy volandooooo!'
end
def landing
'Estoy cansado de volar, voy a aterrizar'
end
end
module Swim
def swimming
'Estoy nadando!'
end
def diving
'glu glub glub glu'
end
end
module Walk
def walking
... | true |
38979b23bd3b50a8e0645282b1505e43e1c2d442 | Ruby | dare1010/rl1 | /1wk/5e_convert.rb | UTF-8 | 105 | 3.25 | 3 | [] | no_license | # http://pastebin.com/AKeV0Scs
def convert(fah)
format("%.2f",(fah - 32) * 5.0/9)
end
puts convert(4)
| true |
0a9b95dc2e13e3331a3549a8298a73fb55d78e64 | Ruby | vadimpetkevich/itechart-students-lab | /practical_part_1/as_short_as_you_can/as_short_as_you_can.rb | UTF-8 | 152 | 3.265625 | 3 | [] | no_license | require_relative 'the_shortest_method'
# usage example
regex = /^[A-Z]*$/ # Upper case
str = 'RUBY'
puts ('Does regex match string?')
m(regex, str)
| true |
06c4f5f24bc64e55170830c31cfed9053185d036 | Ruby | ffleming/crypto_toolchain | /lib/crypto_toolchain/tools/ecb_cut_and_paste_attack.rb | UTF-8 | 1,345 | 2.640625 | 3 | [
"MIT"
] | permissive | module CryptoToolchain
module Tools
class EcbCutAndPasteAttack
include DetermineBlocksize
def initialize(replace: "user",
with: "admin",
oracle: CryptoToolchain::BlackBoxes::EcbCutAndPasteTarget.new,
initial: "charlesisagood@dog.com"
... | true |
fe4b0f07357bcaaac2b3b677fb30188b9572ad3b | Ruby | buscanopaul/batch8-activities | /rubyactivities/encapsulation.rb | UTF-8 | 346 | 4.15625 | 4 | [] | no_license | class Comparison
def initialize(num1, num2)
@num1 = num1
@num2 = num2
end
def winner
if @num1 > @num2
puts "Number 1 is greater than Number 2"
elsif @num2 > @num1
puts "Number 2 is greater than Number 1"
else
puts "Numbe is equal"
end
end
end
compare = Comparison.new(... | true |
68153bc3428d07236294da12c54088a4d2c1bb65 | Ruby | joecowton/learn-to-program | /chap06/ex_1.rb | UTF-8 | 127 | 2.984375 | 3 | [] | no_license | puts 'Hello what do you want?'
speech = gets.chomp.upcase!
#num.to_s
puts "WHAT DO YOU MEAN #{speech}???? YOU\'RE FIRED!!!"
| true |
f1c8839adfc7fa3bbfe87ee73e44a03490f5faf4 | Ruby | apiaryio/dredd-hooks-ruby | /spec/lib/dredd_hooks/server/buffer_spec.rb | UTF-8 | 1,638 | 2.59375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'spec_helper'
module DreddHooks
describe Server::Buffer, private: true do
let(:message_delimiter) { "\t" }
let(:buffer) { described_class.new(message_delimiter) }
it { expect(buffer).to respond_to :<< }
it { expect(buffer).to respond_to :flush! }
it { expect(buffer).to respond_to :unshi... | true |
0f7640b446b46f2fc09145403ba547648a8fb1f8 | Ruby | kei500/twitter_utility | /bin/follow-follower-randomly | UTF-8 | 2,037 | 2.59375 | 3 | [] | no_license | #!/usr/bin/env ruby
$: << File.expand_path(File.join(__FILE__, '..', '..', 'lib'))
require 'optparse'
require 'logger'
require 'twitter_utility'
OPTIONS = {}
OptionParser.new do |opt|
opt.on('-s self_account_name', '--self_account_name', String) {|v| OPTIONS[:self_account_name] = v}
opt.on('-t target_accou... | true |
0f5a9187dc7e3ab9238b3da17f69f58a27c0a49a | Ruby | sainiboey/git_repository | /06_union.rb | UTF-8 | 362 | 4.0625 | 4 | [] | no_license | # Write a method, union, that accepts any number of arrays
# as arguments.
# The method should return an array containing all
#elements of the given arrays.
def union (*array1)
print array1
array1.flatten
end
p union(["a", "b"], [1, 2, 3]) # => ["a", "b", 1, 2, 3]
p union(["x", "y"], [true, false], [20, 21, 23])... | true |
1dd2070c6f7e346eefa90cc8283fcb29259a951c | Ruby | anantdimri96/transactions | /app/services/transaction_service/resultant_sum.rb | UTF-8 | 294 | 2.703125 | 3 | [] | no_license | module TransactionService
class ResultantSum
def initialize(transaction)
@transaction = transaction
end
def call
process_transaction
end
private
def process_transaction
@transaction.amount + @transaction.descendants.sum(:amount)
end
end
end | true |
bc5736c4e2761ba6be41d618c2e05109cc97f950 | Ruby | siruguri/railsschool-catchup-ruby | /level1/v2/homework/code_samples_1/sample_5.rb | UTF-8 | 1,310 | 4.71875 | 5 | [] | no_license | # This sample introduces a new array method called "select"
# Select is similar to each, in that it takes a block. The difference
# is that each looks at each element of an array, but doesn't create
# anything new - select will look at each element, and if the block
# returns true, will add that element to a new array... | true |
985fc3f17a4db1144fb2389646734ba51df9169e | Ruby | moa7ed/sf-movies | /app/models/movie.rb | UTF-8 | 908 | 2.59375 | 3 | [] | no_license |
class Movie < ApplicationRecord
has_and_belongs_to_many :locations, -> { distinct }
has_and_belongs_to_many :actors, -> { distinct }
has_and_belongs_to_many :production_companies, -> { distinct }
def self.filter (title, director, writer, actor, production_company)
movies = Movie.all.includes(:actors, :pr... | true |
1668bf60a31af0976b2a48de10f585bd33f58bd7 | Ruby | coolbrg/progfun | /ruby_metaprogramming/course_day1/class_method_demo.rb | UTF-8 | 648 | 3.40625 | 3 | [] | no_license | # Phase 1
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
end
ClassMethodDemo.greet
# Phase 2
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
ClassMethodDemo.greet
end
# Phase 3
class ClassMethodDemo
def self.greet
puts "Hello, Ruby"
end
greet
end
# Phase 4
clas... | true |
c6579c4bdbb38e897ee6cc0461b1145c63025d27 | Ruby | BJSummerfield/Projecteuler | /problem68.rb | UTF-8 | 1,680 | 3.15625 | 3 | [] | no_license | list = Array(1..10)
end_nodes = 5
def runner(list, end_nodes)
total = find_max(list, end_nodes)
possible_routes = create_node_routes(list, end_nodes, total)
poly = create_poly(end_nodes)
answer = place_node(possible_routes, poly, total, end_nodes)
p answer.flatten.join
end
def create_poly(end_nodes)
retur... | true |
0a56277c9057035f837978e0d91924a07c8cbe73 | Ruby | sheg/fuzzyrip | /app/helpers/pick_helper.rb | UTF-8 | 282 | 2.8125 | 3 | [] | no_license | module PickHelper
def convert_total_pick(pick_total)
round = ((pick_total - 1) / 12) + 1
pick = pick_total - (round - 1)*12
"#{round}.#{pick}"
end
def filter_position(players, position)
players.select { |player| player.position.name == position }
end
end | true |
18b2075f01150fef03f3abc0ff8c7b52fb02583e | Ruby | pocari/pocarisp | /tokenizer_test.rb | UTF-8 | 2,920 | 2.890625 | 3 | [] | no_license | require 'pry-byebug'
require 'minitest/autorun'
require_relative 'tokenizer'
class TokenizerTest < MiniTest::Test
def test_read_number
tk = Tokenizer.new("123")
token = tk.next
assert_equal :tk_num, token.type
assert_equal 123, token.value
end
def test_read_str
tk = Tokenizer.new('"this is... | true |
badb3d708f40e5a6f6602d62919df05c36fd0090 | Ruby | krwood90/sep-assignments | /01-data-structures/07-graphs/bacon_graph.rb | UTF-8 | 775 | 3.171875 | 3 | [] | no_license | require_relative 'node'
class Graph
def find_kevin_bacon(start)
queue = []
found = false
queue.push(start)
while(queue.size != 0)
node = queue.shift
node.film_actor_hash.each do |movie, actor_nodes|
if !start.path_array.include?(movie)
start.path_array.push(movie)
... | true |
cf7b3558fe382d847fbaceebce55544d3eaf4f7e | Ruby | landongrindheim/exercises | /nth-prime/nth_prime.rb | UTF-8 | 368 | 3.484375 | 3 | [] | no_license | class Prime
def self.nth(num)
Nth.prime_at(num)
end
end
class Nth
def self.prime_at(num)
raise ArgumentError if num < 1
prime_generator.first(num).last
end
private
def self.prime_generator
(2..Float::INFINITY).lazy.reject {|prime_candidate| (2..Math.sqrt(prime_candidate)).any? {|facto... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.