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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
d77609dd35972de4097d72807a4c4e465606d04d | Ruby | Jeremy-Barrass/boris_bikes | /lib/dockingStation.rb | UTF-8 | 283 | 3 | 3 | [] | no_license | class DockingStation
attr_reader :bikes
def initialize(bikes = [])
@bikes = bikes
end
def release_bike
if bikes.empty?
raise "No bikes are available."
else
Bike.new
end
end
def dock_bike(bike)
bikes << bike
@bikes.count
end
end
| true |
ff9e47a2960e6fe6ba935319bef10abcd6cee7db | Ruby | companygardener/lookup_by | /lib/lookup_by/caching/lru_legacy.rb | UTF-8 | 926 | 2.65625 | 3 | [
"MIT"
] | permissive | module LookupBy
module Caching
class LRU
def max_size=(size)
raise ArgumentError.new(:max_size) if size < 1
@max_size = size
if @max_size < @data.length
@data.keys[0..@max_size-@data.size].each do |key|
@data.delete(key)
end
end
end
... | true |
1edc169fe89d24984dde9f6d5a3bf835fecbb4a7 | Ruby | luiseduardohdbackup/ruby-mongrel2 | /lib/mongrel2/handler.rb | UTF-8 | 11,254 | 2.75 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'zmq'
require 'loggability'
require 'mongrel2' unless defined?( Mongrel2 )
require 'mongrel2/config'
require 'mongrel2/request'
require 'mongrel2/httprequest'
require 'mongrel2/jsonrequest'
require 'mongrel2/xmlrequest'
require 'mongrel2/websocket'
# Mongrel2 Handler application class. I... | true |
88eee44f6165c89d7ff4b0f393ae0fc9120d61fa | Ruby | rohrmanj/HarryPotterKata | /spec/harry_potter_spec.rb | UTF-8 | 243 | 2.65625 | 3 | [] | no_license | require './harry_potter.rb'
describe HarryPotter do
it 'cost 8 for one book' do
expect(subject.calc_price(1,0,0,0,0)).to eq 8
end
it 'cost 16 for 2 of the same book' do
expect(subject.calc_price(2,0,0,0,0)).to eq 16
end
end
| true |
bd009c8b0223f677a04a81b1bbc9398f8600fafc | Ruby | KaminKevCrew/Jumpstart_Lectures | /methods_and_conditionals.rb | UTF-8 | 7,764 | 4.46875 | 4 | [] | no_license | # Warm-up!
# help me construct a boolean statement that checks if a string is even length
# str1 = "Jumpstart" # false (odd length)
# str2 = "Demon Slayer" # true (even length)
# str3 = "TzTok-Jad" # false (odd length)
# puts str1.length % 2 == 0
# puts str2.length % 2 == 0
# puts str3.length % 2 == 0
... | true |
f16be6ed3672b32b2a825fac813b6ed1151b0b35 | Ruby | EliahKagan/crystal-sketches | /captures.rb | UTF-8 | 167 | 2.5625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"0BSD"
] | permissive | #!/usr/bin/env ruby
# frozen_string_literal: true
$VERBOSE = 1
actions = []
(1..5).each { |i| actions << ->{ puts "#{i} squared is #{i**2}." } }
actions.each &:call
| true |
05a4ce9968da810c4c48ff8745c13b8fb06f1d34 | Ruby | devrandom/rkv | /lib/rkv/store/tokyocabinet_adapter.rb | UTF-8 | 2,954 | 2.671875 | 3 | [] | no_license | require 'rubygems'
require 'tokyocabinet'
module Rkv
module Store
class TokyocabinetAdapter < BaseAdapter
attr_accessor :recurse
def self.open(opts)
self.new(opts)
end
def tc_raise
ecode = @bdb.ecode
raise "TokyoCabinet - #{@bdb.errmsg(ecode)}"
end
... | true |
84ec576af16aae96f5428a985cf6f5fab231cd4c | Ruby | r-wataru/circle | /question2.rb | UTF-8 | 1,441 | 3.875 | 4 | [] | no_license | # coding: utf-8
# n(L) = L × (L - 1) + 1
# N(X) = {1,2,3,...,n(L)}
# 解答が存在しない場合「Nothing」
require 'pp'
class Circle
def initialize(l)
@n = l * (l - 1) + 1
@sums = []
@n.times do |nn|
@sums << nn + 1
end
@answers = []
answer
end
def arr_count
arr1 = []
@sums.each_with_inde... | true |
5d3a66d0bdd0ef8ddb16c65c980d97bc9d8381ed | Ruby | byung-u/HackerRank | /Ruby/Enumerable/introduction.rb | UTF-8 | 126 | 2.890625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
def iterate_colors(colors)
colors.map {|color| color}
end
iterate_colors(['Red', 'Green', 'Blue'])
| true |
29e783d3b25fca60986ce517faf9debc83a7f73d | Ruby | esposama/crcp2330 | /06/parser.rb | UTF-8 | 1,171 | 3.5 | 4 | [] | no_license | require_relative 'code'
class Parser
def initialize(assembly_instructions)
@assembly_instructions = assembly_instructions
@machine_instructions = []
@codez = Code.new()
end
def parse
@assembly_instructions.each do |instruction|
if command_type(instruction) == :a_command
@machine_instructions << a... | true |
559a5f92101fa08f19c6dc3bfe56d1cb64cefb6c | Ruby | oliveira-andre/it_crowd_test | /api/app/models/concerns/convert_to_roman.rb | UTF-8 | 460 | 3.453125 | 3 | [] | no_license | # frozen_string_literal: true
module ConvertToRoman
# i got this code by stack overflow https://codereview.stackexchange.com/questions/7937/roman-numeral-converter
# coz i didn't know how roman numbers works, but reading this code i learned it
def roman(year)
return '' if year.zero?
ROMAN_NUMBERS.each d... | true |
c568d3141c53fdefaaebffeee065a6324a366cae | Ruby | benjlcox/data_structures_and_algorithms | /coursera/01 Union-Find/social_network.rb | UTF-8 | 1,887 | 3.71875 | 4 | [] | no_license | #Social network connectivity. Given a social network containing N members and a log file containing M timestamps at which times pairs of members formed friendships, design an algorithm to determine the earliest time at which all members are connected (i.e., every member is a friend of a friend of a friend ... of a frie... | true |
7899c70db1435cc1270c6c3910a94f9e81a8df99 | Ruby | HirenBhalani/My-Pro | /9.rb | UTF-8 | 314 | 2.828125 | 3 | [] | no_license | days = "Mon Tue Wed Thu Fri Sat Sun"
months="Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
puts "Here are the days: ",days
puts "Here are the months: ",months
puts <<PARAGRAPH
There's something going ong here.
With the PARAGRAPH thing we'll
be able as much as we like.
Even 4 lines if we want, or 5,or 6.
PARAGRAPH | true |
dfe69520ceb069f0f3e816ba874c3e1e62168b85 | Ruby | ericabasak/ruby-enumerables-hash-practice-emoticon-translator-lab-nyc-web-091619 | /lib/translator.rb | UTF-8 | 966 | 3 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "yaml"
def load_library(path)
h = YAML.load_file(path)
result = {
'get_emoticon' => {}
}
h.each do |k,v|
if result['get_meaning'].nil?
result['get_meaning'] = {}
end
if result['get_meaning'][k].nil?
result['get_meaning'][v[1]] = k
end
end
h.each do |k,v|
i... | true |
2232351a6422bd333b6adfee51a9948db46d30eb | Ruby | phoorichet/wheretomigrate | /app/controllers/cities_controller.rb | UTF-8 | 4,205 | 2.640625 | 3 | [] | no_license | class CitiesController < ApplicationController
# GET /cities
# GET /cities.json
def index
@cities = City.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @cities }
end
end
# GET /cities/1
# GET /cities/1.json
def show
@city = City.find(params... | true |
487a8d2f5591de62d53ca6dd5e85a504101fa93c | Ruby | mespealva/arreglos | /visitas.rb | UTF-8 | 165 | 2.78125 | 3 | [] | no_license | vis=[]
#vis=[1000, 800, 250, 300, 500, 2500]
def promedio(a)
sum = 0
a.each do |i|
sum += i
end
return sum.to_f / a.length
end
promedio(vis) | true |
da94ef9594b3aca45ff81d3f71244ba93cb93b58 | Ruby | kiriakosv/gitlang | /lib/gitlang/organization.rb | UTF-8 | 1,639 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'gitlang/github_stats'
require 'gitlang/repository'
require 'gitlang/utilities'
module Gitlang
# Class representing a GitHub organization
class Organization
include Gitlang::GithubStats
include Gitlang::Utilities
attr_reader :name, :repositories
def initialize(name, client)
@name = ... | true |
84fb4b91d3927abf9c333458cc5e267c62be0595 | Ruby | SamLau95/send-the-workers | /app/models/testimony.rb | UTF-8 | 626 | 2.6875 | 3 | [] | no_license | # == Schema Information
#
# Table name: testimonies
#
# id :integer not null, primary key
# name :text
# summary :text
# content :text
# created_at :datetime
# updated_at :datetime
#
class Testimony < ActiveRecord::Base
has_many :image_urls
has_one :video_url
validates :name,... | true |
f1b82b6bbde5e9b43e55143d58d31105afcee35e | Ruby | andreif/input-processors | /SerpentInput.rb | UTF-8 | 5,879 | 2.828125 | 3 | [
"MIT"
] | permissive |
class Serpent::Input
def initialize #path=nil
@nests, @surfaces, @materials, @universes, @lattices, @cells, @parameters, @comments = Array.new(10) {{}}
#@comments[:file] = path
#if path_or_text =~ /\n/
#Parser.new(path, self)
end
def get card
type, id = card.keys.first, card.values.fi... | true |
95060a54dc9a33a1b6f977d8b5670b327ebf3ad9 | Ruby | jm96441n/phase-0 | /week-8/ruby_review.rb | UTF-8 | 6,483 | 4.25 | 4 | [
"MIT"
] | permissive | # Cipher Challenge
# I worked on this challenge [by myself, with:]
# I spent [#] hours on this challenge.
# 1. Solution
# Write your comments on what each thing is doing.
# If you have difficulty, go into IRB and play with the methods.
# def dr_evils_cipher(coded_message)
# input = coded_message.downcase.split("")... | true |
b6454bc888346eb7d582d3680298a5e987972ccb | Ruby | wmleidy/advent-of-code-ruby | /solutions/10-elves-look-and-say.rb | UTF-8 | 876 | 3.90625 | 4 | [] | no_license | # My SLOW solution (made considerably faster by using << instead of + to combined strings)
def look_and_say_wrapper(input, iterations = 40)
iterations.times do |x|
input = look_and_say(input)
end
input.to_s.length
end
def look_and_say(input)
old_str = input.to_s
new_str = ""
prev = ""
count = 0
i ... | true |
ef53744145f7ceabfe3d5968de5ebcf29dbcdcd3 | Ruby | mattybrown/vms | /app.rb | UTF-8 | 1,113 | 2.546875 | 3 | [] | no_license | require "sinatra"
require "sinatra/activerecord"
set :database, "sqlite3:vms.db"
class Vehicle < ActiveRecord::Base
has_many :costs, dependent: :destroy
end
class Cost < ActiveRecord::Base
belongs_to :Vehicle
end
get "/" do
@vehicles = Vehicle.order("created_at DESC")
erb :"vehicle/index"
end
get "/vehicles... | true |
3b1ce4414d3cb4988d6407e79841696f878203a0 | Ruby | hderms/ruby_in_the_mud | /lib/ruby_in_the_mud/entity_instance.rb | UTF-8 | 915 | 2.9375 | 3 | [
"MIT"
] | permissive | class EntityInstance
include LifecycleNotification
# basic attributes all entities have
attr_accessor :hp, :loot, :name
def initialize(name, lifecycle_block)
@name = name
@loot = []
@hp = 0
# use the lifecycle block passed to its template to configure a particular instance
instance_exec(&lif... | true |
b814356714795cd7b9076dbac7723b2f706b6145 | Ruby | PhilippePerret/Proximites | /lib/module/prox/control/main.rb | UTF-8 | 569 | 2.875 | 3 | [] | no_license | # encoding: UTF-8
class Prox
class << self
# = main =
#
# Méthode principale qui check les données
#
def data_control
puts Tests.delimiteur_tableau
# Contrôle des fichiers produit. Cf. files.rb
control_files || return
puts Tests.delimiteur_tableau
end
# Méthode principale à appeler po... | true |
33a9d7498864cf0d997ffd18bd588d7b1122881c | Ruby | fuji-nakahara/fuji_markdown | /lib/fuji_markdown/processor.rb | UTF-8 | 690 | 2.703125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'commonmarker'
module FujiMarkdown
class Processor
def initialize(preprocessors: [], postprocessors: [], renderer: CommonMarker::HtmlRenderer.new)
@preprocessors = preprocessors
@postprocessors = postprocessors
@renderer = renderer
end
def ... | true |
4db878aad1494eb83b38df3274241ff03cc046a6 | Ruby | subhranildey/resque-rails-god-example | /lib/sample_job.rb | UTF-8 | 151 | 2.640625 | 3 | [] | no_license | class SampleJob
@queue = :low
def self.perform(value)
p 'SampleJob start'
p "value: #{value}"
sleep 1
p 'SampleJob end'
end
end
| true |
33924432c53c13743005ef121d4f279bd293bd11 | Ruby | bogdan-zaharia/TicTacToe | /spec/unit/play_game_spec.rb | UTF-8 | 1,504 | 3.25 | 3 | [] | no_license | describe PlayGame do
it "can print out the outcome of the game on the screen" do
game = PlayGame.new
#expect { game.execute }.to output.to_stdout
expect { game.display_winner(:draw) }.to output("DRAW!\n").to_stdout
expect { game.display_winner(:aiwins) }.to output("AI WINS!\n").to_stdout
expect {... | true |
7936bee0beb9ab4ab028eacb9f5f02ebbf209a03 | Ruby | ashu1061/tcp_server | /tcp_server.rb | UTF-8 | 2,863 | 2.921875 | 3 | [] | no_license | require "socket"
requests={}
server = TCPServer.new('localhost', 8080)
def request socket, requests, connId, timeout #handling response of /api/request
Thread.current['startTime'] = Time.now #storing required information for each request in thread variable
Thread.current['timeout']=timeout
Thread.current['socket... | true |
0ecee8686f1d29267b780e0b0f3508a878a566ce | Ruby | dgrald/FlingSolver | /board.rb | UTF-8 | 5,191 | 3.859375 | 4 | [] | no_license | require_relative 'directions'
require_relative 'furball'
require_relative 'move'
require_relative 'state'
class Board
attr_reader :board
COLUMNS = 5
ROWS = 5
def initialize(board)
unless board.is_a? Array
raise ArgumentError, "Board must be an instance of an Array but was a #{board.class.to_s}"
... | true |
9dedb5c3beb39019d2fe3fb2d283c0b8d0d43b60 | Ruby | marcelobarbosaO/avaliacao_desenvolvedor | /app/services/create_sale_service.rb | UTF-8 | 760 | 2.53125 | 3 | [] | no_license | class CreateSaleService
attr_reader :sale
def initialize(params:)
@params = params
@sale = Sale.new(sale_params)
@customer = Customer.find_or_create_by(name: params[:customer_name])
@address = Address.find_or_create_by(name: params[:address])
@vendor = Vendor.find_or_create_by(n... | true |
f972cbab0ca884dfb2bd4da4aa68d060a69dfef2 | Ruby | michaelpmattson/flash_cards | /lib/round.rb | UTF-8 | 1,061 | 3.65625 | 4 | [] | no_license | # frozen_string_literal: true
# Stores and performs actions on Deck Object, turns as array, and current card.
class Round
attr_reader :deck, :turns, :current_card
def initialize(deck)
@deck = deck
@turns = []
@current_card = deck.cards.first
end
def take_turn(guess)
turn = Turn.new(guess, @cu... | true |
932f97c0d90159ff6f940fce15dd43382e586876 | Ruby | Lebeil/tests-ruby | /lib/06_pig_latin.rb | UTF-8 | 374 | 3.25 | 3 | [] | no_license | def translate(str)
arr = str.split
arr.each do |string|
i = (/[aeiou]/ =~ string)
if i != 0 && string[i-1..i] != "qu"
string << string[0..i-1] << "ay"
string.slice!(0..i-1)
elsif i != 0 && string[i-1..i] == "qu"
string << string[0..i] << "ay"
string.slice!(0..i)
else
st... | true |
1ee87256d2f726891b4d5d019461a790ad7b25e3 | Ruby | woobaik/Alorithm_Practice | /hackerrank/plus_minus.rb | UTF-8 | 529 | 3.578125 | 4 | [] | no_license | #!/bin/ruby
require 'json'
require 'stringio'
# Complete the plusMinus function below.
def plusMinus(arr)
leng = arr.length.to_f
result = [0,0,0]
arr.each do |num|
if num > 0
result[0] += 1
elsif num < 0
result[1] += 1
else
result[2] += 1
... | true |
94815a1ae5d888d87ce59cb4f4eb5d55d457ad59 | Ruby | atecdeveloper/ruby_lessons | /hashes/exercise3.rb | UTF-8 | 288 | 3.78125 | 4 | [] | no_license | hash = { Andre: "32", Luiz: "22" }
puts hash.keys
#or hash.each_key { |key| puts key }
puts hash.values
#or hash.each_value { |value| puts value }
hash.each { |key, value| puts "#{key}'s age is #{value}" }
#puts "#{hash.keys.first}'s age is #{hash.values.first}" getting a single row
| true |
86effb17318040350afffd1af3a18b2671744a0c | Ruby | sds/scss-lint | /lib/scss_lint/linter/variable_for_property.rb | UTF-8 | 1,218 | 2.734375 | 3 | [
"MIT"
] | permissive | module SCSSLint
# Reports the use of literals for properties where variables are prefered.
class Linter::VariableForProperty < Linter
include LinterRegistry
IGNORED_VALUES = %w[currentColor inherit initial transparent].freeze
def visit_root(_node)
@properties = Set.new(config['properties'])
... | true |
f54795bbb93d07fd078165834a48d33e53bb6fbc | Ruby | NathanyApSalles/Ruby-on-Rails | /app/models/pontuation.rb | UTF-8 | 743 | 2.796875 | 3 | [] | no_license | require 'csv'
class Pontuation < ApplicationRecord
attr_reader :data, :nome, :idUsuario, :pontos
@pontuacoes = []
def self.read_file(adicionado)
#caso seja adicionado, o arquivo deve ser lido e inserido no banco
unless (adicionado.empty?)
CSV.foreach(adicionado[0], col_sep: ';').with... | true |
e3fcb1b2a9faf284d4f52353b4dac882a48299d1 | Ruby | joevandyk/authorize-net | /lib/authorize_net/payment_methods/echeck.rb | UTF-8 | 2,641 | 2.6875 | 3 | [] | no_license | module AuthorizeNet
# Defines constants for each payment method type.
module PaymentMethodType
ECHECK = 'ECHECK'
end
# Models an eCheck.
class ECheck
PAYMENT_METHOD_CODE = AuthorizeNet::PaymentMethodType::ECHECK
# Defines constants for each bank account type.
module AccountType
... | true |
86d610812391be184b4bf1f771ada2beb92dde60 | Ruby | hugochougt/wx_customs | /lib/wx_customs/sign.rb | UTF-8 | 1,448 | 2.609375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "digest/md5"
module WxCustoms
# :nodoc:
module Sign
SIGN_TYPE_MD5 = "MD5"
# Generate signature of parameters
#
# @see https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=4_5&index=3
# @raise [ArgumentError] Error raised when `sign_ty... | true |
95d57f4160742c1fb8dde273f3382a9aff5de570 | Ruby | LipeiYang/demo2 | /app/models/criteria_order.rb | UTF-8 | 834 | 2.5625 | 3 | [] | no_license | class CriteriaOrder
include Modules::Criteria::TermDateRange,
Modules::Criteria::TermCustomer,
Modules::Criteria::TermProduct,
Modules::Criteria::TermPaied
def initialize(*arg)
arg.empty? ? init_default : init_params(arg[0])
end
def init_default
init_date_range Date.today-1.day, Date.toda... | true |
c7ea187708f56e0f18e465d4cc90ed56e7b3a507 | Ruby | WilmarvanDijk/basic-ruby-projects | /bubble-sort/bubble-sort.rb | UTF-8 | 453 | 3.515625 | 4 | [] | no_license | def bubbleSort(sortingArray)
sortFlag = false
until sortFlag
sortFlag = true
sortingArray[0, (sortingArray.length - 1)].each_with_index do |elm, idx|
if sortingArray[idx] > sortingArray[idx + 1]
sortFlag = false
sortingArray[idx], sortingArray[idx +... | true |
752c6a40fc6ef9712bb058bf86747871d80cea24 | Ruby | jhavaldar/PE | /euler65.rb | UTF-8 | 397 | 3.453125 | 3 | [] | no_license | def b(n)
if n == 0
return 2
end
case (n % 3)
when 0
return 1
when 1
return 1
when 2
return 2*((n+1)/3)
end
end
def conv(i)
a0 = 2
a1 = 3
n = 2
while n < i
x = (b(n))*a1 + a0
a0 = a1
a1 = x
n += 1
end
return a1
end
def digit_sum(n)
return n.t... | true |
447624550688a5d9b25152d46ed71dd5631d4b1e | Ruby | szymko/taskmaster | /spec/lib/parse_strategies/obligatory_optional_strategy_spec.rb | UTF-8 | 508 | 2.53125 | 3 | [] | no_license | require_relative './../../spec_helper'
describe ObligatoryOptionalStrategy do
describe "#parse" do
let(:html_body) { "<html><body><h1>Header1</h1><div><p>Paragraph 1</p><p>Paragraph 2</p></div><h2>Header 2</h2></body></html>" }
it "extracts text according to supplied paths" do
@strat = ObligatoryOpt... | true |
e11e9da90c72e2fcd3d3e95210af4dd0475e0403 | Ruby | team-umlaut/umlaut | /bin/umlaut | UTF-8 | 4,128 | 2.703125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# This is a command line executable installed as part of the umlaut gem.
# All it does is install a new umlaut rails app, by simply running
# 'rails new' with certain arguments, and the umlaut rails application
# template. The rails application template basically just runs the
# umlaut generator... | true |
9109808547e63541d51314c0b23c297578c669ba | Ruby | quocl/brainfint | /src/brainfuck.rb | UTF-8 | 2,845 | 3.984375 | 4 | [] | no_license | # Brainfuck interpreter in ruby 1.9.3
# There are 8 valid commands in brainfuck, which are: '>', '<', '+', '-', '.',',', '[' and ']'
# Author: Quoc Le
class Brainfuck
SIZE = 30000
def initialize(input="")
# initialize the brainfuck interpreter
@data = Array.new(SIZE,0) # data
@pos = 0 # data pointer
... | true |
7f425ce21bf7c0c2ccc457962e156892a9d0caf9 | Ruby | jlotrug/oo-banking-v-000 | /lib/transfer.rb | UTF-8 | 818 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Transfer
attr_accessor :sender, :receiver, :amount, :status
# your code here
def initialize(sender, reciever, amount)
@sender = sender
@receiver = reciever
@amount = amount
@status = "pending"
end
def valid?
@sender.valid? && @receiver.valid?
end
def execute_transaction
@initial_amount = @amount... | true |
4a6b3d531c8af2818eda685b261eecf3ef111005 | Ruby | rshiva/MyDocuments | /10-book-case/ruby1.9/samples/exttk_9.rb | UTF-8 | 686 | 2.59375 | 3 | [] | no_license | #---
# Excerpted from "Programming Ruby",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www... | true |
2798fe726b3dabc6203b0204dbaa5e100806b37e | Ruby | ysabelm/rspec-fizzbuff | /fizz_buzz.rb | UTF-8 | 281 | 4 | 4 | [] | no_license | class FizzBuzz
def numbers
(1..100).to_a
end
def fizzify(numb)
if numb%5 == 0 && numb%3 == 0
"FizzBuzz"
elsif numb%5 == 0
"Buzz"
elsif numb%3 == 0
"Fizz"
else
numb
end
end
def result
numbers.map do |number|
fizzify(number)
end
end
end | true |
9ad7b12fb6129dc6251d23e540fc8739ba3d0ada | Ruby | jumichot/Everydays | /Dojo/haiku_review/haiku_review_spec.rb | UTF-8 | 1,031 | 3.625 | 4 | [] | no_license | class HaikuReview
attr_accessor :sentences
def initialize input
raise ArgumentError.new("This is not a string") unless input.is_a? String
@sentences = input.split("/")
end
class << self
def is_vowel letter
raise ArgumentError.new("This is not a character") if letter.length != 1
return ('aeiouy')... | true |
e6b9aba45c8e3f13b64af852b0ef8d1e560c59cf | Ruby | esquilo-azul/eac_ruby_utils | /spec/lib/eac_ruby_utils/common_constructor_spec.rb | UTF-8 | 3,774 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'eac_ruby_utils/common_constructor'
RSpec.describe ::EacRubyUtils::CommonConstructor do
ARG_LIST = %i[a b c d].freeze # rubocop:disable RSpec/LeakyConstantDeclaration
let(:instance) do
described_class.new(*ARG_LIST, default: %w[Vcc Vd]) do
@z = 'Vz'
end
end
... | true |
9f7a38efebc01453949ac0144d1d97782e1532b6 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/98b785c69eae4c538d6c49e6742b01b7.rb | UTF-8 | 286 | 3.765625 | 4 | [] | no_license | class Bob
def hey(words)
words = words.gsub(/[0-9]/, "")
if words =~ /^\s*$/
'Fine. Be that way!'
elsif words[-1].chr == '?' && words != words.upcase
'Sure.'
elsif words == words.upcase
'Whoa, chill out!'
else
'Whatever.'
end
end
end
| true |
8878bc66f8904509deb10c80b87423a973390e63 | Ruby | MDes41/pizza_parlor | /lib/toppings_menu.rb | UTF-8 | 360 | 2.90625 | 3 | [] | no_license | require 'csv'
require_relative 'topping'
class ToppingMenu
def load_data(data)
contents = CSV.open data, headers: true, header_converters: :symbol
@all = contents.to_a.map {|row| row.to_hash}
end
def find_by_name(inputed_name)
matching_line = @all.find {|line| line[:name].downcase == inputed_name}
... | true |
f5919fa1fa9b57c28d0ff4e558d2855176bf8cb9 | Ruby | porawiec/ruby-enumerables-hash-practice-emoticon-translator-lab-chicago-web-111819 | /lib/translator.rb | UTF-8 | 863 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # require modules here
require 'pp'
require "yaml"
def load_library(file_path)
emotes = {"get_meaning" => {}, "get_emoticon" => {} }
YAML.load_file(file_path).each do | meaning, ej_array |
english, japanese = ej_array
emotes["get_meaning"][japanese] = meaning
emotes["get_emoticon"][english] = japanese
... | true |
ea0c550b4cbb18526e1b538a6ca474fd21a7a057 | Ruby | Ghalip701/Terminal-App | /src/user_class.rb | UTF-8 | 6,869 | 4.15625 | 4 | [] | no_license | require "json"
require "colorize"
#Creating a user class. This will have varoius funcions in it, and will use recursion to go through all necessary functions. It can be called using 'login_screen' which will go through the functions and bring the user of the app to the class
class User
attr_accessor :name, :usern... | true |
f497a307473a1d3b8f8dae93dee23667a0fa0e3d | Ruby | michaelstucki/ruby_programming | /6_methods/lecture.rb | UTF-8 | 253 | 3.140625 | 3 | [] | no_license | def weekday
Time.new.strftime("%A")
end
def movie_listing(title, rank=0)
"#{weekday.upcase}: #{title.capitalize} has a rank of #{rank}."
end
puts movie_listing("goonies", 10)
puts movie_listing("ghostbusters", 9)
puts movie_listing("goldfinger")
| true |
f90a5f649f3824c0266adcddff4a67670c29798f | Ruby | inomar/puzzle | /ruby/q04.rb | UTF-8 | 168 | 3.46875 | 3 | [] | no_license | def cutbar(m,n,current)
if current >= n
0
elsif current < m
1 + cutbar(m,n,current*2)
else
1 + cutbar(m,n,current + m)
end
end
puts cutbar(3,20,1) | true |
1a5212e32a79bf1cf429f820feea5f61fb660c76 | Ruby | zoeKD/womentor | /app/models/mentor_search/single_criteria.rb | UTF-8 | 1,018 | 2.90625 | 3 | [] | no_license | class MentorSearch
class SingleCriteria
# @param query_field [String] table_name.field_name to compare to the criteria
# @param criteria [String] matching value for the query_field
# @param score_name [String] name of the field in the SQL query
def initialize(query, query_field, criteria, score_name)... | true |
214ba49a0de8f91249ae9c1965e504750f718cda | Ruby | wilsonokibe/BasicRuby | /inverse_case/bin/main.rb | UTF-8 | 135 | 2.921875 | 3 | [] | no_license | require_relative "../lib/string.rb"
puts "Enter anything and i will swap it's case"
input = gets.chomp
input = input.to_s
puts input
| true |
3b025ca2e0869838bfad010298d81e28f4b4b2bf | Ruby | dougvidotto/launchschoolprojects | /prepcourses/intro_programming_ruby/more_stuff/divide.rb | UTF-8 | 337 | 3.84375 | 4 | [] | no_license | def divide (first_number, second_number)
begin
result = first_number / second_number
puts "#{first_number} divided by #{second_number} is #{result}"
rescue ZeroDivisionError => e
puts "Error dividing #{first_number} by #{second_number}"
puts e.message
end
end
divide(4, 2)
divide(10,... | true |
1d612d8410e05ce00a7f915f7fbbfca77cdbcab3 | Ruby | amellors/gamenight | /app/models/normal_stats.rb | UTF-8 | 517 | 3.0625 | 3 | [
"MIT"
] | permissive | class NormalStats
def initialize (wins)
@wins = wins
@winner_count = Hash.new
@wins.each do |win|
if @winner_count[win.winner.name]
@winner_count[win.winner.name] += 1
else
@winner_count[win.winner.name] = 1
end
end
# @winner_count = @winner_count.sort {|a,b| b[1... | true |
c0986a758a5ad80d8c6ccd859b5825b29a11db83 | Ruby | igneus/ordodo | /lib/ordodo/tree_calendar.rb | UTF-8 | 2,188 | 2.609375 | 3 | [
"MIT",
"LicenseRef-scancode-public-domain"
] | permissive | module Ordodo
class TreeCalendar
def initialize(year, sanctorale_tree, temporale_extensions, temporale_options)
@year = year
temporale_options_always =
temporale_options[:always]&.dup || {}
temporale_options_always[:extensions] = temporale_extensions
@temporale =
Calendar... | true |
ce0fac0920b582eaf44c7e9a8d2fce335e646e55 | Ruby | punnadittr/chess | /spec/chess_spec.rb | UTF-8 | 3,369 | 3.03125 | 3 | [] | no_license | require "spec_helper.rb"
require "chess_board"
describe King do
before(:each) do
@mygame = Game.new
@myboard = Board.new
end
before(:each) { @myboard.board[3][3] = King.new(3,3) }
describe ".king_legal_moves" do
context "given normal case (no pieces intervene)" do
before { @mygame.select '... | true |
d71db7819571fe079006e8d1148b53f9a04e389b | Ruby | GDemps/real_estate_2005 | /lib/room.rb | UTF-8 | 373 | 3.515625 | 4 | [] | no_license | class Room
attr_reader :category,
:length,
:width
def initialize(category, length = 10, width)
@category = category
@length = length
@width = width.to_i
@paint_status = false
end
def area
@length * @width
end
def is_painted?
@paint_status == true
end... | true |
8fa1e9e177a4103f68bf96f19b199c23848e79e0 | Ruby | jasonlhoward/ls-101-lesson-6 | /21.rb | UTF-8 | 7,174 | 3.3125 | 3 | [] | no_license | SUITS = { 'hearts' => "1F0B",
'diamonds' => "1F0C",
'clubs' => "1F0D",
'spades' => "1F0A" }
RANKS = { 'ace' => { value: 1, code: '1' },
'2' => { value: 2, code: '2' },
'3' => { value: 3, code: '3' },
'4' => { value: 4, code: '4' },
'5' => { value: 5,... | true |
bdad24cb9d84e4a8492f0b2adf79f16ac0e522b7 | Ruby | cfong57/bloccit | /app/models/post.rb | UTF-8 | 2,167 | 2.84375 | 3 | [] | no_license | class Post < ActiveRecord::Base
has_many :comments, dependent: :destroy
has_many :votes, dependent: :destroy
has_many :favorites, dependent: :destroy
belongs_to :user
belongs_to :topic
attr_accessible :body, :title, :topic, :image
after_create :create_vote
#after_create :send_favorite_emails
mount_u... | true |
0b6759fee860d91c6eddfc96ad938ffd9adba550 | Ruby | TakutoRU/open-plaques-3 | /spec/models/person_spec.rb | UTF-8 | 11,796 | 2.8125 | 3 | [] | no_license | require 'spec_helper'
describe Person do
describe '#full_name' do
context 'a person' do
before do
@person = Person.new(name: 'John Smith')
end
it 'has their name displayed as-is' do
expect(@person.full_name).to eq('John Smith')
end
end
context 'a Baronet' do
... | true |
44927ab0379175e12c170373fdfd835b4e92bb8e | Ruby | kjs222/sorting | /test/bubble_sort_test.rb | UTF-8 | 1,185 | 3.296875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require_relative '../lib/bubble_sort.rb'
class BubbleSortTest < MiniTest::Test
def test_sorts_2_element_array
bubble = SortingSuite::BubbleSort.new
array1 = [2, 1]
assert_equal [1, 2], bubble.sort(array1)
array2 = [1, 2]
assert_equal [1, 2], ... | true |
b97fca7f7a71e65840e1399e8531ad2d90f605cc | Ruby | christianrojas/drawing_tool | /lib/drawing_tool.rb | UTF-8 | 4,309 | 3.484375 | 3 | [
"MIT"
] | permissive | require 'drawing_tool/version'
require 'drawing_tool/canvas'
require 'thor'
require 'terminal-table'
module DrawingTool
class Cli < Thor
desc 'new', 'This will create a new drawing instance.'
def new
draw_canvas
loop do
cmd = ask 'enter command:'
cmd = cmd.split(' ')
case... | true |
2bdaa00fb47de6cfb4a53b015d5d6fde4d132887 | Ruby | askrynnikov/samurai | /lesson_01/04_quadratic_equation.rb | UTF-8 | 728 | 3.484375 | 3 | [] | no_license | puts 'Решение квадратного уравнения ax2 + bx + c = 0'
puts 'Введите первый коэффициент "a"'
a = gets.to_f
puts 'Введите второй коэффициент "b"'
b = gets.to_f
puts 'Введите свободнй член "c"'
c = gets.to_f
d = b**2 - 4 * a * c
result =
if d < 0
"Уравнение действительных решений не имеет."
elsif d == 0
"Од... | true |
8e350106a9b926f0c3a8f9de9f1121d79bcd0c4c | Ruby | akolanko/RubyObjects | /student.rb | UTF-8 | 897 | 3.0625 | 3 | [] | no_license | class Student
attr_accessor :firstName
attr_accessor :lastName
attr_accessor :gender
attr_accessor :school
attr_accessor :gpa
def study
puts "study"
end
def do_homework
puts "do homework"
end
def take_test
puts "take test"
end
end
class CollegeStudent < Student
attr_accessor :major
attr_accessor... | true |
6af414003c9b0884fe98dc3f6b8ae515b778b717 | Ruby | shogooooooo/fake-sns | /app/models/post.rb | UTF-8 | 828 | 2.5625 | 3 | [] | no_license | # == Schema Information
#
# Table name: posts
#
# id :bigint not null, primary key
# content :text not null
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_posts_on_user_id (user_id)
#
c... | true |
8a854074ac037a04cc6e181113f0b50c94edfcd4 | Ruby | rmagick/rmagick.github.io | /ex/color_floodfill.rb | UTF-8 | 728 | 2.84375 | 3 | [
"MIT"
] | permissive | #!/home/software/ruby-1.8.7/bin/ruby -w
require 'RMagick'
# Demonstrate the Image#color_floodfill method
before = Magick::Image.new(200,200) { self.background_color = 'white' }
before.border!(1,1,'black')
circle = Magick::Draw.new
circle.fill('transparent')
circle.stroke_width(2)
circle.stroke('black')
circle.circle... | true |
42bb7b0f3f1d6f184b7328ce20fb6353876249c7 | Ruby | minstrel/mystars | /lib/mystars_dso.rb | UTF-8 | 2,923 | 2.71875 | 3 | [
"MIT",
"BSD-3-Clause"
] | permissive | # encoding: utf-8
#require 'curses'
require_relative 'stars3d'
require_relative 'helpers'
require_relative 'mystars'
class MyStarsDSO < MyStars
# A single DSO
#
# cart_world is the cartesian coordinate column vector in the world
# cart_proj is the cartesian coordinate column_vector in the current
# projecti... | true |
32be95946118759702c6021764c4409b11377795 | Ruby | andrewkirkwood/wk_03_day_3__pub_lab | /specs/customer_spec.rb | UTF-8 | 1,148 | 2.875 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/reporters')
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
require_relative('../customer')
require_relative('../drink')
require_relative('../food')
class CustomerTest < MiniTest::Test
def setup()
@customer = Customer.new("Jim", 10, 25, 55)
@d... | true |
40bbba13c152c70434bd6d8dffa0d92d5cc9ce2c | Ruby | Juanmcuello/garufa | /lib/garufa/subscriptions.rb | UTF-8 | 1,672 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'set'
require 'garufa/message'
require 'garufa/api/stats'
module Garufa
module Subscriptions
extend self
@semaphore = Mutex.new
def all
subscriptions
end
def stats
@stats ||= API::Stats.new(subscriptions)
end
def add(subscription)
subs = subscriptions[subscri... | true |
eaa3302447cce011f037914570afbf678219688b | Ruby | chhunge/RSpec-With-Selenium-Tutorial | /base_page.rb | UTF-8 | 1,299 | 3.390625 | 3 | [
"MIT"
] | permissive | require "selenium-webdriver"
module BasePage
DEFAULT_WAIT_TIME = 10
WEBDRIVER_ERRORS = [
Selenium::WebDriver::Error::TimeOutError,
Selenium::WebDriver::Error::NoSuchElementError
].freeze
def explicitly_wait_for_presence(locator = nil, wait_time = DEFAULT_WAIT_TIME)
puts "Expl... | true |
75362295a542064dd9379539728f42d7abdb98ea | Ruby | joshuaflanagan/pr-check | /lib/settings.rb | UTF-8 | 610 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Super-simple approach to push configuration values in to objects
class Settings
def self.init(values)
@values = values
end
def self.configure(namespace, other)
@values.each do |key, value|
setting_ns, setting = key.split("_", 2)
if setting.nil?
setting... | true |
9a1aff60d720b84735009aa12e8aac5ce8134820 | Ruby | gstark/life | /game.rb | UTF-8 | 1,429 | 3.3125 | 3 | [] | no_license | require 'gosu'
require_relative 'life'
class Game < Gosu::Window
FRAMERATE = 1000 / 4.0
SCALE = 10
def initialize
super 640, 480
self.caption = "Game of Life"
@prev_state = Set.new()
@state = Set.new()
@is_running = true
@space_down = false
@elapsed = 0
end
def screen_to_world... | true |
abe3528dbd8523742f44ead6d348d778cf700436 | Ruby | smpalh/RubyDoc | /05_27/05_27each.rb | UTF-8 | 147 | 2.875 | 3 | [] | no_license | # each
names = ["test1","test2","test3"]
names.each do |name|
puts name
end
i = 0
name.each do |name|
i += 1
redo if i == 2
p [i,name]
end | true |
93a16c1605a0375a500f651e6e7ce3735c23bb50 | Ruby | mdub/clamp | /lib/clamp/parameter/definition.rb | UTF-8 | 1,447 | 2.765625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "clamp/attribute/definition"
module Clamp
module Parameter
# Represents an parameter of a Clamp::Command class.
#
class Definition < Attribute::Definition
def initialize(name, description, options = {})
@name = name
@description = description... | true |
d3935d7d1e6e9387fbae5b93229a247aa8edec93 | Ruby | vinnyjth/advent-of-code-2020 | /day4.rb | UTF-8 | 1,696 | 3.296875 | 3 | [] | no_license | require './utils'
def solve1
lines = Utils.input_read(4)
passports = lines.join("").split("\n\n")
valid = passports.filter do |passport|
fields = passport.split(/[ \n]/).map { |field| { key: field.split(':')[0], value: field.split(':')[1] } }
['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid'].all? do |f|
... | true |
4eaa40326df916db9f38b82ede9a7d8443624e87 | Ruby | jtarchie/crawler | /lib/crawler.rb | UTF-8 | 1,522 | 2.875 | 3 | [] | no_license | require_relative 'page'
require_relative 'processed_links'
require 'json'
Crawler = Struct.new(:base_url) do
def process!
current_page = process_page(base_url)
processed_links = ProcessedLinks.new
processed_links.processed!(base_url)
processed_links.add(current_page.links)
while processed_links... | true |
28bd65557514246e3525c7ffbe3cd5b21c428de5 | Ruby | NightFeather/plurk | /lib/plurk/client.rb | UTF-8 | 2,637 | 2.65625 | 3 | [] | no_license |
require_relative 'client/endpoints'
module Plurk
# Contains credentials
class Client
include Endpoints
# :nodoc:
DEFAULT_OAUTH_OPTIONS = {
:site => 'https://www.plurk.com',
:scheme => :header,
:http_method => :post,
:request_token_path => '/O... | true |
013932bca7e555e9abd5c20b69e2ec1a0ac15e48 | Ruby | bjtj/tjsamples | /ruby/thread/queue.rb | UTF-8 | 308 | 3.328125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'thread'
queue = Queue.new
producer = Thread.new do
5.times do |i|
sleep rand(i)
queue << i
puts "#{i} produced"
end
end
consumer = Thread.new do
5.times do |i|
value = queue.pop
sleep rand(i/2)
puts "consumed #{value}"
end
end
consumer.join
| true |
3939ebc7a729e32778e75cf5ee80269beb382e4d | Ruby | chanfe/the-bachelor-todo-dumbo-web-080618 | /lib/bachelor.rb | UTF-8 | 1,265 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def get_first_name_of_season_winner(data, season)
# code here
data.each do |season_num, people|
if season_num == season
people.each do |person|
if person["status"] == "Winner"
return person["name"].split(" ")[0]
end
end
end
end
end
def get_contestant_na... | true |
2c9ee5630ada724e8ace6662fc6848f3bc0f71eb | Ruby | abrausch/fogata | /app/models/user.rb | UTF-8 | 961 | 2.53125 | 3 | [
"MIT"
] | permissive | class User < ActiveRecord::Base
# accessible attributes
attr_accessible :email, :first_name, :last_name, :provider, :uid
# associations
has_many :channels
has_many :messages
has_many :onlines
has_many :online_channels, through: :onlines, source: :channel
# validations
validates :email, presence: tru... | true |
f24eada179b032eb49c23696f4d56de2d03301de | Ruby | kskoo9/project-euler-sum-square-difference-q-000 | /lib/oo_sum_square_difference.rb | UTF-8 | 332 | 3.21875 | 3 | [] | no_license | # Implement your object-oriented solution here!
class SumSquareDifference
def initialize(num)
@num = num
end
def difference
sumofsq = 0
sqofsum = 0
for i in 1..@num
sumofsq += i*i
end
for i in 1..@num
sqofsum +=i
end
sqofsum = sqofsum*sqofsum
return sqofsum - sumofs... | true |
bbcc992a7642cf6968ff8ed3c2db94464be92a37 | Ruby | npapagna/scrum_bolivia_day_2015 | /01_object.rb | UTF-8 | 91 | 2.671875 | 3 | [] | no_license | puts 1.class.name
puts 'Hola SBD!'.size
# las clases son objetos tambien:
puts String.name | true |
41dbfa20616e114d152f853cdbf364f2434db440 | Ruby | cjkelling/sweater_weather | /app/facades/background_facade.rb | UTF-8 | 300 | 2.828125 | 3 | [] | no_license | class BackgroundFacade
attr_reader :id,
:background
def initialize(location)
@id = 1
@location = location
@background = image
end
def lat_long
Geocoding.new(@location).latitude_longitude
end
def image
Background.new(lat_long).get_background
end
end
| true |
32b7aba26ebe7f8ec0b7c8281863e8a420434d6f | Ruby | jakofranko/vessel.yuri | /objects/memory.arc.rb | UTF-8 | 749 | 2.546875 | 3 | [] | no_license | require_relative '../../../system/memory.rb'
require_relative './arc'
require_relative './_toolkit'
class ArcMemory < Memory_Array
def add summary_id, order, text
new_id = self.length.to_s.prepend("0", 5)
# Append this string to the entities.ma file
self.append("#{new_id} #{summary_id.pr... | true |
a7494817b89a9f8be41397456454fb47a5303604 | Ruby | TimWei/haijin_kabe | /lib/kabe.rb | UTF-8 | 1,058 | 2.78125 | 3 | [
"MIT"
] | permissive | class Kabe
def initialize opt={}
#load_setting
@config = opt[:config]
freq = @config['frequency']
@pic_num = (freq['download_new_image'] / freq['change_wallpapper']) + 1
end
def init
self.class.clear_old_img
@source = SourceFactory.new(source: @config['source'], pixiv: @config['... | true |
6f37e7cce58aa0c5418d4f824ef9570717573d1a | Ruby | eshamukherjee08/Esha_Ruby_Nokogiri | /XML_formatter.rb | UTF-8 | 1,585 | 3.390625 | 3 | [] | no_license | ## GENERAL COMMENT - Good exploration of nokogiri
require 'nokogiri'
##### COMMENT - We dont need a module here
# Module comprising of xml file scanner and builder
module Formatting
# Method to return array of text elements of xml file passed.
def scanner(filename)
#### COMMENT - Use a file utility funct... | true |
b8c1f45dc62f87591eb1c0ebc6face37230a60a5 | Ruby | ReynaldoJacob/tic_tac_toe | /tic.rb | UTF-8 | 2,099 | 3.90625 | 4 | [] | no_license |
class Tictac
def initialize(tamano)
@tamano = tamano
@matriz = []
end
def dimension()
@tamano.times do
columnas = []
@tamano.times do
columnas.push("°")
end
@matriz.push columnas
end
for f in 0..@matriz.size-1
puts
for c in 0..@matriz[f].size-1
print " "
... | true |
cff04e1c6ec2931109e25cec853b9c650b741360 | Ruby | JoshCheek/blog_engine | /lib/blog_engine/persisters/in_memory.rb | UTF-8 | 326 | 2.578125 | 3 | [
"MIT"
] | permissive | class BlogEngine
module Persisters
class InMemory
def add_blog(blog_hash)
blogs << blog_hash
end
def blogs_written_on(date)
blogs.select { |blog| blog.date == date }
end
def blogs
@blogs ||= []
end
alias all_blogs blogs
end
e... | true |
fb097e96ed01fbb51a20b4e095e63e25fbe23f09 | Ruby | chakeresa/westeros | /app/facades/search_index_facade.rb | UTF-8 | 426 | 2.609375 | 3 | [] | no_license | class SearchIndexFacade < BaseFacade
def initialize(house_id)
@house_id = house_id
end
def house_name
westeros_aas_api_service.house_name_by_id(@house_id)
end
def member_count
members.count
end
def members
return @members if @members
members_ary = westeros_aas_api_service.members(@... | true |
a6c3583c03897ebe8c4ef2082817e523b86d4854 | Ruby | vitorrjorge/treinamento_fundamentos | /aoQuadrado.rb | UTF-8 | 297 | 3.953125 | 4 | [] | no_license | array = []
print "Digite um número: "
array.push gets.chomp.to_i
print "Digite mais um número: "
array.push gets.chomp.to_i
print "Digite outro número: "
array.push gets.chomp.to_i
array.each do |a|
result = a ** 2
puts "Numero #{a} elevado ao quadrado é: #{result}"
end | true |
31ae1e33027cb1c8eca91ce33bb9e16272f147ca | Ruby | elunico/Quadtrees | /ruby/quadtree.rb | UTF-8 | 3,718 | 3.390625 | 3 | [] | no_license |
class Point
attr_accessor :x, :y
def initialize(x, y)
@x = x
@y = y
end
def ==(other)
return x == other.x && y == other.y
end
def to_s
return "(#{x}, #{y})"
end
def distance_to(other)
Math.sqrt(((x - other.x) ** 2) + ((y - other.y) ** 2))
end
end
class Rectangle
attr_access... | true |
a6a76590ccd67bd4434830b62f79e2325944dd4f | Ruby | ayafushimi/ruby-music-library-cli-v-000 | /lib/music_library_controller.rb | UTF-8 | 1,368 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class MusicLibraryController
def initialize(file_path = "./db/mp3s")
MusicImporter.new(file_path).import
end
def call
input = ""
lists = Song.all.sort_by{|a| a.artist.name }
while input != "exit"
puts "input something"
input = gets.strip
if input == "list songs"
lists.... | true |
90a5ac55b0ed8c0344f582f0f45c25d73541b8ce | Ruby | mmzyk/redirect_destination | /redirect_follower.rb | UTF-8 | 1,240 | 2.96875 | 3 | [] | no_license | require 'logger'
require 'net/http'
# Credits go to John Nunemaker for the heart of this code - railstips.org
class RedirectFollower
class TooManyRedirects < StandardError; end
attr_accessor :url, :body, :redirect_limit, :response
def initialize(url, limit=5)
@url, @redirect_limit = url, limit
#logger.level ... | true |
61a4cf68fc60d0384dd70ce1245dc1215822d31e | Ruby | hannahwhy/mirrorer | /mirror.rb | UTF-8 | 2,172 | 2.578125 | 3 | [
"LicenseRef-scancode-public-domain"
] | permissive | #!/usr/bin/env ruby
require 'celluloid'
require 'logger'
LOG = Logger.new($stderr)
module Shelling
def run(cmd, dry_run = false)
cmd = "cd #{path} && #{cmd}"
LOG.debug cmd
if !dry_run
`#{cmd}`
end
end
end
class Repo < Struct.new(:path)
include Shelling
def initialize(*)
super
... | true |
28ff42f685a52669831c70369b02ff8cb4011655 | Ruby | ryanrustler/sei | /outlines/33-routing-controllers-sinatra/classmate.rb | UTF-8 | 414 | 3.890625 | 4 | [] | no_license | class Classmate
def initialize(name, super_power)
@name = name
@super_power = super_power
end
def i_have_the_power!
return "My name is #{ @name } and my super power is #{ @super_power }"
end
end
# using this to test our class
# garth = Classmate.new('garth', 'sleeping in class!')
# marlon = Class... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.