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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2e82733eda8cb98124848d507760680204365f2b | Ruby | KelsBecker/programming-univbasics-3-build-a-calculator-lab-nyc-web-010620 | /lib/math.rb | UTF-8 | 413 | 3.1875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def addition(num1, num2)
sum=num1+num2
sum
end
addition(5,4)
def subtraction(num1, num2)
sum=num1-num2
sum
end
subtraction(10,5)
def division(num1, num2)
sum=num1/num2
sum
end
division(50,2.0)
def multiplication(num1, num2)
sum=num1*num2
sum
end
multiplication(4,30)
def modulo(num1, num2)
sum=(... | true |
573c9a0d7737cd93b884c0f2ea7d480a509bf2d4 | Ruby | taichi0129/code_collection | /ruby/TECH_collection/39_コントローラーにおけるインスタンス変数の必要性と、paramsの解説.rb | UTF-8 | 1,493 | 2.984375 | 3 | [] | no_license | class ArticlesController < ApplicationController
def show
article = Article.find(params[:id])
end
end
# ①showアクションの中にあるarticleという変数定義ですが、このままだとビューの表示を意図した通りに行うことができません。その理由と解決策を解説してください。
# Railsではコントローラで設定された「インスタンス変数」がビューに渡される仕組みになっている。
# コードのarticleは通常のローカル変数であるためビューで使うことができない。そのため、articleを@articleに変更すればよい... | true |
a07e996b42d5d1e5c09c0142078145b0ecb96196 | Ruby | lostboy/rack-ip-whitelist | /lib/rack-ip-whitelist/netaddr_list.rb | UTF-8 | 573 | 3.15625 | 3 | [] | no_license | require "netaddr"
class NetaddrList
def self.parse addresses=""
new addresses.split(',').collect {|address|
if address['..'].nil?
NetAddr.wildcard(address)
else
ips = address.split '..'
NetAddr.wildcard(ips.first)..NetAddr.wildcard(ips.last)
end
}
end
def i... | true |
d424ba97828da531483f5a451df1c895c8556484 | Ruby | CarlosCalgaro/car-rental | /car_rental.rb | UTF-8 | 3,748 | 3.6875 | 4 | [] | no_license | module CarStyles
SALOON = 0
SUV = 1
HATCHBACK = 2
end
class Car
attr_reader :title
attr_reader :price_per_day
def initialize(title)
@title = title
@price_per_day = 0
end
# The default bonus point for a rent is 1
# If the car is an SUV, it should return the default bonus points + 1... | true |
fb867c8fb9e55e94e146657ee840c85204d794e3 | Ruby | swade19/boris-bikes | /lib/van.rb | UTF-8 | 212 | 2.859375 | 3 | [] | no_license | class Van
attr_reader :broken_bikes
def initialize
@broken_bikes = []
end
def pick_up_broken_bikes(station)
station.get_damaged_bikes.each do |bike|
broken_bikes << bike
end
end
end
| true |
7394772a4ea3619cfce77df20d24b0980e1e7f1d | Ruby | terryblue99/ruby-advanced-class-methods-lab-v-000 | /lib/song.rb | UTF-8 | 1,662 | 3.34375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'pry'
class Song
attr_accessor :name, :artist_name
@@all = []
def self.all
@@all
end
def save
self.class.all << self
end
def self.create
song = self.new
song.save
song
end
def self.new_by_name(new_name)
song = self.new
song.name = new_name
@name = song
end
... | true |
62390c7694046ad06440ee9bf658c3e1765cc25b | Ruby | ilya-the-frog/Ruby-Education | /Educative/Methods.rb | UTF-8 | 563 | 4.03125 | 4 | [] | no_license | # here will be all exercises case they are quite easy
#ex1 - Greet person
def greet1(name)
"Hello #{name}!"
end
#ex2 - Greet with some random
def greet2(name)
hi = ["Hello", "Hi", "Ohai", "ZOMG"]
"#{hi.sample} #{name}!"
end
#ex3 - Miles -> Km
def miles_to_kilometers(miles)
miles * 1.60934
end
#ex4 - Leap y... | true |
cc176dccbb60711df8082adab7d54ecf2f69acdd | Ruby | dhintz89/ttt-with-ai-project-v-000 | /lib/players/computer.rb | UTF-8 | 1,885 | 3.71875 | 4 | [] | no_license | require 'pry'
module Players
class Computer < Player
attr_accessor :board, :game
WIN_COMBINATIONS = [[0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8], [0,4,8], [2,4,6]]
# choose the next move based on current state of the board
def move(board)
puts "Computer:"
case
#check for winni... | true |
aeab0a4ecb829473f323266d8b875dbebabb0986 | Ruby | iBryan6/G5-Automation-Tests-A-Team | /Main/PageObjects/Location/LocationPages.rb | UTF-8 | 7,351 | 2.625 | 3 | [
"MIT"
] | permissive | # This class will show all the locators and methods of this Page
require "rubygems"
require "webdrivers"
class LocationPages
#CONSTRUCTOR
def initialize(driver,wait)
@driver = driver
@wait = wait
end
#NAVIGATION PAGES
def pageTitleFirstChild
return @driver.find_element(:xp... | true |
6cafd911e95e9301fe761591452a49a1f7a311d8 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grains/6e6cccc82e04470aa3580d6b2352f539.rb | UTF-8 | 260 | 3.015625 | 3 | [] | no_license | class Grains
# http://en.wikipedia.org/wiki/Wheat_and_chessboard_problem
NR_OF_SQUARES_ON_CHESSBOARD = 64
def square nr
2 ** (nr - 1)
end
def total
# optimization of geometric series
square(NR_OF_SQUARES_ON_CHESSBOARD) * 2 - 1
end
end
| true |
c07a0f9388c23ae2c4bd478a350794e2363ce51f | Ruby | nyongee12/coderbyte | /easy/ArrayAddition1.rb | UTF-8 | 305 | 3.484375 | 3 | [] | no_license | def ArrayAdditionI(arr)
# code goes here
arr.sort!
sum = 0
for i in 0..arr.length-2
sum += arr[i]
end
return sum >= arr[arr.length-1] ? true : false
end
# keep this function call here
# to see how to enter arguments in Ruby scroll down
ArrayAdditionI(STDIN.gets)
| true |
2d26e040e0714251badb34f6ec18053576d554c9 | Ruby | mrkamot1979/learningruby | /enum/Player.rb | UTF-8 | 319 | 3.53125 | 4 | [] | no_license |
class Player
include Comparable
attr_accessor :name, :score
def <=>(other_player)
score <=> other_player.score
end
def initialize(name, score)
@name, @score = name, score
end
end
=begin
player1 = Player.new("nenu", 100)
player2 = Player.new("tak", 90)
puts player1.score < player2.score
=end
| true |
611fd649e0db3165e5a85fed7a78e18f24279e1e | Ruby | TonGarcia/NitroStart | /app/models/concerns/name.rb | UTF-8 | 825 | 2.90625 | 3 | [] | no_license | # Capability name helper methods
module Name
extend ActiveSupport::Concern
# return it last name on composite name
def last_name
self.name.split(' ').last
end
# return it first name on composite name
def first_name
self.name.split(' ').first
end
# return it name as an array
def names
se... | true |
7eccf488183bda84a996239163a1913a7042dada | Ruby | nacltsutomu/ruby-exercise | /k_testunit_6.rb | UTF-8 | 716 | 3.3125 | 3 | [] | no_license | #1
#特異メソッド
require "test/unit" #この記述をすることでTest::Unit::TestCaseが実行される
class Drink
def order
"モカ"
end
end
#assert_equal(期待値),(実際の値)
class TestSample < Test::Unit::TestCase #Test::Unit::TestCaseを継承したTestSampleクラスを定義
def setup
@drink1 = Drink.new
@drink2 = Drink.new
def @drink1.re... | true |
38987f110690edfa60941da72e6c1ca8ca37588b | Ruby | ColeRBradley/backend_mod_1_prework | /final_prep/annotations.rb | UTF-8 | 2,640 | 4.34375 | 4 | [] | no_license | # Add your annotations, line by line, to the code below using code comments.
# Try to focus on using correct technical vocabulary.
# Use the # to create a new comment
# Build a Bear
# Define a method of build_a_bear and assign its parameters.
def build_a_bear(name, age, fur, clothes, special_power)
# Interpulate the p... | true |
c8e0603f53f783ae15fac6e50f547d085ab14436 | Ruby | perlun/jlox | /scripts/generate_ast_classes.rb | UTF-8 | 2,182 | 3.078125 | 3 | [] | no_license | #!/usr/bin/env ruby
Type = Struct.new(:class_name, :fields)
Field = Struct.new(:type, :name)
def define_visitor(base_name, types)
stream = StringIO.new
stream.puts ' interface Visitor<R> {'
types.each { |t|
stream.puts " R visit#{t.class_name}#{base_name}(#{t.class_name} #{base_name.downcase});"
}
... | true |
1fa6604dd6d9610da3847c0cf246c64c0ff04be5 | Ruby | e-kravchenko/RoR_lesson1- | /1.rb | UTF-8 | 150 | 3.453125 | 3 | [] | no_license | puts 'Введите число:'
numeric = gets.chomp
sum = numeric.split("").map{|x| x.to_i}.reduce(:+)
puts "Сума цифр числа #{sum}" | true |
7ceb59f12a35b7860712e0cc640bc8c7d1073d4d | Ruby | Eden-Eltume/101 | /101_Exercises/Small_Problems3/7_Easy7/ex5.rb | UTF-8 | 1,003 | 4.59375 | 5 | [] | no_license | =begin
Problem - Given a string starting with caps, alternate between uppercase and capital letters. Non-leters count as a character.
Example - 'I Love Launch School!' -> 'I LoVe lAuNcH ScHoOl!'
Data Structure - string to new string
Approach - LOOP through the string
IF current_char is the first letter, cap... | true |
0ff031a28703d7c8e5b321fde99ccbbd5073fe6a | Ruby | travissanon/code-katas | /ruby-katas/fizz-buzz.rb | UTF-8 | 316 | 3.828125 | 4 | [] | no_license | def FizzBuzz(max)
num = 1
result = []
max.times do
if num % 3 == 0 && num % 5 == 0
result.push('FizzBuzz')
elsif num % 3 == 0
result.push('Fizz')
elsif num % 5 == 0
result.push('Buzz')
else
result.push(num)
end
num += 1
end
return result
end
FizzBuzz(100)
| true |
8ea38c75c5b87cef8eb2da193a25f6f9dd87ef3f | Ruby | banana-peel-team/mtg-chest-web | /app/queries/editions.rb | UTF-8 | 1,074 | 2.640625 | 3 | [] | no_license | module Queries
module Editions
extend self
def sort_name(ds, dir)
if dir == :asc
ds.order(Sequel.asc(:edition_name))
else
ds.order(Sequel.desc(:edition_name))
end
end
def sort_date(ds, dir)
if dir == :asc
ds.order(Sequel.asc(:edition_date))
else
... | true |
3a1de628f7cb9fc103a5b262e001bafeb0a97d10 | Ruby | TALlama/Alexandria | /lib/readers/api_reader.rb | UTF-8 | 2,768 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'date'
module Alexandria
# pull tweets directly out of Twitter's public API
class ApiReader
DEFAULT_PAGE_RANGE = 0..15
DEFAULT_PAGE_COUNT = 200
include TweetReader
include Twitter::Autolink
include HierarchalOutputUser
include UserCacheUser
attr_accessor :opts, :api_delay
def initial... | true |
8ec9a555f9a1c7f3ffd0b9d8089410f46250dd13 | Ruby | doolin/vroom | /lib/vroom.rb | UTF-8 | 1,202 | 2.546875 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/async'
require 'pool'
class Vroom < Sinatra::Application
register Sinatra::Async
GC_INTERVAL = (ENV['GC_INTERVAL'] || 1000).to_f/1000.0
puts "GC_INTERVAL = #{GC_INTERVAL}s"
def self.do_gc_thing
@@interval ||= proc { GC.disable; Time.now.to_f }.call
now = Time.now.t... | true |
99b1ca753f80b118d821f1ae95edb806c4a677cc | Ruby | stonefield/cipher_bureau | /lib/cipher_bureau/statistic.rb | UTF-8 | 2,068 | 2.71875 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2013 Dynamic Project Management AS
# Copyright (c) 2013 Knut I. Stenmark
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation ... | true |
3d1239cf01e7eddab8cf5e25942ef966febb4afd | Ruby | IrukNuj/programming_lessons | /create_triangle.rb | UTF-8 | 141 | 3.25 | 3 | [] | no_license | puts "段数を入力してね"
i = gets.chomp.to_i
(0..i-1).each do |a|
(0..a).each do |b|
print "*"
end
print "\n"
end
| true |
34b19999f397d84e12863977b067cffc78da0d4b | Ruby | dyjakan/misc | /hashify.rb | UTF-8 | 558 | 3.03125 | 3 | [] | no_license | #!/usr/bin/env ruby
#
# Hack the planet.
#
require 'digest/sha1'
def rename(file_path)
file = File.open(file_path, 'rb')
data = file.read
file.close
hashed = Digest::SHA256.hexdigest(data)
puts "#{ARGV[0]}/#{hashed}.#{file_path.split('.')[-1]} = #{file_path}"
File.rename(file_path, "#{ARGV[0]}/#{hashed}.#... | true |
86b7d1a8a20f51016c89d495d81f852673905a51 | Ruby | viswans83/breakout-ruby | /lib/breakout/event.rb | UTF-8 | 269 | 2.90625 | 3 | [
"MIT"
] | permissive | module Breakout
class EventQueue
def initialize
@data = Array.new
end
def add_event ev
data.unshift(ev)
end
def next_event
data.pop
end
def empty?
data.empty?
end
private
attr_reader :data
end
end
| true |
737641c875f126d05203ef8bb786de2a20df7e83 | Ruby | jessepollak/rbdb | /lib/rbdb/db/index.rb | UTF-8 | 442 | 2.5625 | 3 | [] | no_license | module RBDB
module DB
class Index
def initialize(key)
@key = key
@store = Hash.new{|hash, key| hash[key] = Array.new}
end
def insert(doc)
@store[doc.send(@key)] << doc
end
def query(key)
... | true |
5853a1ec3b9c72936a3617a5a47201ec2108c558 | Ruby | shuryak/ITMO | /course_2/formal_languages/lab_2(regex_recognizer)/regex.rb | UTF-8 | 1,368 | 3.515625 | 4 | [] | no_license | #! /usr/bin/env ruby
class State
def initialize(name, isFinal)
@name = name
@transitions = []
@isFinal = isFinal
end
def addTransition(char, destination)
@transitions.push([char, destination])
end
def addTransitions(transitions)
transitions.each do |transition|
addTransition(trans... | true |
27fd41e8cc1005cec1c909910dfb2664847aabaf | Ruby | AutumnJ/ruby-collaborating-objects-lab-v-000 | /lib/song.rb | UTF-8 | 421 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #require "pry"
class Song
attr_accessor :name, :artist
def initialize(name)
@name = name
end
def self.new_by_filename(file)
#binding.pry
artist = file.split(/\s-\s/)[0]
song = file.split(/\s-\s/)[1]
new_song = self.new(song)
new_song.artist_name = artist
new_song
end
def artist_name=... | true |
6bfed48d83a474cb48e8fa1a87ced3688a1423a8 | Ruby | rcgutierrez/ruby-exercises | /08-ruby-exercises-arrays.rb | UTF-8 | 1,049 | 4.53125 | 5 | [] | no_license | # Arrays
# Array iniitalizes array
# friends = Array[].new
friends = Array["Kevin", "Karen", "Oscar"]
puts friends
# arr[i] -> will output i index of arr
puts friends[2]
# arr[-i] -> will output from the end of arr, starting from -1
puts friends[-1]
# arr[i, j] -> will output from i up to, but not including, j
put... | true |
e5514e350a1a69bb83ad1b8900f36caf93d1f0e0 | Ruby | nhh/spectr | /bin/spectr | UTF-8 | 575 | 2.625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'optparse'
# Usage: spectr .
# Usage: spectr test/**
# Usage: spectr test/*.rb
# This will hold the options we parse
options = {}
OptionParser.new do |parser|
# Whenever we see -n or --name, with an
# argument, save the argument.
parser.on('-ff', '--fail-fast', 'Enable fail fast') ... | true |
b2c5ce6d1bd82739345bb299fafdd26bcbc175bd | Ruby | giffenaw/themoviedbsearch | /app/controllers/home_controller.rb | UTF-8 | 1,988 | 2.5625 | 3 | [] | no_license | class HomeController < ApplicationController
def index
response = HTTParty.get("https://api.themoviedb.org/3/search/movie?api_key=0ff635a62d30604c0001931e63a24938&query=The+Parent+Trap")
@total_results = 0
@total_pages = 0
@results_message = ""
@index = Array.new
@titles = Array.new
@images = Ar... | true |
fb12f27125322402290b2784b3b00881d2a41f92 | Ruby | jagrit1/RSpec | /person.rb | UTF-8 | 1,432 | 3.765625 | 4 | [] | no_license | require "date"
class Person
attr_accessor :dob, :first_name, :surname
attr_reader :emails, :phone_numbers
def initialize(fname = "Jagrit Gyawali", sname, dob)
@dob = Date.parse(dob)
@first_name = fname.capitalize
@surname = sname.capitalize
@emails = []
@phone_numbers = []
end
def fullname
"#{first_n... | true |
0d4691b0be8f41aba57cdca230e8143d4cabf1bf | Ruby | mbrown78/LS_ruby_basics | /return/BLD_part3.rb | UTF-8 | 180 | 3.578125 | 4 | [] | no_license | def meal
return 'Breakfast'
'Dinner'
end
puts meal
#Breakfast
#when return is executed, it tells the method to end,
#which means anything after that line won't be processed. | true |
b756b5c660f35bdb77a81a87d2a141ceec48cf4c | Ruby | BideoWego/assignment_sort | /lib/benchmark.rb | UTF-8 | 514 | 3.21875 | 3 | [] | no_license | def benchmark(array, n=100)
puts "\n\nReady. Set. Sort!"
puts array.length > 100 ? "Given: #{array}"[0..100] + " ..." : "Given: #{array}"
results = {}
[
:bubble_sort,
:select_sort,
:insert_sort,
:merge_sort,
:quick_sort,
:count_sort,
:radix_sort
].each do |m|
before = Time.now
... | true |
c4574f148deea97f99b0805bf3812d03301314b4 | Ruby | dgokman/advent_of_code_2019 | /aoc_2019_10.rb | UTF-8 | 2,498 | 2.78125 | 3 | [] | no_license | A = File.read("aoc_2019_10.txt")
require 'set'
# 1
hash = {}
arr = A.split("\n").map {|x| x.split("")}
for x in 0..arr[0].length-1
for y in 0..arr.length-1
if arr[y][x] == "#"
hash[[y,x]] = 1
end
end
end
set = Set.new
for x in 0..arr[0].length-1
for y in 0..arr.length-1
next if arr[y][x] ... | true |
c45670ea75cd4d15a486a4be981d60f64838a93c | Ruby | AnnaLindegren/emergency-compliment | /lib/compliment.rb | UTF-8 | 1,746 | 3.125 | 3 | [] | no_license | class Compliment
attr_reader :message, :color, :image
def make_hash_message
f = File.open('./lib/compliments.txt')
message_array = Array.new
f.each_line do |line|
message_array << line
end
@message_hash = Hash.new
message_array.each_with_index do |line, idx|
idx +=1
@me... | true |
711e5a4a68c044a6da9567c57036b3df755ae6f4 | Ruby | EmilReji/ruby_small_problems | /Easy_6/10.rb | UTF-8 | 273 | 4.03125 | 4 | [] | no_license | =begin
given the num, run a loop num times
within loop start by printing num - 1 spaces and 1 *
then decrease space by 1 and * by 1
repeat till done
=end
def triangle(num)
1.upto(num) do |val|
puts ' ' * (num - val) + '*' * (val)
end
end
triangle(5)
triangle(9)
| true |
b818165432e0e0a8d78e4f099a6d93d62da1fa3d | Ruby | nate-alspaugh/ruby-challenges | /magic8.rb | UTF-8 | 730 | 3.25 | 3 | [] | no_license | # get a persons question
# -using the "gets" method
# randomly select an answer
# -maybe loops?
# -maybe arrays?
# -maybe boolen?
# send that answer via twilio
require 'rubygems'
require 'twilio-ruby'
puts "Give me a question and I'll text you your fortune..."
answer = gets
possible_answer = ["It is certa... | true |
5772dc6b51bb2a63a78a303516b2f1371f4c29d2 | Ruby | ricardo75777/Project7 | /Game/Data/Scripts/source/Sprite_RichText.rb | UTF-8 | 2,162 | 2.734375 | 3 | [] | no_license | class Sprite_RichText < Sprite
MAX_LIFE = 60
attr_accessor :dead
def initialize(text,xy,color=Fuc::WHITE_COLOR,size=20,viewport=nil)
viewport ? super() : super(viewport)
@text = text
@xy=xy
if xy.is_a?(Array)
@base_x = x
@base_y = x
@offset_x = 0
@offset_y = 0
... | true |
dfbdbebd83a52245139ed371e9f7b50740350334 | Ruby | saadremani/exo-1-21 | /exo_13.rb | UTF-8 | 219 | 3.5 | 4 | [] | no_license | puts " Ecrire ton année de naissance"
annee_de_naissance =gets.chomp.to_i
annee_en_cours = 2019
while (annee_de_naissance <= annee_en_cours)
puts annee_de_naissance
annee_de_naissance = annee_de_naissance + 1
end | true |
4da66d6e40356c00eec6390e0d517e96c117871f | Ruby | mgborgman/ls_130_ruby_foundations | /lesson_2/exercises/sieve.rb | UTF-8 | 329 | 3.5625 | 4 | [] | no_license | class Sieve
def initialize(limit)
@range = (2..limit).to_a
end
def primes
@range.each_with_index do |_, index|
current_number = @range[index]
@range.delete_if {|number| number % current_number == 0 && number != current_number}
break if current_number == @range.last
end
@range
... | true |
7d7221ecba633f66df96669a3f3c38cef18883e7 | Ruby | Jonwheeler/trawler | /lib/trawler/spider.rb | UTF-8 | 356 | 2.828125 | 3 | [
"MIT"
] | permissive | require "open-uri"
module Trawler
class Spider
attr_reader :page, :full_url
def initialize(url)
@url = url
end
def call
get_page
self
end
def full_url
@full_url ||= URI.parse(@url).scheme.nil? ? 'http://' + @url : @url
end
def get_page
@page ||= op... | true |
d00c21b3e79e8e93cfdbc984143ff57f0726a4be | Ruby | gxx/bahrainhub | /app/models/user.rb | UTF-8 | 1,941 | 2.625 | 3 | [] | no_license | # == Schema Information
#
# Table name: users
#
# id :integer(4) not null, primary key
# username :string(255)
# email :string(255)
# encrypted_password :string(255)
# password_salt :string(255)
# reset_password_token :string(255)
# is_admin ... | true |
174723499cc6496d41924ca501e476b91c1a559c | Ruby | agakow/Boris-bikes | /lib/docking_station.rb | UTF-8 | 680 | 3.171875 | 3 | [] | no_license | require_relative 'bike'
require_relative 'van'
require_relative 'garages'
class DockingStation
DEFAULT_CAPACITY = 20
attr_reader :capacity
attr_accessor :bikes
#attr_reader :brokenbikes
def initialize(capacity = DEFAULT_CAPACITY)
@bikes = []
@capacity = capacity
end
def release_bike
fail 'N... | true |
04c4cc3e7fbdfe6bfbddec155e065c684c94b5c6 | Ruby | iseessel/Algorithms | /dynamic programming/subsequence.rb | UTF-8 | 2,230 | 3.84375 | 4 | [] | no_license | require 'byebug'
class Subsequence
def initialize(str_one, str_two)
@str_one = str_one
@str_two = str_two
@matrix = Array.new(str_one.length + 1) {
Array.new(str_two.length + 1)
}
end
#BOTTOM UP WITH DYNAMIC PROGRAMMING
def subsequence
setup_basecase
(1...@matrix.length).each ... | true |
e38295d1f317442c84f451f454833803e9d51de0 | Ruby | xtone/programming-contest | /20140602_PartElf/take/main.rb | UTF-8 | 569 | 3.21875 | 3 | [] | no_license | require 'pp'
casecount = 0
cases = []
open( ARGV[0] ) {|f|
casecount = f.gets.to_i
casecount.times {
cases.push(f.gets.split('/').map{|s| s.to_i })
}
}
i = 0
cases.each {|c|
i += 1
ans = 1
if c[1] % 2 != 0
puts "Case ##{i}: impossible"
next
end
a = Rational(c[0], c[1])
flag = false
... | true |
d3b38cf7509d3ba9350cd5bf01531e525ea9ca9f | Ruby | HeroCoders/timber-ruby | /lib/timber/log_entry.rb | UTF-8 | 3,202 | 2.734375 | 3 | [
"ISC"
] | permissive | require "socket"
require "time"
require "timber/contexts"
require "timber/events"
module Timber
# Represents a new log entry into the log. This is an intermediary class between
# `Logger` and the log device that you set it up with.
class LogEntry #:nodoc:
BINARY_LIMIT_THRESHOLD = 1_000.freeze
DT_PRECISI... | true |
7f2a08c0b75ff3ecb0d03702188ce71a4693cc52 | Ruby | clok/scrimps | /datadog/create_rabbitmq_timeboard.rb | UTF-8 | 821 | 2.5625 | 3 | [] | no_license | # Make sure you replace the API and/or APP key below
# with the ones for your account
require 'rubygems'
require 'dogapi'
# Account to sync from (Synctree)
from_api_key = ''
from_app_key = ''
# Account to sync to
to_api_key = ''
to_app_key = ''
from_dog = Dogapi::Client.new(from_api_key, from_app_key)
to_dog = Doga... | true |
3ac7da1c7b5a46c82d58a945117d6cde5730069b | Ruby | remnantkevin/ruby | /ruby_essential_training/project_attempt/init.rb | UTF-8 | 1,575 | 3.796875 | 4 | [] | no_license | require_relative 'restaurant'
require './guide'
#functions here in init? e.g. read in file?
restaurants = [] #proper way?
File.open("data.txt","r") do |file|
#while line = file.gets
file.each_line do |line|
line_split = line.chomp.split(',')
restaurants << Restaurant.new(line_split[0],line_split[1],line_s... | true |
b470b7e2a59137de0f0eaac218c03667b6a5deeb | Ruby | marcko/ruby2 | /case.rb | UTF-8 | 689 | 3.8125 | 4 | [] | no_license | class Case
def initialize()
end
def prueba()
edad=101
res=case edad
when 0..11 then "es menor"
when 12..15 then "es adolescente"
when 16..50 then "es adulto"
when 51..100 then "es viejito"
else "ponte al tiro"
end
print res
end
def prueba2()
nombre = "memo"
respuesta = case nombre
when "ma... | true |
9178428c6654269e1896857762430a4238926cf1 | Ruby | gsharp/cs177 | /homework/hw4/hw4_old.rb | UTF-8 | 3,262 | 3.46875 | 3 | [] | no_license | #!/usr/local/bin/ruby1.9 -w
#
# Author: Glen Cuthbertson
# Date : 10/10/2009
# Program Name: hw4.rb
# - make file of 20,000 random ip addresses
# - remove duplicate ip's
# - report which id's were duplicated + how many times
# - make file of non duplicated ips
# - report math/proof to vali... | true |
c24bdc2ec9b3c5ef5df51399018c221ae6e9872f | Ruby | alabs/carchi_tramites | /test/models/slot_test.rb | UTF-8 | 636 | 2.734375 | 3 | [] | no_license | require "test_helper"
class SlotTest < ActiveSupport::TestCase
def slot
@slot ||= Slot.new
end
def test_valid
assert_not slot.valid?
assert slot.errors[:dow].include? "no puede estar en blanco"
assert slot.errors[:starts_hour].include? "no puede estar en blanco"
assert slot.errors[:ends_hour... | true |
00cf0f5abae80c1179d4a7aee7b286803531e423 | Ruby | cider-load-test/markable | /spec/markable_spec.rb | UTF-8 | 2,017 | 3.125 | 3 | [] | no_license | require File.join(File.dirname(__FILE__), '..', 'lib', "markable")
class Sample
include Markable
attr_reader :title, :text
def initialize(title, text)
@title, @text = title, text
end
def format
mab do
html do
head do
title @title
end
body do
p @... | true |
72f85f7b4dbb38ae0f34ed2ffb62c6a5efd37a2e | Ruby | jdan/adventofcode | /2017/rb/2017/02b-spreadsheet.rb | UTF-8 | 361 | 3.34375 | 3 | [] | no_license | puts ARGF.map { |line|
list = line.chomp.split.map &:to_i
line_result = nil
0.upto(list.size - 2) do |i|
(i+1).upto(list.size - 1) do |j|
if list[i] % list[j] == 0
line_result = list[i] / list[j]
elsif list[j] % list[i] == 0
line_result = list[j] / list[i]
end
e... | true |
cb67300917cd18a0dbdc2f4455efcc2a95245d34 | Ruby | tortitommaso/quiz | /unique_char_in_string/unique_char_in_string.rb | UTF-8 | 213 | 3.65625 | 4 | [] | no_license | class UniqueCharInString
def initialize
@char_map = {}
end
def verify string
string.each_char {|c|
if @char_map.has_key? c
return false
else
@char_map[c] = true
end
}
true
end
end | true |
20e27fb9fa71849bbaf4a16d5dcf3739df052739 | Ruby | oli-gra/nyc-pigeon-organizer-london-web-career-031119 | /nyc_pigeon_organizer.rb | UTF-8 | 353 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def nyc_pigeon_organizer(data)
pigeon_list = {}
data.each do |stat_key,stats|
stats.each do |stat,pigeons|
pigeons.each do |pigeon|
pigeon_list[pigeon] ||= {}
binding.pry
pigeon_list[pigeon][stat_key] ||= []
pigeon_list[pigeon][stat_key] << stat.to_s
en... | true |
34cead425733d3ad14138a70477cd713872e7d96 | Ruby | tpdorsey/tap-utils | /tap-avg-grades.rb | UTF-8 | 4,197 | 3.203125 | 3 | [
"MIT"
] | permissive | require 'json'
require 'optparse'
ARGV << '-h' if ARGV.empty?
# Lookup table for float grade to letter grade
# Return array includes:
# - Letter grade
# - Index
# - 0 to 5 scale raw
# - 0 to 5 stars scale rounded to .5
# - 60 to 100 scale similar to BeerAdvocate
# - 0 to 4 scale
def gradeLookup(grade)
if grade <= 0... | true |
9be5fc593c0fe356a4bb0e76b64eb29f9f9b6a25 | Ruby | jongillies/barnyard | /barnyard_dns/lib/barnyard_dns.rb | UTF-8 | 888 | 2.578125 | 3 | [
"MIT"
] | permissive | require "barnyard_dns/version"
require "barnyard_harvester"
require "json"
require "dnsruby"
module BarnyardDns
class DnsObject
attr_reader :synchronizer, :began_at, :ended_at
def initialize(args)
@began_at = Time.now
@debug = args.fetch(:debug) { false }
@log = args.fetch(:logger) { ... | true |
8be5216d2094d4dafc671eeb48238a10c4692cfa | Ruby | RomanADavis/challenges | /daily-programmer/easy/challenge1.rb | UTF-8 | 688 | 3.84375 | 4 | [] | no_license | #create a program that will ask the users name, age, and reddit username. have
#it tell them the information back, in the format:
##your name is (blank), you are (blank) years old, and your username is (blank)
#for extra credit, have the program log this information in a file to be
#accessed later.
def input(typ... | true |
b1e8303967ce42c49a3124fa0e5dc44333125945 | Ruby | zackshepKSR/TicTacToe | /TicTacTest.rb | UTF-8 | 2,817 | 4.4375 | 4 | [] | no_license | # TO DO:
# * Add tie game message
# * Get rid of these global variables and put the board in a class after i have the logic working.
#--------------------------------------------------------------
# Create the game postions with a hash. Using numbers to reduce
# input error and make it easy to check if a cell is alre... | true |
6e1a096c6f6a295f8fe5a3829236ebf782dbd5a2 | Ruby | sashka3076/joomlascan | /lib/joomlascan/output.rb | UTF-8 | 1,769 | 2.9375 | 3 | [] | no_license | # requires
require 'colorize'
require 'readline'
module JoomlaScan
module Output
attr_accessor :use_colours
def print_line(prefix, text, new_line = true)
print prefix
if use_colours
print " #{text}".light_white
else
print " #{text}"
end
print "\r\n" if new_lin... | true |
72f69ac852b1816afdc347228c0fd053019c507c | Ruby | sami-p/enigma | /lib/key.rb | UTF-8 | 164 | 3.0625 | 3 | [] | no_license | class Key
def self.generate
nums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
key = []
5.times { key << nums.sample }
key.join
end
end
| true |
0d3f8626a25352d80baf86a37dc91c67b823f09e | Ruby | logandk/acts_as_name | /test/acts_as_name_test.rb | UTF-8 | 1,925 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'test/unit'
require 'test_helper'
require 'acts_as_name'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :cooks do |t|
t.column :first_name, :string
t.column :last_name, :string
... | true |
2b4c08760235625b7c18cfc949bfb97c74051b60 | Ruby | arbivelaj/batch593 | /fd1/livecode/repositories/order_repository.rb | UTF-8 | 1,487 | 3.203125 | 3 | [] | no_license | require "csv"
class OrderRepository
def initialize(csv_file, meal_repository, employee_repository, customer_repository)
@csv = csv_file
@meal_repository = meal_repository
@employee_repository = employee_repository
@customer_repository = customer_repository
@orders = []
load_csv if File.exist?(... | true |
74d2410f25197e0cd47ada297e47af9ef500fc66 | Ruby | Joshua-Tukman/flash_cards | /flashcard_runner.rb | UTF-8 | 505 | 3.25 | 3 | [] | no_license | require './lib/card'
require './lib/turn'
require './lib/round'
require './lib/deck'
card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM)
card_3 = Card.new("Desc... | true |
8d2facce56cde6f6586951d1658f542cb4d64b2c | Ruby | nicosuave/siriproxy-arduino | /lib/siriproxy-arduino.rb | UTF-8 | 1,263 | 2.578125 | 3 | [] | no_license | require 'cora'
require 'siri_objects'
require 'pp'
require 'dino'
#######
# siriproxy-arduino is boilerplate code for controlling your Arduino from Siri.
# I hope you find this as useful as I do. Home automation from your iPhone...
######
class SiriProxy::Plugin::Arduino < SiriProxy::Plugin
def initialize(config)
... | true |
a37739fbebfc922fa1710f443976cf1b60d1522b | Ruby | lpires/train-router | /app/models/path.rb | UTF-8 | 189 | 3.046875 | 3 | [] | no_license | class Path
attr_accessor :nodes, :cost, :final
def initialize node, cost=0, final=false
@nodes = node.kind_of?(Array)? node : [node]
@cost = cost
@final = final
end
end
| true |
755103f4807a18f618959d5ab35f910c15757707 | Ruby | jb-start-here/ruby-start-here | /Misc/augementing_method_behavior.rb | UTF-8 | 702 | 3.671875 | 4 | [
"MIT"
] | permissive | # the old way - using alias_method (created a with and without )
# doggo.rb - maybe a gem file or another library
module Doggo
class Chihuahua
def bark
"woof!"
end
end
end
# now you want to augment/modify good_boi? method
# somewhere else in our_code.rb
module Doggo
class Chihuahua
def bark_... | true |
22269ca6390c9571b0877c642ce49bf4e143d9b0 | Ruby | zhaoj1/ruby-enumerables-reverse-each-word-lab-nyc-web-082619 | /reverse_each_word.rb | UTF-8 | 124 | 3.46875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(str)
new = str.split
new.collect do |word|
word.reverse!
end
new = new.join(" ")
new
end | true |
a0ed6de0c515c0dad8ee6054014120dcb5bf58d6 | Ruby | oscos/launch_school | /rb101/lesson5/practice_problems/x01.rb | UTF-8 | 587 | 3.59375 | 4 | [] | no_license | =begin
Launch School: RB101 Programming Foundations - Lesson 5
ExerciseName: [Lesson 5 - Practice Problems](https://launchschool.com/lessons/c53f2250/assignments/f524e910)
FileName: x01.rb
Answered On: 10/25/2020
=end
# require "pry"
# require "pp"
# How would you order this array of number strings by descending nume... | true |
6dbeb7a6ac506093ba3515a8aa7ad96ca6700262 | Ruby | CrowdHailer/shallot | /test/method_matcher/method_test.rb | UTF-8 | 1,969 | 2.734375 | 3 | [
"MIT"
] | permissive | require_relative '../test_config'
module Shallot
class MethodMatchersTest < MiniTest::Test
# string matching
def test_matches_single_method
matcher = MethodMatcher.for('GET')
match = matcher.new('GET')
assert_equal true, match.match?
end
def test_fails_single_method
matcher =... | true |
83cc3405447471d0c7699585667191d2d856c117 | Ruby | Joshua-Tukman/Enigma | /test/shift_test.rb | UTF-8 | 1,450 | 3.046875 | 3 | [] | no_license | require_relative "../test/test_helper"
require 'minitest/autorun'
require 'minitest/pride'
require './lib/date'
require './lib/key'
require './lib/shift'
class ShiftTest < Minitest::Test
def test_it_exists
date = Date.new
key = Key.new("02715")
shift = Shift.new(key, date)
assert_instance_of Shift, ... | true |
1df9c781b5985cbf03122b950b29671f13ff802d | Ruby | ninkibah/icu_ratings_app | /app/presenters/tournaments/fide_data.rb | UTF-8 | 1,602 | 2.640625 | 3 | [
"MIT"
] | permissive | module Tournaments
class FideData
attr_reader :status, :updates
class Matches
attr_reader :fid, :fed, :dob
def initialize(fid, fed, dob, matches, max_samples=3)
@fid, @fed, @dob = fid, fed, dob
@matches = matches
@max_samples = max_samples
end
def count
... | true |
858de053f3c7f813d1c252d2ce06943e12e71fe2 | Ruby | JBelta/pantry_2005 | /test/recipie_test.rb | UTF-8 | 1,356 | 3.09375 | 3 | [] | no_license | require './lib/ingredient'
require './lib/recipe'
require 'minitest/autorun'
require 'minitest/pride'
class RecipeTest < Minitest::Test
def setup
@ingredient1 = Ingredient.new({
name: "Cheese",
unit: "oz",
calor... | true |
e5a874f9f8cdb310a6d5bd4b09983fd9f20d6423 | Ruby | huynhngoccanh/cra_1 | /engines/czardom_models/spec/models/event_spec.rb | UTF-8 | 677 | 2.5625 | 3 | [
"MIT"
] | permissive | require "rails_helper"
describe Event do
context "timeframe" do
let(:timeframe) { "2015-01-20 01:35am to 2015-01-20 03:45pm" }
let(:start_at) { DateTime.new(2015, 1, 20, 1, 35) }
let(:end_at) { DateTime.new(2015, 1, 20, 15, 45) }
it "gets timeframe from start_at and end_at" do
event = Event.n... | true |
9aed840aaff45d7081aa2e56cb8d116173dc68d4 | Ruby | shahwarspall/learn-co-sandbox | /learning-case.rb | UTF-8 | 174 | 2.625 | 3 | [] | no_license | greeting = "unfriendly_greeting"
case greeting
when
"unfriendly_greeting"
puts "What do you want?????"
when "friendly_greeting"
puts "Hi! How are you?"
end | true |
0eb768ffd8a3b48f2f35b0f5c89a05afa7b24099 | Ruby | Rmartinez75/Launch_School | /Prog_BackEnd_Prep/Variables/name.rb | UTF-8 | 184 | 3.53125 | 4 | [] | no_license | puts 'What is your name?'
name = gets.chomp
puts 'What is your last name'
last_name = gets.chomp
10.times do |n|
puts 'Nice to meet you ' + name + ' ' + last_name
end
| true |
f04ea8098f648adee01e67d929135b955ea336b3 | Ruby | michaelrizzo2/Ruby-Development | /string_concatenation.rb | UTF-8 | 315 | 3.5 | 4 | [] | no_license | #!/usr/bin/ruby
#String concatenation can be done in ruby using <<,+ or a blank space
puts "String concatenation in ruby using <<"
s="Hello"<<"World"
puts s
puts "String concatenation in ruby using +"
s="Hello" + "World"
puts s
puts "String concatenation in ruby using a blank space"
s="Hello" "World"
puts s
| true |
3b398cdf7bd5f1bfd1e3d6db96af0c8925c927de | Ruby | arianchemist/reversestrings | /reverserb.rb | UTF-8 | 139 | 3.4375 | 3 | [] | no_license |
l = Array["h" , "e" , "l" , "l" , "o"]
puts "normal string === #{l}"
puts "reverse string ==== " + l[4] + l[3] + l[2] + l[1] + l[0] | true |
8f17adba663758ac26a36c445d84b53329264717 | Ruby | rsmease/ruby-misc | /subarray_maker.rb | UTF-8 | 427 | 3.109375 | 3 | [] | no_license | def make_parts(arr, chunk_size)
if (arr.length <= chunk_size)
if arr.length === 0
return arr
else
return [arr]
end
end
num_parts = (arr.length / chunk_size).floor
result = []
for part in 0...num_parts
result.push(arr[(part*chunk_size)...((part*chunk_size) + chunk_size)])
end
if arr.length % (nu... | true |
12df0b5253c353c43676da00f8391309b06fd8fa | Ruby | samworrall/SmartPension-ruby_app | /lib/log_orderer.rb | UTF-8 | 202 | 2.71875 | 3 | [] | no_license | # frozen_string_literal: true
# LogOrderer responsible for ordering log counts by magnitude.
class LogOrderer
def self.call(log_counts)
log_counts.sort { |a, b| a[1] <=> b[1] }.reverse
end
end
| true |
8804931bab3e351b93b25961f2b84835db5dd747 | Ruby | eprothro/cassie | /benchmarks/inclusion.rb | UTF-8 | 1,104 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'benchmark/ips'
require 'cassie'
require 'memory_profiler'
def mod
Module.new do
def foo
end
end
end
def additive_mod
Module.new do
def foo
super
end
end
end
# ~2.27 usec execution time
@klass = Class.new
@klass.include(mod)
# ~2.38 usec execution time
# + 11 nsec
@overriding_c... | true |
92398c389db81d204975417d237e7743bd2697f7 | Ruby | Skuznetz/kod | /app/duck.rb | UTF-8 | 346 | 3.578125 | 4 | [
"MIT"
] | permissive | class Duck
@@greeting = "hello"
def initialize(greeting)
@greeting = greeting
end
def quack
puts "#{@@greeting} #{@greeting}"
end
class << self
attr_accessor :greeting
def quack
puts "#{@@greeting} #{@greeting}"
end
end
end
duck1 = Duck.new("quack quack")
duck1.quack
Duck.greeting ... | true |
4c3eb6fbb13d13914d4f243013e8512ff47972e7 | Ruby | dianawhalen/archived_black_thursday | /test/merchant_test.rb | UTF-8 | 1,388 | 2.703125 | 3 | [] | no_license | require './test/test_helper'
require './lib/merchant'
require_relative '../lib/sales_engine'
require_relative '../lib/merchant_repository'
class MerchantTest < Minitest::Test
def setup
@se = SalesEngine.from_csv({
:merchants => "./data/merchants.csv",
:items => "./data/items.csv",
:custome... | true |
37860cfced26e20ae43714089278f41fae115ff3 | Ruby | kramerkeller/launch | /exercises/101_109_small_problems/5_easy/10_bannerizer.rb | UTF-8 | 804 | 4.21875 | 4 | [] | no_license | # Bannerizer
# Write a method that will take a short line of text, and print it within a box.
# Example:
# print_in_box('To boldly go where no one has gone before.')
# +--------------------------------------------+
# | |
# | To boldly go where no one has gone before. |
# | ... | true |
03e1364b638aa372cf839718ed7e71655aa927e3 | Ruby | Cryptochris/RubyLearning | /pair_programming/hello.rb | UTF-8 | 746 | 4.65625 | 5 | [] | no_license | # I want to write a program that greets the world when I wake up in the
# morning. I just want to stretch and say hello and then my computer says
# "hello world". Eventually, I am going to realize I dont want to greet the
# world everytime, but sometimes I want to greet someone personally. I may
# want to use the sa... | true |
00b6b396cf33dc7d596318faa38fb1a506f8f45d | Ruby | taniiiiim/taniiiiim | /updatememories.rb | UTF-8 | 3,626 | 2.546875 | 3 | [] | no_license | #!/usr/local/bin/ruby
print "Content-Type: text/html\n"
print "\n"
require "cgi"
require "cgi/session"
cgi = CGI.new
begin
session = CGI::Session.new(cgi, {"new_session"=>false})
rescue ArgumentError
end
if session.nil?
print "
<!Doctype=html>
<html lang=\"jp\">
<head>
<meta charset=\"utf-8\">
<meta name=\"descrip... | true |
dc0be727fad6cac245045bf95db0c2d6e8b7b6e7 | Ruby | sasadangelo/Tetris | /Block.rb | UTF-8 | 2,047 | 3.890625 | 4 | [] | no_license | require 'gosu'
# Block
#
# This class represents a simple block in Tetris game.
# All the pieces in the game (i.e. L Shape, Z Shape, Cube Shape and so on)
# are composed by blocks. For example, this is an example of L Shape where
# each X is a block:
#
# X
# X
# X
# X
# XXXXXX
#
# The World is a g... | true |
e37934bc0c1c70d43bb23a47c3a31e72380eed99 | Ruby | mdo5004/ruby-music-library-cli-v-000 | /lib/music_importer.rb | UTF-8 | 1,995 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class MusicImporter
attr_reader :path, :filenames
def initialize(path = "./db/mp3s")
@path = path
@filenames = ''
return self
end
def files
mp3s = Dir.entries(@path)
mp3s.select do |file|
file.end_with?(".mp3")
end
end
... | true |
8420c50142764f66f14889db0e53ab767052696c | Ruby | donfanning/ddnsupdate | /bin/ddnsupdate | UTF-8 | 2,544 | 2.859375 | 3 | [
"WTFPL"
] | permissive | #!/usr/bin/env ruby
$0 = 'ddnsupdate' # hide arguments from ps and top
require 'rubygems'
require 'trollop'
require 'ddnsupdate'
module DDNSUpdate
SUB_COMMANDS = %w(gen up ip)
Trollop::options do
banner <<-EOS
ddnsupdate update your dynamic dns zone with your current local or remote IP
Usage:
ddnsupdate... | true |
61b74730a39fc010dc93dbc7be4fa9002d3824d1 | Ruby | sfumyuri/yuri-study | /ruby_lessons/plain2hex.rb | UTF-8 | 275 | 3.625 | 4 | [] | no_license | #コマンド引数を取得
command = ARGV[0]
#取得した文字列を10進配列に変換
decimal_array = command.bytes.to_a
#10進配列から要素を取り出して16進文字列に変換
decimal_array.each do |decimal|
print (decimal.to_s(16)).chomp
end
print "\n"
| true |
129a2f2fca148671b7eabd034adb99790ca9682a | Ruby | polyvision/emitos | /app/models/marketing_call.rb | UTF-8 | 4,131 | 2.78125 | 3 | [] | no_license | class MarketingCall < ActiveRecord::Base
attr_accessible :sound_file_id, :name, :play_at, :use_matrix, :day_matrix, :minutes_pro_call
belongs_to :sound_file
def update_matrix(params)
if !params[:matrix]
self.day_matrix = Array.new.to_json
self.save
return
end
json_data = Array.new... | true |
3d13f3c06ed3490fe0612aebc6c5873da154d366 | Ruby | r0b0x-0/Launch-School | /RB100/intro_to_programming/8_more_stuff/exercise_5.rb | UTF-8 | 216 | 3.921875 | 4 | [] | no_license | # We need to establish that the method parameter is a block by preceding the word "block" with the ampersand symbol "&".
def execute(&block)
block.call
end
execute { puts "Hello from inside the execute method!" } | true |
6270667100e5711df0d250ae5186e0c663005f84 | Ruby | atRobert/Minesweeper | /ms.rb | UTF-8 | 7,505 | 3.75 | 4 | [] | no_license | require 'yaml'
require 'colorize'
def save_game(curr_game)
File.open('Minesweeper.yml',"w") { |file| file.write(curr_game.to_yaml)}
end
class Minesweeper
def initialize
@grid = Array.new(9) {Array.new(9,0)}
@game_over = true
@flag_pair = []
@known_empty = []
plant_bombs... | true |
b57ab2ca20c3706180ebe939005ff8c3a0b93462 | Ruby | grant-nebbs/rootins-problem | /testing/test_timeToHours.rb | UTF-8 | 376 | 2.90625 | 3 | [
"MIT"
] | permissive | # Testing for timeToHours method
require_relative "../methods.rb"
require "test/unit"
class TestTimeToHours < Test::Unit::TestCase
def test_zero_time
assert_equal(0, timeToHours("00:00"))
end
def test_empty_string
assert_raise(RuntimeError){ timeToHours("") }
end
def test_wrong_format
assert_... | true |
22784090452b351aa1d7e1e5bae53dea4a731764 | Ruby | emjo91/02-15-15-Findo | /controllers/new_dog.rb | UTF-8 | 985 | 2.71875 | 3 | [] | no_license | # The owner ID is passed along to this page from the previous page. - this is no longer the case 02/22/15
# New Dog Set Up
# goes to new_info_confirmed
get "/new_user_dog" do
@title = "Add a Pet"
@header = "FINDO"
erb :"new_dog/new_user_dog"
end
# Goes to verify_new_user_and_dog
# Need to make a form that insert... | true |
2015476dd4e269d40e5a16ba42bd2cd3909bbd27 | Ruby | petitlapin86/ttt-4-display-board-rb-ruby-intro-000 | /lib/display_board.rb | UTF-8 | 396 | 2.796875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def display_board(zeboard)
puts " #{zeboard[0]} | #{zeboard[1]} | #{zeboard[2]} "
puts "-----------"
puts " #{zeboard[3]} | #{zeboard[4]} | #{zeboard[5]} "
puts "-----------"
puts " #{zeboard[6]} | #{zeboard[7]} | #{zeboard[8]} "
end
zeboard = [" "," "," "," "," "," "," "," "]
display_board(zeboard)
puts ... | true |
2d3eda944b3fa7bf0cfa73fd38439c392de75cb2 | Ruby | adamjohnsnow/bank_tech_test | /spec/deposit_spec.rb | UTF-8 | 439 | 2.984375 | 3 | [] | no_license | require 'deposit'
describe Deposit do
let(:deposit) { Deposit.new(200, '10/01/2017', 300) }
it 'gets created with amount' do
expect(deposit.amount).to eq 200
end
it 'gets created with date' do
expect(deposit.date).to eq '10/01/2017'
end
it 'gets created with balance' do
expect(deposit.balanc... | true |
1b24d0ddfab20332c8225691d937dda6ee9a1edf | Ruby | pejuko/sudoku | /spec/sudoku_spec.rb | UTF-8 | 5,496 | 2.9375 | 3 | [] | no_license | require './sudoku'
def read_grid name
Sudoku::Grid.read_file "test/#{name}.sud"
end
def read_solver name
Sudoku::Solver.new read_grid(name)
end
def get_sud name
sud = read_solver name
sol = Sudoku::Grid.read_file "test/#{name}_result.sud"
[sud, sol]
end
describe Sudoku::Solver do
describe "#sol... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.