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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
d9a2d0c477e9d0a9945284898d80b029ddfbefa2 | Ruby | dlaststark/machine-learning-projects | /Programming Language Detection/Experiment-2/Dataset/Train/Ruby/letter-frequency-2.rb | UTF-8 | 275 | 3 | 3 | [] | no_license | def letter_frequency(file)
freq = Hash.new(0)
file.each_char.lazy.grep(/[[:alpha:]]/).map(&:upcase).each_with_object(freq) do |char, freq_map|
freq_map[char] += 1
end
end
letter_frequency(ARGF).sort.each do |letter, frequency|
puts "#{letter}: #{frequency}"
end
| true |
b4a9afc6dc92bdb97f1a7a96999b4c239d70c140 | Ruby | HenriqueArtur/brasil-system-challenge | /classes/Utils.rb | UTF-8 | 1,709 | 3.90625 | 4 | [] | no_license | require 'date'
class Utils
def strReverse(str)
if str.is_a? String
return str.reverse
else
puts "Parametro inválido.\nPasse uma string como parametro"
newStr = gets.chomp
srtReverse(newStr)
end
end
def srtHalf(str)
if str.... | true |
47e33ab3db9a096ab2554d5337051d5cc23cc7d3 | Ruby | Jackiesan/oo-ride-share | /specs/trip_dispatch_spec.rb | UTF-8 | 6,951 | 2.78125 | 3 | [] | no_license | require_relative 'spec_helper'
describe "TripDispatcher class" do
describe "Initializer" do
it "is an instance of TripDispatcher" do
dispatcher = RideShare::TripDispatcher.new
dispatcher.must_be_kind_of RideShare::TripDispatcher
end
it "establishes the base data structures when instantiated... | true |
ce682b8e97ecdb485e0a602ce25413ff253b6922 | Ruby | papistan/phase-0-tracks | /ruby/hashes.rb | UTF-8 | 1,278 | 3.5 | 4 | [] | no_license | # Interior
# Psuedocode
# Indentify client and save their
# name
# age
# numnber of children
# decor theme
# money is no object?
# favorite colors
# special needs?
client_1 = {
name: "",
age: 0,
children: 0,
decor: "",
money: true,
colors: "",
requests: "",
}
puts "Enter client's first and last name as ... | true |
67e6b772aae778d264dd673b77f24d8b830aa5cd | Ruby | melnock/the-bachelor-todo-web-012918 | /lib/bachelor.rb | UTF-8 | 1,271 | 3.546875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def get_first_name_of_season_winner(data, season)
winner = []
data.each {|seasons, array|
if seasons == season
array.each {|hash|
if hash["status"] == "Winner"
winner << hash.values_at("name")
end
}
end
}
name = winner[0][0].split
name[0]
end
def get_contestant_name(data, occupation... | true |
c4483cbb86299c9e62d8193a890ea26732e230f9 | Ruby | kellyeryan/phrg-regex-lab-pca-000 | /lib/regex_lab.rb | UTF-8 | 996 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def starts_with_a_vowel?(word)
if word.match(/\b[AEIOUaeiou][a-z]*\b/)
return true
else
return false
end
end
def words_starting_with_con(text)
text.scan(/\bcon[a-z]*\b/)
end
def words_starting_with_un_and_ending_with_ing(text)
text.scan(/\bun[a-z]*ing\b/)
end
def words_five_letters_long(text)
tex... | true |
4aeaf6797c89d942d85b11823e52b1f31b2ff70e | Ruby | Scientist-Stephen/GoFish | /FishGame.rb | UTF-8 | 6,203 | 3.671875 | 4 | [] | no_license | require_relative 'FishDeck.rb'
require_relative 'FishHand.rb'
require_relative 'FishPlayers.rb'
class FishGame
attr_accessor :player
#attr_accessor :player2
#attr_accessor :player3
#attr_accessor :player4
#attr_accessor :player5
attr_accessor :top_card_container, :turn, :winner_message, :player_to_player_resul... | true |
63e2d1aaa881b2c70a7844924b6174f26fe88daa | Ruby | flavorjones/calendar-assistant | /lib/calendar_assistant/event_set.rb | UTF-8 | 4,294 | 2.9375 | 3 | [
"Apache-2.0"
] | permissive | class CalendarAssistant
#
# note that `events` could be a few different data structures, depending.
#
# - it could be an Array of Events
# - it could be a Hash, e.g. Date => Array of Events
# - it could be a bare Event
#
class EventSet
def self.new(event_repository, events = nil)
if events... | true |
e282e2fbf12e89188c77c19b9ed3e352998927e7 | Ruby | alu0100614220/prct12 | /lib/matrizdensa.rb | UTF-8 | 737 | 3.296875 | 3 | [
"MIT"
] | permissive | class Matrizdensa < Matriz
def initialize (x, y, v)
throw "Dimensiones invalidas" if (x * y) == 0
@xsize= x
@ysize= y
@values= Array.new(x * y)
for i in (0...@xsize) do
for j in (0...@ysize) do
@values[j * @ysize + i] = v[j * @ysize + i]
end
end
end... | true |
77d1be2ea078dbd1f608041bb2311a2478b3e3f4 | Ruby | capaca/band-manager-rb | /bandmanager/spec/models/song_spec.rb | UTF-8 | 1,344 | 2.5625 | 3 | [] | no_license | require 'test_helper'
class SongTest < ActiveSupport::TestCase
test "Should save a song" do
song = create_song
assert_difference "Song.count" do
song.save
song.release.save
end
end
test "Should destroy a song" do
song = create_song
song.save
assert_difference "Song.co... | true |
d9c76aac66f2eecd112edc451c4d3f565e2e6e04 | Ruby | EricaNichol/CodeCore- | /react-native/week_1/greg.rb | UTF-8 | 240 | 3.609375 | 4 | [] | no_license | puts "how many lines should triangle have?"
size = gets.chomp.to_i
space = ""
(size - 1).times { space += " " }
zeros = "0"
#2 times string = 2 string
size.times do
puts "#{space}#{zeros}"
space = space.chomp(" ")
zeros += " 0"
end
| true |
2b3ccb32aeabc713123a1ec419a4794e2112618b | Ruby | tztz8/CIS-283-Various_Classes | /RubyClasses_Freeman.rb | UTF-8 | 7,255 | 3.9375 | 4 | [] | no_license | #################################################################
#
# Name: Timbre Freeman
# Assignment: Ruby Classes
# Date: 01/22/2020
# Class: CIS 283
# Description: Make and use Perosn, Address and Character Class
#
#################################################################
# Perso... | true |
96577e2758042566c27eb63df7f112bba1f79629 | Ruby | anthonycarlos/ehash | /bin/ehash | UTF-8 | 2,843 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'gli'
begin # XXX: Remove this begin/rescue before distributing your app
require 'ehash'
rescue LoadError
STDERR.puts "In development, you need to use `bundle exec bin/ehash` to run your app"
STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
STDERR.p... | true |
f8596779613a668b9d8f6bf5cce6dfff796120de | Ruby | gbuilds/bank-app | /bankapp.rb | UTF-8 | 1,520 | 3.875 | 4 | [] | no_license | class Account
attr_reader :name, :balance
def initialize(name, balance=100)
@name = name
@balance = balance
end
public
def display_balance(pin_number)
if pin_number == pin
puts "Balance: $#{@balance}"
else
puts pin_error
end
end
def withdraw(pin_number, amount... | true |
497f0be5ed5b78739b9d838bf6ecdd25b320f51a | Ruby | samullen/ruby-redtail | /lib/ruby-redtail/contact/addresses.rb | UTF-8 | 2,240 | 2.515625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module RubyRedtail
class Addresses
def initialize(api_hash)
@api_hash = api_hash
end
# Fetch Address By Contact Id
def fetch (contact_id)
RubyRedtail::Query.run("contacts/#{contact_id}/addresses", @api_hash, "GET")
end
# Update Address
def update (contact_id, address_id, par... | true |
ebfc525c4977411e53913e2df94682b94615cc9a | Ruby | jeaxelrod/railschallenge-city-watch | /app/services/dispatcher.rb | UTF-8 | 1,624 | 2.75 | 3 | [] | no_license | class Dispatcher
attr_accessor :emergency
attr_reader :full_response, :available_on_duty_responders
TYPES = [:fire, :police, :medical]
def initialize(emergency)
@emergency = emergency
@resolved = {}
TYPES.each { |type| @resolved[type] = false }
dispatch
end
def available_on_duty_responders... | true |
309e4eb5481fca0d90c047fe1369bd3fce868493 | Ruby | akanshmurthy/codelearnings | /appacademy/w2d4/my-stack.rb | UTF-8 | 1,291 | 3.5 | 4 | [] | no_license | require "byebug"
class MyStack
attr_reader :max, :min
def initialize
@store = []
@min = nil
@max = nil
end
def pop
el = @store.pop
if peek.nil?
@max = nil
@min = nil
else
@max = peek[:max]
@min = peek[:min]
end
el
end
def push(el)
@min = el i... | true |
a2001e3ddddbc283558493c03c889637bdae859d | Ruby | spektroskop/scheme | /cons.rb | UTF-8 | 2,004 | 3.109375 | 3 | [] | no_license | require "./undefined"
require "./empty"
class Object
def list?
if Cons === self
last.cdr.null?
else
null?
end
end
def null?
Empty === self
end
def pair?
Cons === self
end
end
def List(array, tail = Empty)
return Empty if arr... | true |
9c3dfcfda9a8975599bb84bdd9770a9914bbdca6 | Ruby | timbuchwaldt/torquebox-chef | /tb-deployer-client/templates/default/knob_poll.rb.erb | UTF-8 | 1,742 | 2.53125 | 3 | [] | no_license | #!/usr/bin/ruby
require 'net/http'
uri = URI(latest_url)
latest_build_number = Net::HTTP.get(uri)
last_build_file = "<%="#{@app_root}/#{@application_name}"%>_lastbuild.txt"
last_build_number = 0
if File.exists? last_build_file
last_build_number = File.new(last_build_file).read
end
unless last_build_number == late... | true |
6d7640f2f4c1abcfb78804d0d1688640b4a61f50 | Ruby | yuuuuut/DootInternKadai | /3-1-backend/app/models/user.rb | UTF-8 | 696 | 2.546875 | 3 | [] | no_license | class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
include DeviseTokenAuth::Concerns::User
validates :name, presence: true
has_many :messages, dependent: :destroy
has_many :entries, dependent: :destroy
has_many :rooms, throu... | true |
c75cadeeb442a1075b3114965b02e8d436089319 | Ruby | ojasve123/training | /ruby/naturalnumbers.rb | UTF-8 | 77 | 3.375 | 3 | [] | no_license | puts "please enter a number"
i = gets.chomp.to_i
for x in 1..i
puts x
end
| true |
be7004fe7710f36d88f2b7fd5f3ba96bfbf80ca7 | Ruby | DarthMarino/UniversalTranslatorRb | /tests/test_universaltranslator.rb | UTF-8 | 1,549 | 3.15625 | 3 | [
"MIT"
] | permissive | require 'test-unit'
require 'universaltranslator'
# TestNumberTranslator tests differents inputs a modified universal translator to instead of printing returning errors.
class TestNumberTranslator < Test::Unit::TestCase
# Empty file
def test_one
input = 'input_tes1.txt'
translate = UniversalTranslator.new
... | true |
6249d3ce14c3ca47c0c157c27a612c9415cf6615 | Ruby | harisafridi/sort | /selectinsort.rb | UTF-8 | 298 | 3.71875 | 4 | [] | no_license |
def selectionsort(array)
(0...array.size).each do |j|
min = j
puts "array value: #{j}"
(j+1...array.size).each do |i|
min = i if array[i] < array[min]
end
array[j], array[min] = array[min], array[j]
end
return array
end
list = [7,10,3,99,50]
puts selectionsort(list)
| true |
862b4430970c43d3c09b1114c1958a6977032d34 | Ruby | dkhan/bible_code | /bible_code.rb | UTF-8 | 14,038 | 3.21875 | 3 | [] | no_license | # Galatians 2:20 (KJV): I am crucified with Christ: nevertheless I live; yet not I, but Christ liveth in me: and the life which I now live in the flesh I live by the faith of the Son of God, who loved me, and gave himself for me.
# verse = "χριστω συνεσταυρωμαι ζω δε ουκετι εγω ζη δε εν εμοι χριστος ο δε νυν ζω εν σαρκ... | true |
f45a4ea44385403afe3208eddbb5cd6e52244b75 | Ruby | l-jdavies/ruby_small_problems | /ruby_basics/longest_alphabetical_substring.rb | UTF-8 | 895 | 4.34375 | 4 | [] | no_license | # Find the longest substring in alphabetical order.
# The input will only consist of lowercase characters and will be at least one letter long.
# If there are multiple solutions, return the one that appears first.
# ALGORITHM
# generate substrings
# store substrings in an array
# if substr is in alphabetical order
# a... | true |
d4807c43af7b05312513eaa2e197b74ecfff2987 | Ruby | brandonrandall/jungle_beat | /lib/jungle_beat.rb | UTF-8 | 372 | 3.203125 | 3 | [] | no_license | require './lib/linked_list'
class JungleBeat
attr_reader :list
def initialize
@list = LinkedList.new
end
def append(words)
# binding.pry
appended = words.split.each do |word|
@list.append(word)
end
final = appended.join(" ")
end
def count
@list.count
end
def play
... | true |
362e4644c42e009be369e9566280d27e4efa6e36 | Ruby | Talbatross/18xx | /lib/engine/share_price.rb | UTF-8 | 2,105 | 2.875 | 3 | [
"MIT",
"LicenseRef-scancode-free-unknown"
] | permissive | # frozen_string_literal: true
module Engine
class SharePrice
attr_reader :coordinates, :price, :color, :corporations, :can_par, :type
def self.from_code(code, row, column, unlimited_colors, multiple_buy_colors: [])
return nil if !code || code == ''
price = code.scan(/\d/).join('').to_i
c... | true |
a8453014309f9966e62bb1d5197d3609e78dff15 | Ruby | daydreamboy/HelloRuby | /ruby_tool/AbstractInterface2.rb | UTF-8 | 984 | 2.859375 | 3 | [
"MIT"
] | permissive | ##
# Provide an abstract module to define an interface
#
# @see https://metabates.com/2011/02/07/building-interfaces-and-abstract-classes-in-ruby/
module AbstractInterface
class InterfaceNotImplementedError < NoMethodError
end
def self.included(clz)
clz.send(:include, AbstractInterface::Methods)
clz.send... | true |
bfd28fc4e2ea255f15ca5cfa5a8188940be68512 | Ruby | TheODI-UD2D/sir_handel | /spec/helpers_spec.rb | UTF-8 | 8,264 | 2.578125 | 3 | [
"MIT"
] | permissive | module SirHandel
describe Helpers do
let(:helpers) { TestHelpers.new }
it 'returns straight away if rack env is test' do
expect(ENV).to receive(:[]).with('RACK_ENV').and_return('test')
expect(helpers.protected!).to eq(nil)
end
it 'returns nil if authorized is true' do
expect(ENV).... | true |
5222259b2b3d60f38b94765692bd468882458227 | Ruby | robertkchang/receipt | /lib/shopping.rb | UTF-8 | 540 | 3.28125 | 3 | [
"MIT"
] | permissive | require_relative 'receipt'
require_relative 'shopping_cart'
#
# Interactively accepts one or more item,
# calculates the sales tax and total,
# and displays the itemized receipt
#
class Shopping
########
# Main #
########
input_list = []
begin
puts 'Enter an item (<ENTER> on empty line to quit... | true |
7b9c8cad77ab8572d3ee8e2ebba9e851841c91f4 | Ruby | kldgarrido/command_line | /model.rb | UTF-8 | 277 | 3.328125 | 3 | [] | no_license | #!/usr/bin/env ruby
class Quiz
include Comparable
attr_reader :question, :answer
def initialize(question, answer)
@question = question
@answer = answer
end
def <=>(anOther)
@question <=> anOther.question
@answer <=> anOther.answer
end
end
| true |
159440d634e5ac9be5b47e1eac7d0ad5c6b60d8d | Ruby | vdepetigny/THPTwitter | /stream.rb | UTF-8 | 1,226 | 2.546875 | 3 | [] | no_license | # ligne très importante qui appelle la gem.
require 'twitter'
# n'oublie pas les lignes pour Dotenv ici…
require 'dotenv'
Dotenv.load
# quelques lignes qui appellent les clés d'API de ton fichier .env
def streaming_twitter
client_stream = Twitter::Streaming::Client.new do |config|
config.consumer_key = ENV... | true |
9f13fdf3239ee03514c20b9e321b379ee6570ca8 | Ruby | robyparr/adjourn | /app/helpers/meetings_helper.rb | UTF-8 | 1,021 | 2.8125 | 3 | [
"MIT"
] | permissive | # typed: true
module MeetingsHelper
def recent_meetings(meetings)
meetings.select { |it| it.recent? }
end
def upcoming_meetings(meetings)
meetings
.select { |it| it.upcoming? }
.sort_by { |it| it.start_date }
end
def display_recent_and_upcoming_meetings_section?(page)
page.nil? || p... | true |
7bc2d153aa384c11027496dc034876a041b1550f | Ruby | haracane/kajax | /lib/mysql_util.rb | UTF-8 | 1,110 | 2.515625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | dirpath = File.expand_path(File.dirname(__FILE__))
$:.push(dirpath)
require 'rubygems'
require 'mysql'
module MysqlUtil
def self.get_option_hash(psql_option)
psql_option_list=psql_option.split(/\s+/)
ret = {}
ret[:db_host]='localhost'
ret[:db_port]=3306
ret[:db_name]='db'
ret[:db_user]='post... | true |
4f802c8d4997ecbe1b1e459317982d9bb8ceb5a6 | Ruby | giannioneill/myexp-meandre | /lib/file_types_handler.rb | UTF-8 | 1,895 | 2.75 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause",
"MIT"
] | permissive | # myExperiment: lib/file_types_handler.rb
#
# Copyright (c) 2008 University of Manchester and the University of Southampton.
# See license.txt for details.
# Helper class to deal with File types and processors.
# Based on the WorkflowTypesHandler
class FileTypesHandler
# Gets all the workflow processor... | true |
869ab230e88e847326710e034b1dc01a56996d42 | Ruby | krisswiltshire30/Bank-ruby | /spec/unit/account_spec.rb | UTF-8 | 867 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
require './lib/account.rb'
RSpec.describe Account do
describe 'Deposit' do
it 'Should return a string containing how much has been deposited' do
expect(subject.deposit(50)).to eq('£50 deposited into your to account')
end
end
describe 'Withdraw' do
it 'Should retu... | true |
4c03395f221a7ba5ef41894495dc71cb484ca2cd | Ruby | gjanee/advent-of-code-2015 | /11.rb | UTF-8 | 2,299 | 4.03125 | 4 | [] | no_license | # --- Day 11: Corporate Policy ---
#
# Santa's previous password expired, and he needs help choosing a new
# one.
#
# To help him remember his new password after the old one expires,
# Santa has devised a method of coming up with a password based on the
# previous one. Corporate policy dictates that passwords must be
... | true |
dda815dce242679fc99b31c4b00a0fc3e11828ed | Ruby | skuhlmann/sales_engine | /lib/merchant_repository.rb | UTF-8 | 1,740 | 3.046875 | 3 | [] | no_license | require_relative 'merchants_parser'
require_relative 'merchants'
class MerchantRepository
attr_reader :merchants, :sales_engine
def initialize(file_path, sales_engine)
@merchants = MerchantsParser.new(file_path).all(self)
@sales_engine = sales_engine
end
def all
merchants
end
def random
merchants.s... | true |
0506f1ae4390aef443f51737ec1cd833f5c3d5b5 | Ruby | bainezydave/gentech-ruby | /day_10/error.rb | UTF-8 | 272 | 3.859375 | 4 | [] | no_license | system "clear"
begin
puts "Enter a number"
num1 = gets.chomp.to_i
puts "Enter another number"
num2 = gets.chomp.to_i
puts "The division of 2 numbers is #{num1/num2}"
rescue
loop do
puts "The second number should not be 0"
end
end
| true |
25c46170404307e81633fde1c64842891965309d | Ruby | dball1126/W2D2 | /chess/game.rb | UTF-8 | 384 | 2.875 | 3 | [] | no_license | require_relative "board"
require_relative "display"
require_relative "player"
class Game
def initialize
@board = board
@display = display
@players = Hash.new{ |h, k| h[k] = nil }
@current_player = #symbol or player
end
def play
end
private
... | true |
6d385123ad5869f4c806b04b48d59b56f405606d | Ruby | judywu29/ruby_pj | /envato_algorigthms/binary_search.rb | UTF-8 | 341 | 3.6875 | 4 | [] | no_license | #O(logN)
def bsearch(arr, key)
min = 0; max = arr.size-1;
while min <= max
mid = min + (max - min) / 2 #plus min!!!!!!!!!!!!
return mid if key == arr[mid]
key < arr[mid] ? max = mid - 1 : min = mid + 1
end
return -1
end
ar = [23, 45, 67, 89, 123, 568]
p bsearch(ar, 23) #0
p bsearch(ar, 123) #4
p b... | true |
690b60b1e4de36b52c07995cf9dbf0438092778e | Ruby | Jwarholic/GiphyQuotes | /app/models/quote.rb | UTF-8 | 1,110 | 2.5625 | 3 | [] | no_license | module Quote
#Hides API Key
KEY = ENV['QUOTES']
#Quote API
def self.quote(word)
uri = URI.parse("http://quotes.rest/quote.json?category=#{word}")
request = Net::HTTP::Get.new(uri)
request["X-Theysaidso-Api-Secret"] = KEY
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") d... | true |
e94d4f76a60dcd0ced381a4ee56d1f10143dfcf7 | Ruby | samworrall/Oystercard2 | /lib/oystercard.rb | UTF-8 | 684 | 3.453125 | 3 | [] | no_license | class Oystercard
attr_reader :balance, :entry_station, :journeys
LIMIT = 90
MINIMUM_FARE = 1
def initialize
@balance = 0
@journeys = []
end
def top_up(value)
raise "Maximum limit of £#{LIMIT} exceeded" if @balance + value > LIMIT
@balance += value
end
def touch_in(station)
fail "I... | true |
e76348428f7386bf0888281bd556cd7d8b4f7950 | Ruby | RafaelCostta13/ExerciciosEmRuby | /04 - Capítulo/Exercícios Resolvidos/01 - Exercicio.rb | UTF-8 | 1,364 | 3.875 | 4 | [] | no_license | =begin
01 - A nota final de um estudante é calculada a partir de três notas atribuídas, respectivamente,
a um trabalho de laboratório, a uma avaliação semestral e a um exame final. A média das três notas mencionadas
obedece aos pesos a seguir:
Nota PESO
Trabalho de laboratório 2
Avaliação semestral ... | true |
2035bc624934894cc105205c3c113ff3f61bce9a | Ruby | sallartiste/ruby | /eath-2/classes/animaux.rb | UTF-8 | 367 | 4.09375 | 4 | [] | no_license | class Animal
def set_parole(parole)
@parole = parole
end
def get_parole
return @parole
end
def set_age(age)
@age = age
end
def get_age
return @age
end
end
cochon = Animal.new
cochon.set_parole("groin, groin!")
cochon.set_age(12)
puts "Le cochon font: #{cochon... | true |
44c88bf6097096f48c07de02b389255c1928b547 | Ruby | sans-pulp/ar-exercises | /exercises/exercise_5.rb | UTF-8 | 595 | 3.21875 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
puts "Exercise 5"
puts "----------"
# Your code goes here ...
#Total revenue for all stores
@total_revenue = Store.sum("annual_revenue")
puts "Total Revenue: #{@t... | true |
8edda100b67db53797a84fa317534cae4787144d | Ruby | daveguymon/Learn-Ruby-Hard-Way | /ex11a.rb | UTF-8 | 241 | 3.5625 | 4 | [] | no_license | print "What is your name? "
name = gets.chomp
print "What is your quest? "
quest = gets
print "What is the wind velocity of a sparrow?"
velocity = gets.chomp
puts "Your name is #{name}. Your quest is #{quest}. The velocity is #{velocity}."
| true |
50cfdf7a2f3e75b039f7b6e309df5c3bf9e9f001 | Ruby | ThriveADRIAN/mars_rover | /mars_rover.rb | UTF-8 | 2,674 | 3.765625 | 4 | [] | no_license | class MarsRover
# constructor method
def initialize
@x_up_right
@y_up_right
@x_coord
@y_coord
@heading
end
# instance methods
def read_instruction_line(file,split_char)
line = file.readline
line = line.chomp!
line = line.split(split_char)
end
def set_up_right_coordinates(line_reader)
@x_up_ri... | true |
39b221202318d62545164ed2e1e2a5b5ab865f7c | Ruby | yhuang/ruby_lessons | /08_pig_latin/pig_latin_translator.rb | UTF-8 | 482 | 3.1875 | 3 | [] | no_license | module PigLatinTranslator
def translate_word(word)
reg_exp = Regexp.new(/(qu|[^aeiouy]*)([aeiouy]+\w*)/)
match_data = reg_exp.match(word)
if match_data.nil?
return ''
elsif match_data[1].nil?
return match_data[2] + 'ay'
else
return match_data[2] + match_data[1] + 'ay'
end
... | true |
4971c683d9dd32dd8739c410c85190dff64849d2 | Ruby | SebEchegaray/planets | /controllers/planets_controller.rb | UTF-8 | 1,195 | 2.578125 | 3 | [] | no_license | get '/info' do
planets = all_planets()
erb :'info/index', locals: { planet: planets }
end
get '/info/add' do
erb :'info/new', locals: { edit: false }
end
post '/info' do
name = params[:name]
diameter = params[:diameter]
distance = params[:distance]
mass = params[:mass]
moon_count = params[:moon_count]... | true |
5ff232f444f6317147f4eb1ceaa73c9c86719f7e | Ruby | sergeynakul/thinknetica2019 | /Lesson2/shop_cart.rb | UTF-8 | 544 | 3.578125 | 4 | [] | no_license | shop_cart = {}
loop do
print "Введите название товара: "
item = gets.chomp
break if item == "стоп"
print "Введите стоимость товара: "
price = gets.to_f
print "Введите кол-во купленного товара: "
quantity = gets.to_f
shop_cart[item] = { price: price, quantity: quantity, amount: price * quantity }
... | true |
1dfa9622ece982c8f8015cd09d6a3cefb104a70d | Ruby | plastictrophy/viddl-rb | /lib/viddl-rb.rb | UTF-8 | 2,436 | 2.640625 | 3 | [] | no_license | #!/usr/bin/env ruby
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'helper')
require "rubygems"
require "nokogiri"
require "mechanize"
require "cgi"
require "open-uri"
require "stringio"
require "download-helper.rb"
require "plugin-helper.rb"
#require all plugins
Dir[File.join(File.dirname(__FILE__),"../plugin... | true |
4f02cd6b7579ebeb4b8585982c172d7b035647ad | Ruby | ejaypcanaria/onquiry_on_rails | /app/models/question.rb | UTF-8 | 800 | 2.546875 | 3 | [] | no_license | class Question < ActiveRecord::Base
before_validation :generate_permalink
belongs_to :user
has_many :answers
validates :question, presence: true, uniqueness: {message: "already exists.", case_sensitive: false}, length: { maximum: 255 }
validates :permalink, presence: true, length: { maximum: 255 }
de... | true |
1e9c23124d6510c469878132a32dd3ba3ffc8000 | Ruby | subintp/stockexchange_ruby | /models/trade.rb | UTF-8 | 282 | 2.796875 | 3 | [] | no_license | class Trade
attr_accessor :sell_order_id, :sell_price,
:quantity, :buy_order_id
def initialize(args)
@sell_order_id = args[:sell_order_id]
@sell_price = args[:sell_price]
@quantity = args[:quantity]
@buy_order_id = args[:buy_order_id]
end
end | true |
409df041c21465688b8caff19c9d89158358aab6 | Ruby | jaywood128/ruby-music-library-cli-online-web-pt-102218 | /lib/concerns/findable.rb | UTF-8 | 465 | 2.578125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
module Concerns::Findable
def find_by_name(name)
all.detect {|object| object.name == name}
#find will return nil of the name isn't in @@all
end
def find_or_create_by_name(name)
find_by_name(name) || create(name) #if find_by_name(name) returns nil, the right side is executed
end
def find_or_c... | true |
5786a1d0ff5fd104d7ca97ef642c05b13c124927 | Ruby | horthbynorthwest/bank-tech-test | /lib/statement.rb | UTF-8 | 441 | 3 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'bank_account'
class Statement
def show_statement(list)
header
statement_content(list)
end
private
def header
puts 'date || credit || debit || balance'
end
def statement_content(list)
list.reverse.each do |t|
puts "#{t.date} || #{form... | true |
070d88f73704b68e7b9a4d0e0570a83ba50fb1bd | Ruby | dhserver/desafios | /ciclos_y_metodos/desafios_zip/solo_impares.rb | UTF-8 | 79 | 2.9375 | 3 | [] | no_license | n = ARGV[0].to_i
for i in 1..n
a = (i*2)-1
print "#{a} "
end
puts
| true |
abd32b294fb75a0bc762b170eab4c79054872d55 | Ruby | thebravoman/software_engineering_2014 | /class017_test/files_for_exam_2/results/Momchil_Angelov_18_5fcdeb_csv_writer.rb | UTF-8 | 184 | 3.046875 | 3 | [] | no_license | require 'csv'
class CSVWriter
def write(student)
CSV.open("results.csv", "w") do |csv|
student.sort.each do |key, value|
csv << ["#{key}", "#{value}"]
end
end
end
end
| true |
20fbec92754cbe7b6cb0d51fb140e2b118784380 | Ruby | treacher/toy-robot | /lib/file_runner.rb | UTF-8 | 601 | 2.921875 | 3 | [] | no_license | class FileRunner
def initialize(file)
@simulation = Simulation.new
@parser = FileParser.new(file)
parse_actions
end
def execute_actions
parser.parsed_actions.each do |action|
if action[:action] == :place
handle_place_action(action)
else
simulation.send(action[:action].... | true |
2221e1de89f7abb444f0c73361ffebf826b61874 | Ruby | gilesbowkett/lattice | /lib/grid.rb | UTF-8 | 2,929 | 3.21875 | 3 | [] | no_license | module DropX
class Grid
def initialize
@grid = []
7.times {@grid << Array.new(7)}
@tagged_to_explode = []
end
def [](index)
@grid[index]
end
alias :row :[]
def to_s
@grid.reverse.inject("") do |string, row|
string << "#{row.inspect}\n"
end
end
... | true |
9282a078178604b11d785441dcd0395de941bd02 | Ruby | tdshap/wdi-rosencrantz | /w05/d03/Classwork/dog_breeds/add_dog.rb | UTF-8 | 455 | 3.234375 | 3 | [] | no_license | puts "Hello. Welcome to the dog database. What is the breed of dog you want to update?"
breed = gets.chomp
puts "What is the dog's name?"
name = gets.chomp
puts "What is the dog's age?"
age= gets.chomp
dog_to_update = Dog.find_by(:breed breed)
id = dog_to_update[:id]
HTTParty.put("http://127.0.0.1:4567/dog/#{id}... | true |
6bfd2bc98c92aec86eeb0f37e3e8d95118ca15c3 | Ruby | dgsuarez/programs_that_understand | /ruby/db_adapters.rb | UTF-8 | 512 | 3.25 | 3 | [] | no_license | # This is a classic metaprogramming use case: Avoid repeating yourself when you
# need to initialize a class based on it's name
module Adapters
class MysqlAdapter; end
class PostgresAdapter; end
class SqlserverAdapter; end
class OracleAdapter; end
end
# Using `const_get` we can resolve a class name (a stri... | true |
9e699a73337c3f1342c456effc0920fea21c7d3a | Ruby | Thieurom/nand2tetris | /06/src/parser.rb | UTF-8 | 2,364 | 3.40625 | 3 | [] | no_license | require_relative 'instruction_type'
require_relative 'symbol_table'
class Parser
def initialize(source_file)
@source = source_file
@symbols = SymbolTable.new
@next_address = 16
@instructions = []
end
def parse
load_from_source
scan_labels
out = []
@instructions.each do |instruct... | true |
8443c2e0e77c0009db6e23b581d65840a9cf8962 | Ruby | gpsing7v/student_shuffle.names | /student_shuffle.rb | UTF-8 | 111 | 2.84375 | 3 | [] | no_license | students = ["Student", "Billy", "Sue", "Mickey", "Mouse",
"Donald", "Duck", "Daffey", "Pluto"]
puts students | true |
0fdb2ab615c7ef9a265520cbc073cf55162133d2 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/gigasecond/8dc7c648a3cc4d13a8434456cbe9c4b5.rb | UTF-8 | 153 | 2.96875 | 3 | [] | no_license | require 'date'
require 'time'
class Gigasecond
def initialize(birthday)
@date = birthday + ((10 ** 9)/(60 * 60 * 24))
end
attr_reader :date
end
| true |
782c87986086cf023320b506fa72c8e0ef993865 | Ruby | chrisb/openfire | /lib/openfire/client.rb | UTF-8 | 735 | 2.578125 | 3 | [
"MIT"
] | permissive | module Openfire
class Client
include ActiveSupport::Configurable
config.services = [ 'Group', 'Room', 'User' ]
def initialize(url,secret)
@services = config.services.map { |s| "Openfire::Service::#{s}".constantize.new url: url, secret: secret }
end
def get_service(service)
klass_nam... | true |
657abf1371b5de833c787ccbff573aa55a209735 | Ruby | EricRichardson/aoc_2020 | /day10/solution.rb | UTF-8 | 360 | 2.546875 | 3 | [] | no_license | def solve
one_diff = 0
three_diff = 1 # for the device
small_count = 0
file_name = 'other.txt'
adaptors = File
.readlines(file_name)
.map(&:to_i)
.sort
.inject(0) do |last, adp|
diff = adp - last
one_diff += 1 if diff == 1
three_diff += 1 if diff == 3
adp
end
... | true |
9786b8bc8bb20ac543ba1ea2a6e9dff6e911192c | Ruby | soffes/quesadilla | /lib/quesadilla/extractor/emoji.rb | UTF-8 | 1,100 | 2.65625 | 3 | [
"MIT"
] | permissive | # encoding: UTF-8
module Quesadilla
class Extractor
# Extract named emoji.
#
# This module has no public methods.
module Emoji
private
require 'named_emoji'
# Emoji colon-syntax regex
EMOJI_COLON_REGEX = %r{:([a-zA-Z0-9_\-\+]+):}.freeze
def replace_emoji
codes =... | true |
6f09455e4b132e4df1f03108f0ecb677cb7ed1e2 | Ruby | nemoDreamer/ruby-extensions | /modules/module.Testable.rb | UTF-8 | 1,649 | 3.234375 | 3 | [] | no_license | begin
# add color support to module.Testable if available
require_relative '../classes/class.String.rb'
rescue LoadError
if !'string'.methods.include? :color
class String
def color (*args) self end
def bold () self end
end
end
end
module Testable
# ------------------------------------------------... | true |
af4e74e00512d65be91fd4476b06b7d8fbbb3f80 | Ruby | amckemie/Rock_Paper_Scissors_Project | /spec/invites_cmd_spec.rb | UTF-8 | 2,558 | 2.671875 | 3 | [] | no_license | require 'spec_helper.rb'
describe 'invites_cmd' do
it 'exists' do
expect(InvitesCmd).to be_a(Class)
end
let(:user1) {RPS.db.create_user(:name => "Ashley", :password => "abc12")}
let(:user2) {RPS.db.create_user(:name => "Katrina", :password => "123kb")}
let(:invite_result) {@cd.create_invite(user1.name, ... | true |
0f5fb2f680eafbcde7e8f65800d0fc6dff3d77c8 | Ruby | mark/string_formatter | /spec/string_formatter_spec.rb | UTF-8 | 2,944 | 3.015625 | 3 | [] | no_license | require 'spec_helper'
describe StringFormatter do
describe "Basic behavior" do
class PersonFormatter < StringFormatter
f { first_name }
l { last_name }
end
Person = Struct.new(:first_name, :last_name) do
include Formattable
define_format_string :format, :with => PersonFormatt... | true |
e914e6efb6c482f66f5631c8294b2907753dc73c | Ruby | denisnurboja/Assignments | /ParsingJSON.rb | UTF-8 | 693 | 4 | 4 | [] | no_license | # Assignment 17
# Require JSON to parse data in Ruby.
require 'json'
# Read external JSON file and set it to the variable 'file'.
file = File.read('assignment17.json')
# Parse the 'questions' object inside of the JSON 'file'; leaving out the
# 'questions' object will print all 3 questions and error out.
questions = ... | true |
c7d28efb27202c9c325b149b8e729d375ebe9b64 | Ruby | tiyd-ror-2016-06/playr | /app/models/hangman.rb | UTF-8 | 657 | 3.078125 | 3 | [] | no_license | class Hangman < ActiveRecord::Base
belongs_to :player, class_name: "User"
@word_list = ["test", "example", "thing"]
def self.start user
word = @word_list ? @word_list.sample : Word.all.sample
create! word: word, lives_left: 6, player: user
end
def self.word_list= l
@word_list = l
end
def r... | true |
bc5c19086c4520b82ebd6293e02deef189dd04df | Ruby | marlonsingleton/crimson-stone | /lesson_1/nothing_to_return.rb | UTF-8 | 308 | 3.65625 | 4 | [] | no_license | =begin
def scream(words)
words = words + "!!!!"
return
puts words
end
scream("Yippeee")
=end
puts "
def scream(words)
words = words + \"!!!!\"
return
puts words
end
scream(\"Yippeee\")
The method returns nothing because the explicit 'return'
within the code block was not passed a value.
"
| true |
61efc235eb3c9e9bbc0e178b787b6eb2be305bee | Ruby | bakutinamari/mary | /t.rb | UTF-8 | 271 | 3.09375 | 3 | [] | no_license | puts "Введите ваше имя"
name = gets.chomp
puts "Введите ваш рост"
height = gets.chomp
h = height.to_i
height_2 = (h-110)*1.15
if height_2 >=0
puts "#{name},ваш вес #{height_2}"
else
puts "Ваш вес уже оптимальный"
end
| true |
4970d9c1b3fd818f979bee8adef7d98a14b682eb | Ruby | aaronsweeneyweb/airport_challenge | /spec/airport_spec.rb | UTF-8 | 944 | 3 | 3 | [] | no_license | require 'airport'
describe Airport do
it { is_expected.to respond_to(:land).with(1).argument}
it { is_expected.to respond_to(:take_off).with(1).argument}
describe '#land' do
it 'can see a landed plane' do
plane1 = (double :plane)
subject.land(plane1)
expect(subject.planes).to include plane1
en... | true |
55248dcda1b4cca7b4fe027f4b97c38b05e3074d | Ruby | hillmandj/clrs-algorithms | /ch-4/code/linear_runtime_maximum_subarray.rb | UTF-8 | 2,505 | 4.03125 | 4 | [] | no_license | #!/usr/bin/env ruby
# CODE FOR 4.1-5
def linear_maximum_subarray(a)
# Initialize values that we'll be returning
low = 0
high = 0
max_sum = 0
# These are the values we'll use to keep track of where the
# maximum subarray is, and the corressponding index.
i = 0
current_sum = 0
0.upto(a.length - 1).e... | true |
41f8067e2774c562b2a7203eb9fe1afac2ee0500 | Ruby | faust45/bharati_ru | /lib/page_path.rb | UTF-8 | 1,689 | 2.796875 | 3 | [] | no_license | class PagePath
attr_reader :helper
delegate :ico_beta, :link_to, :content_tag, :root_path, :to => :helper
def initialize(helper, &block)
@helper = helper
@block = block
@prefix = ''
@path = Path.new(helper)
end
def to_s
@block.bind(self).call
@path.to_s
end
def method_missing(m... | true |
73fbb3add31677e2ade043b45c4ef019f5256ac9 | Ruby | jjc224/Matasano | /Ruby/25.rb | UTF-8 | 6,166 | 3.34375 | 3 | [] | no_license | # Challenge 25: break random access read/write AES-CTR.
require_relative 'matasano_lib/aes_128'
require_relative 'matasano_lib/url'
require_relative 'matasano_lib/monkey_patch'
include MatasanoLib
# irb(main):003:0> MatasanoLib::AES_128::random_key
# => "/\x82\x82\xC8\"\xEE\\i_\x1F\x06\xA0\xAC;\x06)"
AES_KEY = '971f... | true |
63ce22434771fabb38c11a3d64cbfe719c1843a6 | Ruby | zachholcomb/practice_ruby | /lib/pascals.rb | UTF-8 | 293 | 3.375 | 3 | [] | no_license | class Triangle
def initialize(num)
@level = num
end
def rows
start_rows = [[1]]
return start_rows if @level == 1
(2..@level).reduce(start_rows) do |finish, row|
new_row = [0, *finish.last, 0].each_cons(2).map(&:sum)
finish.append(new_row)
end
end
end | true |
ed00d08a799b4744f7a8722073267f5fd35c7349 | Ruby | wefasdfaew2/betting | /lib/migration.rb | UTF-8 | 2,423 | 2.59375 | 3 | [] | no_license | module Migration
extend self
def get_team(team_name)
team = Team.find_by_name(team_name)
team = Team.create({name: team_name}) if team.nil?
team
end
def run_migration
league = League.find_by_name("Ligat ha al")
(27..36).each { |idx|
page_url = "http://football.org.il/League... | true |
3c81dee0b42fccab81806a3a871f64c5753b4ca2 | Ruby | Nova840/phase-0 | /week-5/gps2_2.rb | UTF-8 | 2,746 | 4.125 | 4 | [
"MIT"
] | permissive | # Method to create a list
# input:
# steps:
# define the method with parameters
# cart = {}
#
# output: puts 'Created cart successfully!'
def create_cart(user_cart)
cart = user_cart
puts 'Created cart successfully!'
p cart
end
# Method to add an item to a list
# input: item name and optional quantity
... | true |
d5904bb2514d7cf88e7388b29c8446c77413badf | Ruby | kedarmhaswade/lilutils | /test/misc/misc_pascal_test.rb | UTF-8 | 695 | 2.859375 | 3 | [
"MIT"
] | permissive | require "test/unit"
require File.dirname(__FILE__) + '/../../lib/lilutils'
require 'stringio'
class PascalTest < Test::Unit::TestCase
PASCAL = LilUtils::Misc::Pascal
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
# Do nothing
end
# Called after every te... | true |
fc8d47edda5207628012e3ed02e497855b177e9a | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/anagram/54079dd27fc943299805397ddcbb4e62.rb | UTF-8 | 666 | 3.65625 | 4 | [] | no_license | require 'forwardable'
class Anagram
def initialize(word)
@word = Word.new(word)
end
def match(words)
words.select { |word| @word.anagram?(Word.new(word)) }
end
end
class Word
extend Forwardable
include Comparable
def_delegator :@word, :downcase
def initialize(word)
@word = word
end
... | true |
51622b7197f76d666b8e2b19e16cbdb0781e06c1 | Ruby | austinb847/ping_pong_ruby | /lib/ping_pong.rb | UTF-8 | 464 | 3.421875 | 3 | [] | no_license | require('pry')
class Integer
def ping_pong
num_to_count_to = self
range = (1..num_to_count_to)
ping_pongs = []
range.each() do |number|
if (number.%(3).eql?(0)) & (number.%(5).eql?(0))
ping_pongs.push("ping pong")
elsif (number.%(3).eql?(0))
ping_pongs.push("ping")
e... | true |
16078ea34309d336c27fad3455ea12d46a18c2d0 | Ruby | Winy81/Rails_game | /app/helpers/characters_helper.rb | UTF-8 | 1,546 | 2.765625 | 3 | [] | no_license | module CharactersHelper
include Services::DateTransformer
def life_length_counter(character)
if character.status == 'alive'
length = Time.now - character.created_at
result(length)
else
length = (character.created_at - character.died_on).abs
result(length)
end
end
def param... | true |
7a1e242054e407beaa31bbc92286bc1be6d3ddfb | Ruby | rpazyaquian/wdi_1_miniproject_game | /spec/menu_spec.rb | UTF-8 | 3,541 | 3.3125 | 3 | [] | no_license | require 'pry'
require_relative '../lib/menu'
describe Menu do
before(:each) do
def say_hello
"Hello!"
end
options = {
say_hello: {
text: "Say hello",
action: method(:say_hello).to_proc
}
}
@menu = Menu.new(options)
def say_goodbye
"Goodbye!"
en... | true |
6742e75792f5f50d33fe58f8c20ccc615d031a03 | Ruby | renevp/bakery | /lib/order_line_processing.rb | UTF-8 | 1,958 | 3.328125 | 3 | [] | no_license | class OrderLineProcessing
attr_accessor :max_items, :items
def initialize(max_items, items)
@max_items = max_items
@items = items.sort.reverse
@error = ""
end
def process_order_line
@quantities = []
@results = []
return display_error() if is_items_error?
@remaining = ma... | true |
bd8fe60df96ff363222d8cf292554d76436bbb3c | Ruby | camertron/gelauto | /spec/gelauto_spec.rb | UTF-8 | 4,671 | 2.640625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'spec_helper'
describe Gelauto do
before { index.reset }
let(:index) { Gelauto.method_index }
context 'with simple types' do
it 'identifies method signatures correctly' do
img = nil
Gelauto.discover do
img = GelautoSpecs::Image.new('foo.jpg', 800,... | true |
786ee7698e7f0c9a22375cbe5fcfbf4f1fa09b9a | Ruby | clemensg/algorithms | /ruby/mergesort/mergesort.rb | UTF-8 | 524 | 3.875 | 4 | [
"MIT"
] | permissive | # Mergesort
# Clemens, 2015
#
# [5], [3] => [3, 5]
def merge(a, b)
c = []
until a.empty? && b.empty? do
if a.first && ((b.first && a.first <= b.first) || !b.first)
c << a.shift
else
c << b.shift
end
end
return c
end
def mergesort(n)
if n.nil? || n.empty?
return []
elsif n.lengt... | true |
ba06037dd5f49c17da1bd246896b7361c19b478e | Ruby | fraterrisus/advent2018 | /day15/part1.rb | UTF-8 | 7,078 | 3.390625 | 3 | [] | no_license | #!/usr/bin/env ruby
require './unit.rb'
require 'colorize'
if ARGV[1]
@part_two = true
elf_attack_power = ARGV[1].to_i
else
@part_two = false
elf_attack_power = 3
end
tokens = IO.readlines(ARGV[0]).map { |l| l.rstrip.split(//) }
xdim = tokens.map(&:size).max
@floor = Array.new
tokens.size.times { @floor << Ar... | true |
306fcee1c41c78533d680366ba5b1655d7facaa8 | Ruby | toinou3010/git-thp-floraJ | /Cours_du_13-4-21/exo_11.rb | UTF-8 | 221 | 3.140625 | 3 | [] | no_license | today = 2021
puts "Quelle est ton age ?"
user_age = gets.to_i
user_birth_date = today - userage
f = -1
for i in user_birth_date..today
print i
f += 1
puts " : il y a #{user_age - f} ans, tu avais #{f} ans"
end | true |
332202e553c65172ae457b74a52540908237d997 | Ruby | sbower/fishy_site | /site.rb | UTF-8 | 364 | 2.546875 | 3 | [] | no_license | require 'rubygems'
require 'sinatra'
require 'haml'
get '/' do
data = File.new("data", "r")
line = data.gets
(@room_temp, @tank_temp, @light_on) = line.split("|")
data.close
if @light_on.eql?("0") then
@light = "off"
else
@light = "on"
end
haml :index
end
get '/about' do
haml :about... | true |
88ab359ee2d7464b70c0bc3b93e2da614803bb29 | Ruby | StephanYu/roman_arabic_numerals | /lib/script.rb | UTF-8 | 279 | 3.1875 | 3 | [] | no_license | #!/usr/bin/env ruby
require './number'
num = Number
ARGF.each do |line|
line = line.chomp
if num.arabic?(line)
p num.to_roman(line)
elsif num.roman?(line)
p num.to_arabic(line)
else raise "Input on line #{ARGF.lineno} with value #{line} is not valid."
end
end
| true |
7197b72a58c6e9079717e983ae4ca7961cb7309d | Ruby | iexus/learningruby | /dojos/phonetic_search/spec/phonectic_matcher_spec.rb | UTF-8 | 3,335 | 3.296875 | 3 | [] | no_license | require_relative "../lib/phonetic_matcher"
describe Phonetic::PhoneticMatcher do
let (:surnames_text) {
surnames = []
file_address = File.join(File.dirname(__FILE__), "surnames.txt")
File.open(file_address, "r") do |f|
f.each_line do |line|
surnames << line.delete("\n")
end
end
... | true |
4420208fd62460cc7ca4a94fa55f3f7aa661b847 | Ruby | epotocko/has_sparse_attributes | /lib/active_record/has/sparse_attributes.rb | UTF-8 | 3,888 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'active_record/has/sparse_attributes/storage'
require 'active_record/has/sparse_attributes/column_storage'
require 'active_record/has/sparse_attributes/table_storage'
module ActiveRecord #:nodoc:
module Has #:nodoc:
module SparseAttributes #:nodoc:
def self.included(base) #:nodoc:
base.extend... | true |
7d1a70836233fb88b88a82cecacb6fcdcd8a6657 | Ruby | dantrovato/launch-school | /small_problems/easy8/9_convert_number_to_reversed_array_of_digits.rb | UTF-8 | 2,077 | 4.65625 | 5 | [] | no_license | =begin
Convert number to reversed array of digits
Write a method that takes a positive integer as an argument and returns that
number with its digits reversed. Examples:
reversed_number(12345) == 54321
reversed_number(12213) == 31221
reversed_number(456) == 654
reversed_number(12000) == 21 # Note that zeros get droppe... | true |
51499c9fe9ca259ee10b9e0dc3a1bce8eb8a8c80 | Ruby | rafer/chess | /lib/chess/move.rb | UTF-8 | 1,017 | 3.140625 | 3 | [] | no_license | module Chess
class Move
class IllegalMove < ArgumentError; end
def initialize(origin, destination)
@origin = origin
@destination = destination
end
def bind(board)
@board = board
@piece = board[@origin]
@mover = @piece.color
@captured_piece = board[@destina... | true |
853e675b6e7a29c7aa9d7fbe012e6a4ace835462 | Ruby | crawsible/advent-2019 | /04/lib/viable_password_counter.rb | UTF-8 | 866 | 3.390625 | 3 | [] | no_license | class ViablePasswordCounter
def initialize(range)
@range = range
end
def count
range.count do |number|
same_adjacent_digits?(number) && no_descending_digits?(number)
end
end
def a_count
range.count do |number|
a_same_adjacent_digits?(number) && no_descending_digits?(number)
e... | true |
0163da1615da070f63bb89fffd19cc16fd9d0476 | Ruby | mindaslab/ilrx | /function_variable_arguments.rb | UTF-8 | 157 | 3.40625 | 3 | [] | no_license | # function_variable_arguments.rb
def some_function a, *others
puts a
puts "Others are:"
for x in others
puts x
end
end
some_function 1,2,3,4,5
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.