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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
e7e3a52d8987cd011bf9bcaba8bb7a3d5bc07d69 | Ruby | rahulpatel-tavant/hackerearth | /hackerearth-master/ruby/manan-and-toys.rb | UTF-8 | 243 | 3.15625 | 3 | [] | no_license | temp = gets.chomp.strip.split(' ').map(&:to_i)
n = temp[0]
k = temp[1]
arr = gets.chomp.strip.split(' ').map(&:to_i).sort
sum = 0
count = 0
(0...n).each do |i|
sum += arr[i]
count += 1
if sum > k
puts count - 1
break;
end
end | true |
ae192c9ddaab4f1d0ae72f217b19f0341c5aedb2 | Ruby | highwide/abc_programming | /026/b.rb | UTF-8 | 254 | 3.234375 | 3 | [] | no_license | n = gets.chomp.to_i
rs = []
n.times do
rs << gets.chomp.to_i
end
rs.sort! {|a, b| b <=> a}
answer = rs.each_with_index.inject(0) do |sum, (r, i)|
if i % 2 == 0
sum + r ** 2 * Math::PI
else
sum - r ** 2 * Math::PI
end
end
puts answer
| true |
0310655ff3986fe602af235a34bdf888a4a2a439 | Ruby | HenriqueSaKi/Curso-Automacao-Testes-Ruby | /RubyBásico/time.rb | UTF-8 | 130 | 3.046875 | 3 | [] | no_license | #Determina a quantidade de vezes que o programa irá executar a ação
5.times{puts "Henrique"} #Irá imprimir 'Henrique' 5 vezes
| true |
dce52fcaac3eaba7737353500a6f6a2f561e5570 | Ruby | escray/geektime | /algo/05_Array/lc015_3_sum_v1.rb | UTF-8 | 722 | 3.578125 | 4 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'set'
# @param {Integer[]} nums
# @return {Integer[][]}
def three_sum(nums)
return [] if nums.size < 3
nums.sort!
# puts nums
result = Set.new
i = 0
until i > nums.size - 3
lo = i + 1
puts lo
hi = nums.size - 1
puts hi
sum = 0 - nums[i]
puts ... | true |
33beb0970f75467785cc2c845a25e3b21b8c0518 | Ruby | chenyukang/rubytt | /tests/cases/index.rb | UTF-8 | 44 | 2.90625 | 3 | [
"MIT"
] | permissive | a = [1, 2, 3, "now"]
b = 1
c = a[b]
puts c
| true |
0c47ad7c0486c0f5e17395d05d8701fb0eaefec4 | Ruby | stubailo/Pantsdora | /app/lib/zappos.rb | UTF-8 | 1,069 | 2.765625 | 3 | [] | no_license | require 'open-uri'
require 'json'
class Zappos
@@api_key = "dafa6d39a387344ebf8582bb58806d535ce47dce"
def self.get_response(path = "", query = {})
query["key"] = @@api_key
query_list = []
query.each_pair{|k,v| query_list << "#{k}=#{v}"}
query_string = URI.escape(query_list.join("&"))
url ... | true |
8b062b46114df36a04bdb35fbd3a3a6e65ffa99f | Ruby | gjtorikian/commonmarker | /test/extensions_test.rb | UTF-8 | 2,262 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "test_helper"
class TestExtensions < Minitest::Test
def setup
@markdown = fixtures_file("table.md")
end
def test_uses_specified_extensions
Commonmarker.to_html(@markdown, options: { extension: {} }).tap do |out|
assert_includes(out, "| a")
assert_includ... | true |
1f2d6627d7259f0a14fc65c090db4163a1a9bd87 | Ruby | Zarecki/week5_weekend_homework | /card_test_spec.rb | UTF-8 | 641 | 2.875 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('./card.rb')
require_relative('./testing_tast_3.rb')
class TestCard < Minitest::Test
def setup
@card1 = Card.new("hearts", 1)
@card2 = Card.new("clubs", 9)
@cardgame = CardGame.new
end
def test_check_for_ace
card1 = @card1
result = @cardga... | true |
013466c853b1386e71b55632a1db89566eaa5d50 | Ruby | artistcoder/aAopen | /rspec_exercise_2/lib/part_1.rb | UTF-8 | 1,224 | 3.578125 | 4 | [] | no_license | def partition(arr, num)
less_than = []
greater_equal = []
final = []
arr.each do |n|
if n < num
less_than << n
else
greater_equal << n
end
end
final.push(less_than, greater_equal)
end
def merge(hash_1,hash_2)
final_hash = Hash.new(0)
hash... | true |
a5605cf93fbc29bec68776de19ecec12ac6ec654 | Ruby | XYUnknown/image_editor | /process.rb | UTF-8 | 2,721 | 3.375 | 3 | [] | no_license | require_relative 'image_editor'
IMG = "images/"
EXT = ".jpg"
SUCCESS_MSG = "Done!"
def run
puts("Please enter your image name (please ensure it is under path images/):")
img = IMG + gets.strip! + EXT
begin
test_open_img(img)
rescue Exception
puts("Ooops... wrong image path!")
exit(status=1)
end
... | true |
e333f1a71bfd155353e3b5b9e3f965a2ad270ab4 | Ruby | kpennachio/restaurant-tycoon | /tools/console.rb | UTF-8 | 398 | 2.96875 | 3 | [] | no_license | require_relative '../config/environment.rb'
essen = Restaurant.new("Essen")
potbelly = Restaurant.new("Potbelly")
place1 = Location.new(essen, "address", 200)
place2 = Location.new(essen, "another address", 100)
place3 = Location.new(potbelly, "here", 300)
em1 = Employee.new("Kevin", 8, place1)
em2 = Employee.new... | true |
40aa996a42cdfc0501bfb870de025efb25eeb993 | Ruby | halfalpine/learn-ruby | /03_simon_says/simon_says.rb | UTF-8 | 817 | 3.8125 | 4 | [] | no_license | def echo(echo_text)
echo_text
end
def shout(shout_text)
shout_text.upcase
end
def repeat(repeat_text, num_repeats = 2)
final_string = ""
while num_repeats > 0
final_string = final_string + " " + repeat_text
num_repeats -= 1
end
final_string.strip
end
def start_of_word(first_word, how_many)
sta... | true |
f738d8c93b4933b1abf10ba301ff42e8fe8f84ad | Ruby | lshimokawa/activegraph | /lib/active_graph/shared/declared_property/index.rb | UTF-8 | 1,273 | 2.625 | 3 | [
"MIT"
] | permissive | module ActiveGraph::Shared
class DeclaredProperty
# None of these methods interact with the database. They only keep track of property settings in models.
# It could (should?) handle the actual indexing/constraining, but that's TBD.
module Index
def index_or_constraint?
index?(:exact) || con... | true |
b57481d59b56dc34be772d5979c93e079eb0f029 | Ruby | chadjemmett/working_rogue | /bomb.rb | UTF-8 | 220 | 3.078125 | 3 | [] | no_license | #bombs
class Bomb
attr_reader :x, :y
def initialize(x, y)
@x = x
@y =y
@icon = Gosu::Font.new(15)
@color = Gosu::Color::RED
end
def draw
@icon.draw("B", @x, @y, 1, 1, 1, @color)
end
end
| true |
4c98cf787136c09d678b71541a12db16468617e3 | Ruby | jamieberrier/ruby-objects-has-many-lab-v-000 | /lib/artist.rb | UTF-8 | 789 | 3.625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # An artist should have many songs and a song should belong to an artist
require 'pry'
class Artist
attr_accessor :name
@@songs = []
def initialize(name)
@name = name
end
def songs
@@songs
end
# takes in an argument of a song and associates that song with the artist by telling the song that i... | true |
985d95215dc630392f72b5b806eaf76fb7012357 | Ruby | minixia/zhidequ2 | /models/question.rb | UTF-8 | 1,774 | 2.53125 | 3 | [] | no_license | class Question < ActiveRecord::Base
after_initialize :default_value
belongs_to :account #asker
has_and_belongs_to_many :tags
has_many :answers
validates :title, :presence => true
validates :account_id, :presence => true
self.per_page = 10
def tag(name, type = nil)
tag = Tag.find_by_name(name)
... | true |
6410fda79f352709b36246225c68bc01ff3ca6a1 | Ruby | mariesonko/my-collect-dumbo-web-042318 | /lib/my_collect.rb | UTF-8 | 175 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_collect(collection)
n=0
my_collection =[]
while n < collection.length
my_collection << (yield collection[n])
n+=1
end
my_collection
end
| true |
cc9e5a8311911e6f06d1858ffd098d03da3493a1 | Ruby | vadimvny/basketballnyc | /models/court.rb | UTF-8 | 178 | 2.625 | 3 | [] | no_license | class Court < ActiveRecord::Base
def split_address
courts = Court.all
address = courts.each {|x| x.address}
address = address[0..100].map {|x| x.split(',')}
end
end | true |
a82c03634585f2a021c2e960e1c210829dd2a3ca | Ruby | cyb-/card-app | /app/models/rules/developer_vs_dragon.rb | UTF-8 | 896 | 2.75 | 3 | [] | no_license | class Rules::DeveloperVsDragon < Rule
# Configurations =============================================================
attr_reader :developer, :dragon
# Callbacks ==================================================================
after_initialize :identify_cards!
# Class Methods ==============================... | true |
4e4f2b15d12fcb5f4128eed45660012d3ec5bf6a | Ruby | AlbayrakSanli/morpion | /app.rb | UTF-8 | 607 | 2.84375 | 3 | [] | no_license | require 'bundler'
Bundler.require
require_relative 'lib/boardcase'
require_relative 'lib/board'
require_relative 'lib/player'
require_relative 'lib/game'
require_relative 'lib/application'
require_relative 'lib/show'
my_board = Board.new
my_application = Application.new
puts "Veux-tu voir un moment fort ? [YES/no]"
... | true |
76be707ae1aefc2744de1dfd7b2da54f8537ba10 | Ruby | iastewar/chess_game | /pieces/king.rb | UTF-8 | 800 | 3.84375 | 4 | [] | no_license | require 'colorize'
require './piece.rb'
class King < Piece
def initialize(color)
super(color)
end
def to_string
if color
"K ".white
else
"K ".black
end
end
def to_sym
if color
return :kw
else
return :kb
end
end
# returns an array of possible move... | true |
3917188570fdf88a0251d39910c1d8d39f301490 | Ruby | AbhiFalcao/RailsIntro | /Lesson5/code_alongs/lib/tiger.rb | UTF-8 | 194 | 3.171875 | 3 | [] | no_license | require 'lib/animal'
class Tiger > Animal
attr_accessor = :food_type
def initialize(food_type="meat", pet_name, zoo_keeper)
@food_type = food_type
super(pet_name, zoo_keeper)
end
end | true |
0d625b17eca91ee6e567bbafa32f224ff7e5986a | Ruby | immorsh/learn_ruby_rspec | /01_temperature/temperature.rb | UTF-8 | 123 | 2.625 | 3 | [] | no_license | def ftoc(fc)
return ((fc - 32.00) * (5.00/9.00))
end
def ctof(cf)
return(cf * 9.00 / 5.00 + 32.00)
end
| true |
0ba114bbcebdfa5abab5206be3674accfde88d5d | Ruby | ppj/LearnRubyTheHardWay | /ex11.rb | UTF-8 | 346 | 3.875 | 4 | [] | no_license | # ex11.rb
print "How old are you again? "
age = gets.chomp
print "And how much did you say you weigh? "
wgt = gets.chomp
print "Whoa!!... Alright\nBut then, how tall are you? "
hgt = gets.chomp()
print "So, let me get this right\nYou are #{age}, #{hgt} tall, and weigh #{wgt}??!!"
print "No no no no... you've gotta do s... | true |
2e0a680c720a0dcb4cd35000f2be6df99605a78b | Ruby | emystein/ruby-exercises | /lib/prime_factors.rb | UTF-8 | 203 | 3.265625 | 3 | [] | no_license | require 'prime'
# https://www.codewars.com/kata/54d512e62a5e54c96200019e
def prime_factors(number)
factors = number.prime_division
factors.map { |p, e| e == 1 ? "(#{p})" : "(#{p}**#{e})" }.join
end
| true |
e66b861bfd861b5144b1797b03c4d91284e40422 | Ruby | jeremyevans/roda | /lib/roda/plugins/error_handler.rb | UTF-8 | 4,616 | 2.953125 | 3 | [
"MIT"
] | permissive | # frozen-string-literal: true
#
class Roda
module RodaPlugins
# The error_handler plugin adds an error handler to the routing,
# so that if routing the request raises an error, a nice error
# message page can be returned to the user.
#
# You can provide the error handler as a block to the plugin... | true |
053bdab90011d8380d96a0c639cbf4b8539ce247 | Ruby | abadfish/deli-counter-v-000 | /deli_counter.rb | UTF-8 | 600 | 4.09375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def line(katz_deli)
if katz_deli == []
puts "The line is currently empty."
else
new_deli = katz_deli.collect.with_index do |name,place|
"#{place+1}. #{name}"
end
puts "The line is currently: #{new_deli.join(" ")}"
end
end
def take_a_number(katz_deli, name)
katz_de... | true |
f33c26077eaf0a52d8bbc6977761721a019b1082 | Ruby | nsw125/tic_tac_toe | /tictactoe.rb | UTF-8 | 3,876 | 3.90625 | 4 | [] | no_license | class Game
def initialize
puts "Enter a name for player one."
@player1 = Player.new(gets.chomp)
puts "Enter a name for player two."
@player2 = Player.new(gets.chomp)
puts "Our players are: #{@player1.name} and #{@player2.name}! Let's see who gets to decide turn order..."
... | true |
42243009ba0ae9e5513d02677e3d9532b04ffdf2 | Ruby | ElaErl/Fundations | /lesson_3/6.rb | UTF-8 | 404 | 3.546875 | 4 | [] | no_license | produce = {'apple' => 'Fruit', 'carrot' => 'Vegetable', 'pear' => 'Fruit', 'broccoli' => 'Vegetable'}
def select_fruit(hsh)
counter = 0
pairs = []
loop do
current_item = hsh.keys[counter]
current_group = hsh[current_item]
counter += 1
if 'Fruit'.include?(current_group.to_s)
pairs << [current_item, current_grou... | true |
3466e6f94fa30a1281abd5421c922eb0d0b0619f | Ruby | ConorOwens/CLI_Town | /CLI_Town/lib/scraper.rb | UTF-8 | 684 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'open-uri'
require 'nokogiri'
class CLI_Town::Scraper
def self.scrape_monster_list(monster_list)
monsters = []
monster_list_html = Nokogiri::HTML(open(monster_list))
monster_list_html.css('ul.column li a').each do |mon|
name = mon.text
url = mon.attr('href')
... | true |
2e95ba5790cddd0d70b1413ed38e76f4d0aa5ff4 | Ruby | TribalDev/tribal_blog | /db/seeds.rb | UTF-8 | 831 | 2.5625 | 3 | [] | no_license | require 'faker'
5.times do
user = User.new(
name: Faker::Name.name,
email: Faker::Internet.email,
password: Faker::Lorem.characters(10)
)
user.skip_confirmation!
user.save!
end
users = User.all
25.times do
Post.create!(
user: users.sample,
title: Faker::Lorem.sentence,
text: F... | true |
0cd40346cac2b063ea729ca63ea03cef44506141 | Ruby | rjspotter/lumos_take_home | /spec/lumos_take_home_spec.rb | UTF-8 | 3,141 | 3.03125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "LumosTakeHome" do
let(:sample) do
[
[1, 4.00, "ham_sandwich"],
[1, 8.00, "burrito"],
[2, 5.00, "ham_sandwich"],
[2, 6.50, "burrito"]
]
end
let(:subject) {LumosTakeHome.new}
before {subject.menu = sample}
... | true |
969529641c32a102c25e1781ebc602f1cf4297d6 | Ruby | DRAKYULA/Euler_Problems | /testpalindrome.rb | UTF-8 | 100 | 2.890625 | 3 | [] | no_license | x = 92
y = 99
z = x * y
puts z
puts z.to_s.reverse
for z in test
if puts z == z.to_s.reverse
| true |
38a716e3fd1526ff0664b51a7a0c79f2b1c4d007 | Ruby | nog/atcoder | /contests/abc238/g/main.rb | UTF-8 | 959 | 2.875 | 3 | [] | no_license | N, Q = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
primes = []
require 'prime'
Prime.each(A.max ** 0.5) do |pr|
primes.push(pr)
end
llist = {}
rlist = {}
hashes = Array.new(Q){ Hash.new 0 }
results = Array.new Q
Q.times do |i|
l, r = gets.split.map(&:to_i)
l-=1
r-=1
llist[l] ||= []
llist[l].push(i)
... | true |
13fba579ea2762184955983938d1f45329c34a47 | Ruby | ksweta/Monopoly | /app/controllers/game_controller.rb | UTF-8 | 2,261 | 2.515625 | 3 | [] | no_license | class GameController < ApplicationController
before_filter :authenticate_user!
def index
@games = Game.all
@users = User.all
end
def show
@game = Game.find(params[:id])
end
def join
@game = Game.find(params[:id])
player_exists = false
if @game.players.length < 4
@game.players.ea... | true |
4892f026e2617a72bf8f39f0aa0ffaf59f9cfbd6 | Ruby | tmdgusya/RubyAlgorithm | /leetcode/add_two_number.rb | UTF-8 | 484 | 3.296875 | 3 | [] | no_license | require 'test/unit'
def add_two_numbers(l1, l2)
l1_toS = ""
l2_toS = ""
while !l1.nil?
l1_toS += l1.val.to_s
l1 = l1.next
end
while !l2.nil?
l2_toS += l2.val.to_s
l2 = l2.next
end
l1_toI = l1_toS.reverse.to_i
l2_toI = l2_toS.reverse.to_i
... | true |
bac9f4ec96c49203ef1cfcc290d21d5d49a5286c | Ruby | wallentx/slack-backup | /log_test.rb | UTF-8 | 1,613 | 2.796875 | 3 | [] | no_license | require 'minitest/autorun'
require_relative 'log'
require 'stringio'
class LogTest < Minitest::Test
def test_log
io = StringIO.new
log = Log.new io
clear = -> do
io.truncate 0
io.rewind
end
clear[]
log.debug "test"
assert_equal <<-EOS, io.string
DEBUG test
EOS
clear[]
... | true |
34a0043dc8d7877d6fbffbf54b7a292c3f96f34b | Ruby | carrierwaveuploader/carrierwave | /lib/carrierwave/processing/rmagick.rb | UTF-8 | 11,878 | 3.1875 | 3 | [
"MIT"
] | permissive | module CarrierWave
##
# This module simplifies manipulation with RMagick by providing a set
# of convenient helper methods. If you want to use them, you'll need to
# require this file:
#
# require 'carrierwave/processing/rmagick'
#
# And then include it in your uploader:
#
# class MyUploade... | true |
512d7f491b4a06bf5f02efa43788b734190d77be | Ruby | ytti/packet_via_dmem | /lib/packet_via_dmem/header/sent.rb | UTF-8 | 1,588 | 2.546875 | 3 | [] | no_license | class PacketViaDMEM
class Header
class Sent
attr_accessor :msg_type,
:statistics,
:increment_reference,
:fragment_info,
:drop_hash,
:decrement_reference,
:prequeue_priority,
:offset,
... | true |
cc5c10c0db9ad3f91d6440a1bf74c1ef7c0590c0 | Ruby | facano/effective_datatables | /app/models/effective/array_datatable_tool.rb | UTF-8 | 1,914 | 2.90625 | 3 | [
"MIT"
] | permissive | module Effective
# The collection is an Array of Arrays
class ArrayDatatableTool
attr_accessor :table_columns
delegate :order_column_index, :order_direction, :page, :per_page, :search_column, :to => :@datatable
def initialize(datatable, table_columns)
@datatable = datatable
@table_columns ... | true |
be9f20b262b6b2903b268a8527c7bb961657fabe | Ruby | slackerar/csv_parser | /app/models/analysis.rb | UTF-8 | 1,298 | 3.109375 | 3 | [] | no_license | class Analysis
MARKS = %w[ПЭТД ПЭТВ ПуГВ АПБ]
COLORS = %w[красный черный синий белый желтый голубой зеленый коричневый оранжевый фиолетовый розовый серый бордовый]
class << self
def get_type_produce(value)
result = value.match('ТУ(.[0-9\-_.]{1,20})*') unless value.match('ТУ(.[0-9\-_.]{1,20})*').nil?
... | true |
2005c8138013be978f3b526081d304d5fe4b7387 | Ruby | grzesiek/git_compound | /lib/git_compound/lock.rb | UTF-8 | 1,277 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'yaml'
module GitCompound
# Class that represents lock file
#
class Lock
FILENAME = '.gitcompound.lock'
def self.exist?
File.exist?(FILENAME)
end
def initialize(file = FILENAME)
@file = file
@locked = YAML.load(File.read(file)) if File.exist?(file)
clean unless... | true |
2b3cb5bbbbc4b0e6f9906df44a877aee3655a446 | Ruby | Will3240/programming-univbasics-3-methods-scope-lab-online-web-prework | /lib/catch_phrases.rb | UTF-8 | 253 | 2.671875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def mario
message="It's-a me, Mario!"
puts message
end
def toadstool
puts 'Thank You Mario! But Our Princess Is In Another Castle!'
end
def link
puts "It's Dangerous To Go Alone! Take This."
end
def any_phrase(phrase)
puts phrase
end | true |
dd9bcf33d6fd20cc3071a2246786c430c0ef2028 | Ruby | Deceptio-Solutions/tapir | /lib/tapir/tasks/dns_reverse_lookup.rb | UTF-8 | 997 | 2.703125 | 3 | [
"BSD-2-Clause"
] | permissive | def name
"dns_reverse_lookup"
end
def pretty_name
"DNS Reverse Lookup"
end
def authors
['jcran']
end
def description
"Look up the name of the given ip address"
end
## Returns an array of valid types for this task
def allowed_types
[Entities::Host]
end
## Returns an array of valid options and their descri... | true |
704f632797f23f3281bb4e5abe515ab39428cebf | Ruby | jnunemaker/ag | /lib/ag/object.rb | UTF-8 | 485 | 3 | 3 | [
"MIT"
] | permissive | module Ag
class Object
Separator = ";".freeze
def self.from_key(key, separator = Separator)
new(*key.split(Separator))
end
attr_reader :type
attr_reader :id
def initialize(type, id)
@type = type
@id = id
end
def key(*suffixes)
[@type, @id].concat(Array(suffi... | true |
d836faecd79c16ca70b9f44dfa65768c7c41615b | Ruby | icoluccio/criticas-app | /app/models/analyst.rb | UTF-8 | 478 | 2.53125 | 3 | [] | no_license | class Analyst < ApplicationRecord
belongs_to :newspaper, required: false
has_many :articles
has_many :favorite_countries
has_many :countries, through: :favorite_countries
def write(country)
Article.create!(title: title, figure: figure(country), analyst: self)
end
def title
raise 'Definilo, capo... | true |
731fdc719d1b588a1477700fd4848d0614eec822 | Ruby | jamie/adventofcode | /2018/01/solver.rb | UTF-8 | 264 | 3.234375 | 3 | [] | no_license | require "advent"
input = Advent.input(:to_i)
# Part 1
puts input.inject(0) { |memo, e| memo + e }
# Part 2
freqs = {}
freq = 0
freqs[freq] = true
loop do
i = input.shift
freq += i.to_i
break if freqs[freq]
freqs[freq] = true
input << i
end
puts freq
| true |
db96c90e87ecf51d6397fbe66fb42a92757d6408 | Ruby | khoinguyenkc/ruby-puppy-online-web-sp-000 | /lib/dog.rb | UTF-8 | 509 | 3.71875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Add your code here
require 'pry'
class Dog
attr_accessor :name
@@all = []
def initialize(name)
@name = name
self.save #self refers to the instance
end
def save #an INSTANCE method
@@all << self #push the object into the all array
end
def self.all
@@all
end
def self.print_all
@@a... | true |
8355eb68097bf365851452a3e7d09f9f378f93c3 | Ruby | mpermperpisang/bandung-telegram-bot | /command/add_staging.rb | UTF-8 | 2,722 | 2.625 | 3 | [] | no_license | module Bot
class Command
# untuk menambahkan staging ke daftar staging squad
class AddStaging < Command
def check_text
check_format if @txt.start_with?("/add_staging")
end
def check_format
@is_squad = Squad.new
return if @is_squad.empty?(@bot, @message.chat.id, @squa... | true |
77ff5f79711b82d3b48de3a4aec1f17e5f7e2be0 | Ruby | meldefern/OpenWeatherAPI | /spec/weather_codes_spec.rb | UTF-8 | 676 | 2.65625 | 3 | [
"MIT"
] | permissive | include WeatherConditions
describe ConditionsCode do
before(:all) do
@first_condition = WeatherConditions::ConditionsCode.new("301")
@second_condition = WeatherConditions::ConditionsCode.new("501")
end
it 'should return a string for the description associated with the id' do
expect(@first_condition.meaning)... | true |
cf6322ee62508dcb40ff3dd41049bee3e725a03c | Ruby | gongo/maizebox | /lib/maizebox/renderer.rb | UTF-8 | 3,496 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'maizebox/js_loader'
require 'maizebox/capybara'
module Maizebox
class Renderer
include Maizebox::Capybara
FRAME_PADDING = '20' # pixel
def render_here
locator = current_locator
render(locator)
end
def render_to(element)
locator = element_locator(element)
render... | true |
037eb6a9f411ea28fd743a4a9d2dfb3f3244a794 | Ruby | fooheads/cucumber_ruby-atm | /features/step_definitions/atm_steps.rb | UTF-8 | 1,307 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'atm'
Before do
@atm = ATM.new(0)
@account = Account.new(0)
@card = Card.new(@account, false)
@thrown_exception = nil
@dispensed_amount = 0
end
Given(/^the account balance is (\d+)$/) do |balance|
@account.balance = balance.to_i
end
Given(/^the card is valid$/) do
@card.valid = true
end
Given(... | true |
bfbac5ba903eb6355033050438b167cdf740f5c1 | Ruby | jeefberkey/advent-of-code-2017 | /day04/day04b.rb | UTF-8 | 502 | 3.125 | 3 | [] | no_license | require 'pry'
def validate_passphrase(phrase)
p = phrase.split(' ')
sorted = p.map do |item|
item.chars.sort.join
end
# binding.pry
sorted.uniq.length == p.length
end
puts validate_passphrase('abcde fghij')
puts validate_passphrase('abcde xyz ecdab')
puts validate_passphrase('a ab abc abd abf abj')
puts... | true |
93c1871b647043d86655ceb89efa37bcbaeaba85 | Ruby | rai-hi/pin-generator | /code/pin_generator.rb | UTF-8 | 915 | 3.265625 | 3 | [] | no_license | # frozen_string_literal: true
class PinGenerator
PIN_LENGTH = 4
def initialize(bank_account:, customer:, validator_classes: [])
@validator_classes = validator_classes
@bank_account = bank_account
@customer = customer
end
def generate
pin = random_pin
pin = random_pin until valid?(pin)
... | true |
8dea75a06c5b2e6010aa55205d4bbf263d9f3cfb | Ruby | yangchuanosaurus/RemoteDataCli | /lib/manipulate/manipulate.rb | UTF-8 | 2,519 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | require 'json'
require_relative 'field'
require_relative 'field_array'
module RemoteDataCli
module Mapping
class Manipulate
def initialize(name)
@name = upcase(name)
@class_instances = Hash.new
end
def generate(json)
data_json = JSON.parse(json)
if data_json.is_a?(Hash)
manipulate... | true |
30d75650dea5b66fe721ab72ecedd52bfad58caa | Ruby | yukaitozu/obi | /db/seeds.rb | UTF-8 | 1,882 | 2.578125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
78ef4bd62a6fe4a95dd0d56f6b8c56b625f921b8 | Ruby | anthonyb/sorts | /sort.rb | UTF-8 | 462 | 3.484375 | 3 | [] | no_license |
def sort(num)
num_array = num.to_s.split('')
done = false
len = num_array.length
while !done do
num_array.each_with_index do |n, i|
if (num_array[i+1]) and (num_array[i] > num_array[i+1])
low = num_array[i]
high = num_array[i+1]
num_array[i] = high
num_array[i+1] = low... | true |
5f7b61365f1538c75714097460f4af1fcf853775 | Ruby | dantelove/109_general_programming | /ruby_basics/10_strings/strings4.rb | UTF-8 | 56 | 2.859375 | 3 | [] | no_license | # strings4.rb
name = "Elizabeth"
puts "Hello #{name}!" | true |
6885cbf3fef407b7ea170d46f0751c43462ae94f | Ruby | clayton/ofcp_scoring | /lib/ofcp_scoring/three_of_a_kind.rb | UTF-8 | 268 | 2.65625 | 3 | [
"MIT"
] | permissive | class OfcpScoring::ThreeOfAKind < OfcpScoring::RankedHand
def <=>(other)
return super if super
highest_trip_card <=> other.highest_trip_card
end
def highest_trip_card
grouped_ranks.map{|card,matches| card if matches.size == 3}.compact.max
end
end
| true |
4f716f6be8d93791bba87a42b16cb6d788e72768 | Ruby | 2peta/rhello | /lib/rhello.rb | UTF-8 | 523 | 2.65625 | 3 | [] | no_license | require 'optparse'
require 'rhello/version'
module Rhello
class Application
OPTS = {}
def run
optparser = optparse OPTS
optparser.parse!
puts "Hello, world!"
end
def optparse opts
parser = OptionParser.new
parser.banner = "Usage: #{parser.program_name} [OPTION]..."
... | true |
ed909421cfe6c158ead5830f01f4a44f0f19c755 | Ruby | cy2003/ruby-collaborating-objects-lab-web-1116 | /lib/mp3_importer.rb | UTF-8 | 327 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class MP3Importer
attr_reader :path, :files
def initialize(path)
@path = path
end
def files
files = Dir["./spec/fixtures/mp3s/*"].collect do |file|
file.gsub("./spec/fixtures/mp3s/", "")
end
end
def import
files.each do |file_name|
Song.new_by_filename(file_name)
end
en... | true |
c74ecab60a3fa05ed4613b2bae157123e3bc4661 | Ruby | ElaineYu/shiny-octo-tyrion | /app/controller/controller.rb | UTF-8 | 1,290 | 2.9375 | 3 | [] | no_license | require 'pry'
require_relative '../../config/application'
require_relative '../models/list'
require_relative '../models/task'
# require_relative '../views/view'
class Controller
def initialize
# display = View.new
end
def add(task, list_name)
task = Task.create(description: task,
list_id... | true |
dae55fcc4738bcd9dded29c3af1f6729c0f033d5 | Ruby | Alex808r/rubyschool | /les18/task2.rb | UTF-8 | 128 | 2.6875 | 3 | [] | no_license | input = File.open 'passwords.txt', 'r'
while (line = input.gets)
line.strip!
if line.size == 6
puts line
end
end
| true |
35f82fea1d23450c9cc17bacae126c23a1b0d7ca | Ruby | OAGr/fermihub | /app/models/distribution.rb | UTF-8 | 751 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'dis'
#encoding: utf-8
#!/bin/env ruby
# encoding: utf-8
class Distribution < ActiveRecord::Base
SIGNIFICANT_DIGITS = 8
has_and_belongs_to_many :outputs, :class_name => "Operation"
has_and_belongs_to_many :models
attr_accessible :name, :mean, :spread, :wideness
before_save :default_values
after_save... | true |
e9b5bad1dfed5e41204db992a8d58ffab58295b5 | Ruby | vclee/phase-0-tracks | /ruby/shout.rb | UTF-8 | 510 | 3.8125 | 4 | [] | no_license | # module Shout
# def self.yell_angrily(words)
# words + "!!!" + " :("
# end
#
# def self.yell_happily(words)
# words + "!!!! :DDD"
# end
# end
module Shout
def yell_crazily(words)
puts words = "!blah@#blah$%^&blah*)"
end
end
class Me
include Shout
end
class You
include Shout
end
#DRIVER ... | true |
798a090e28062376b7ab95b2d6c58083fad83a84 | Ruby | pasvistelik/ruby-exercises | /20.rb | UTF-8 | 65 | 2.796875 | 3 | [] | no_license | p (1..100).reduce(:*).to_s.chars.inject(0){|sum,i| sum + i.to_i}
| true |
073cf00ab0cf4e202fdb115a52702f63cdcd5609 | Ruby | thms/tic-tac-toe | /lib/game.rb | UTF-8 | 1,928 | 4 | 4 | [] | no_license | require_relative './board'
class Game
attr_accessor :board
attr_accessor :player_one
attr_accessor :player_two
attr_accessor :winner
STONES = {1.0 => 'x', -1.0 => 'o', 0 => ' '}
def initialize(player_one, player_two, params = {display_output: false})
@board = Board.new
@player_one = player_one
... | true |
53121266c8b3b25751c98327b8c6ffab84374510 | Ruby | MAPC/metrofuture-api | /app/models/project_manager.rb | UTF-8 | 803 | 2.609375 | 3 | [] | no_license | class ProjectManager < ActiveRecord::Base
self.table_name = 'OwnerBase'
self.primary_key = 'OwnerId'
default_scope { where("OwnerIdType" => 8) }
has_many :projects, class_name: 'Base::Project', foreign_key: 'OwnerId'
alias_attribute :base_name, :Name
def name(options={})
order = options.fetch(:forma... | true |
d1613b442009b4c035fce6fdb4125c1d0f402419 | Ruby | zachholcomb/brownfield-of-dreams | /app/models/following.rb | UTF-8 | 173 | 2.625 | 3 | [] | no_license | class Following
attr_reader :name, :link
def initialize(name, link)
@name = name
@link = link
end
def user?
User.find_by(github_user: @name)
end
end
| true |
6648aea3c8ccc5cc7fe22e25e632eb5a84b50f36 | Ruby | AlexStoll/RB101 | /SmallProblems/Easy_6/4.rb | UTF-8 | 519 | 4.625 | 5 | [] | no_license | # Swap Case
# Problem
# Swap the case of each letter in a string
# Example
# swapcase('CamelCase') == 'cAMELcASE'
# Data
# String split to a chars array, joined back to a string
# Algorithm
# Split into chars
# Map through chars, if upcase => downcase, if downcase => upcase
# join chars back to a string
# Code
de... | true |
6cde5d6544cbc0402b2a0ac9d6342cc258d17882 | Ruby | ruan20a/ga_change_machine | /machine.rb | UTF-8 | 1,770 | 3.59375 | 4 | [] | no_license | require 'pry'
require 'debugger'
require 'active_record'
require 'active_support/inflector'
class Machine
attr_accessor :currency_set
CURRENCY = {"penny" => 1, "nickel" => 5, "dime" => 10, "quarter" => 25}
def initialize
@currency_set = Machine::CURRENCY
end
#standardize methods are used to clean up i... | true |
6a47102fe7ab0ef155722db4ed5ffd95191d118e | Ruby | sdbeng/ryby_stand_class | /hello_ruby.rb | UTF-8 | 223 | 2.765625 | 3 | [] | no_license | puts "Hello guys, welcome to my Lemonade Stand!"
puts spacing = "************ ***********"
hello = "This is Alan your friendly neighbor.I'm happy to see you."
puts time = Time.new
3.times do
puts hello
end
puts spacing
| true |
80b51b36e3fe39b1015d92caaed33566bd04d08a | Ruby | kirbynator/Brain-Teasers | /EvenOrOdd.rb | UTF-8 | 665 | 3.84375 | 4 | [] | no_license | require "pry"
def initialize(go)
prng = Random.new
responce = prng.rand(10)
prng = Random.new
responce1 = prng.rand(10)
prng = Random.new
responce2 = prng.rand(10)
@numbers = [responce1,responce2,responce, 11, 4]
@prejuice = []
go == ("even") ? (seger("even")) : (seger("odd"))
end
def seger(input)
@inp... | true |
b4c49062242ec93e7639ae2de19456a829d8eaa9 | Ruby | onofricamila/TTPS-Ruby | /p1/p1e17.rb | UTF-8 | 1,022 | 3.890625 | 4 | [] | no_license | # Ejercicio hecho por Seba-
# Original --> https://github.com/SebaRaimondi/TTPS-Ruby-Practicas/tree/master/Practica-01
# 17. Cada nuevo término en la secuencia de Fibonacci es generado sumando los 2 términos
# anteriores. Los primeros 10 términos son: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55. Considerando los
# términos en ... | true |
a8787c672f2af5a3cb7a387e632814779b7041db | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz101_sols/solutions/Peter Severin/program_manager.rb | UTF-8 | 1,080 | 3.296875 | 3 | [
"MIT"
] | permissive | class Time
def seconds
(hour * 60 + min) * 60 + sec
end
end
class Program
attr_reader :channel
def initialize(program_details)
@program_start = program_details[:start]
@program_end = program_details[:end]
@channel = program_details[:channel]
end
end
class SpecificProgram < Program
def record?(time)
t... | true |
ef46b3e91372d6ca346f208f70746d56defab66f | Ruby | lisunshiny/oo-chess | /lib/pieces/stepping_pieces/king.rb | UTF-8 | 188 | 2.578125 | 3 | [] | no_license | class King < SteppingPiece
def move_deltas
[ [1, 1], [0, 1], [1, 0], [-1, 0], [0, -1], [-1, -1], [1, -1], [-1, 1] ]
end
def render
color == :black ? "♚" : "♔"
end
end
| true |
4526f6627f62deec22af846b14cedbd99bdd7a9e | Ruby | tubbo/nitro | /app/services/github/user.rb | UTF-8 | 241 | 2.890625 | 3 | [] | no_license | module Github
# Basic wrapper for a user on the GitHub API
class User
attr_reader :name
def initialize(name: '')
@name = name
@user = Octokit.user(name)
end
def valid?
@user.present?
end
end
end
| true |
a3f4021452ecc29c3b57319fcc342928e489252b | Ruby | c7/scoped_search | /test/query_language_test.rb | UTF-8 | 5,454 | 2.8125 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/test_helper'
class QueryLanguageTest < Test::Unit::TestCase
# change this function if you switch to another query language parser
def parse_query(query)
ScopedSearch::QueryLanguageParser.parse(query)
end
def test_empty_search_query
parsed = parse_query('')
ass... | true |
90da036d3a896c63624bea197657e2581c20136c | Ruby | Nossborn/learn_ruby | /02_calculator/calculator.rb | UTF-8 | 364 | 3.921875 | 4 | [] | no_license | #write your code here
def add(x, y)
return x + y
end
def subtract(x, y)
return x - y
end
def sum(array)
res = 0
array.each do |n|
res += n
end
return res
end
def multiply(array)
res = 1
array.each do |n|
res *= n
end
return res
end
def power(x, y)
return x ** y
end
def factorial(n)
res = 1
while n... | true |
52acd120ae1794fa6e5353e40ce014d523eacaa3 | Ruby | thanhnguyen9/portfolio | /Week-1/day1/homework.rb | UTF-8 | 1,110 | 4.03125 | 4 | [] | no_license | # Assign "Hello World" to a variable message
message = "Hello World"
# Assign a different string to a different variable
any = "First app"
# Assign a number to a variable
number = 9
# Use string interpolation to display the number in a string
# string interpolation = #{}
puts "#{number}"
# Make an array of your fa... | true |
24edf4e49500531f934648f0a7e31a6a8b78c00d | Ruby | CedricLor/art_des_nations | /lib/my_modules/aktion_article_pictures.rb | UTF-8 | 2,292 | 2.515625 | 3 | [] | no_license | # lib/my_modules/aktion_article.rb
module AktionArticlePictures
def persist_picture_changes
if md_to_update
update_pictures(@main_model, md_to_update, md_for_carousel)
end
if new_md
create_pictures
end
if for_card && for_card.match(/existing_md_/)
pict_id = for_card.sub(/exist... | true |
a23ceb25b6c476221a2b5b4d2100ab0b9c748d6d | Ruby | SazPavel/Ruby_on_Rails_Valera_SIBSUTIS | /spec/lib/valera_spec.rb | UTF-8 | 2,416 | 2.703125 | 3 | [] | no_license | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Valera do
let(:valera) { Valera.new(100, 100, 10, 10, 100) }
let(:dead_valera) { Valera.new(0, 0, 0, 0, 0) }
let(:invalid_valera) { Valera.new(10_000, -100, 1000, -1000, -1000) }
describe '#initializer' do
context 'when health > 100' do
... | true |
f5426769792a6e2413408b203d33317360eae92d | Ruby | timdisab/ruby_tut | /methods/greeting.rb | UTF-8 | 83 | 3.375 | 3 | [] | no_license | def greeting(name)
"Hi, " + name + ". How's it going?"
end
puts greeting("Tim")
| true |
c596775d261991e450bdf00fd77b38ed83fed2f6 | Ruby | Yorkshireman/string_keys_to_syms | /lib/convert.rb | UTF-8 | 134 | 3.296875 | 3 | [] | no_license | def convert(hash)
new_hash = {}
hash.each_pair do |key, value|
new_hash.store(key.downcase.to_sym, value)
end
new_hash
end | true |
61eb52af25463cc35301160871fb8dd35c1adde5 | Ruby | Icicleta/practical_object_oriented_design_in_ruby | /06_Inheritance/06.rb | UTF-8 | 2,280 | 3.953125 | 4 | [] | no_license | # The very calling of super itself below means that Roadbike expects, nay requires, that one of its superclasses has a spares method, and that it returns a hash.
# Both send super in their initialize and spares methods, which creates a strong dependency.
class Bike
attr_reader :size, :chain, :tire_size
def initia... | true |
24aa29d066741e94f39dbe418c9aa16e83f28b10 | Ruby | joshuaylee/advent-of-code | /2018/16/opcodes.rb | UTF-8 | 2,847 | 3.03125 | 3 | [] | no_license | require 'set'
def each_sample(file)
e = File.open(file).each_line
loop do
reg_pre, instr, reg_post, _blank = e.next, e.next, e.next, e.next
break unless reg_pre.match(/^Before:/)
yield(parse_regs(reg_pre), parse_instr(instr), parse_regs(reg_post))
end
end
def parse_regs(str)
str.match(/\[(.*)\]/... | true |
93d6015ba35b6e9ad62684a8e4e13d42707bc2fc | Ruby | yeatsphillis87/rotuka-rails-extender | /lib/rotuka/core_ext/hash.rb | UTF-8 | 865 | 3.1875 | 3 | [
"MIT"
] | permissive | # Imported from http://source.collectiveidea.com/public/rails/plugins/awesomeness/lib/awesomeness/core_ext/hash.rb
class Hash
# Usage { :a => 1, :b => 2, :c => 3}.only(:a) -> {:a => 1}
def only(*keys)
self.reject { |k,v| !keys.include? k.to_sym }
end
# Usage {:a => [1, 3, 4], :b => [2, 5]}.witho... | true |
244b0510a3bdef65ce8a8d5a40fe2b35d124f2e6 | Ruby | oldGCdM/ruby-collaborating-objects-lab-london-web-060418 | /lib/mp3_importer.rb | UTF-8 | 384 | 3.171875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class MP3Importer
attr_accessor :path, :files
def initialize(file_path)
@path = file_path
@files = self.files
end
def files
files_list = Dir[@path + '/*']
files_list.map do |song_path|
song_ary = song_path.split('/')
song_ary.last
end
end
def import
@files.each do |fil... | true |
e621cb7c39d137a59eeb94c56fba83bb8f3d4fc1 | Ruby | jayshenk/algorithms | /binary_search.rb | UTF-8 | 351 | 3.890625 | 4 | [] | no_license | def binary_search(array, target)
left = 0
right = array.size - 1
while left + 1 < right
mid = left + (right - left) / 2
if array[mid] == target
return mid
elsif array[mid] > target
right = mid
else
left = mid
end
end
return left if array[left] == target
return right ... | true |
18157d610338debef6aa667dea9cb81359b4f8b9 | Ruby | lennhy/ruby-collaborating-objects-lab-v-000 | /lib/artist.rb | UTF-8 | 1,236 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # require "pry"
class Artist
attr_accessor :name, :songs
@@all =[]
def initialize(name)
@name= name
@songs = []
@@all << self
end
def self.all
@@all # to be able to use logic with @@all variable first define / expose the all class variable
end
def add_song(song)
@songs << song
... | true |
c877539297a3f028f1657974389075652643dbd9 | Ruby | flores34000/exo_ruby | /exo5.rb | UTF-8 | 237 | 3.25 | 3 | [] | no_license | puts "on vas compter le nombre d'heures de travail à THP"
puts "travail : #{10*5*11} heure"
puts "en minutes ça fait : #{10*5*11*60} s"
puts "et en secondes:"
puts 10*5*11*60*60
puts 3 + 2 < 5 - 7
puts "ca fait combien 3 + 2 ? #{3+2}" | true |
3a736b9c6d54b64adad69f8b17d1b79f11974f02 | Ruby | balanalina/Assignment2_CarService | /spec/test_spec.rb | UTF-8 | 3,943 | 2.765625 | 3 | [] | no_license | require_relative "../car_service/request_service"
describe 'test for one car, no waiting/scheduling' do
context 'leave it today, take it today' do
it 'should print Thursday 23-07-2020 17:30' do
service = RequestService.new
allow(Time).to receive(:now).and_return(Time.new(2020,07,23,15,30))
expe... | true |
25715a1cbedf7918784ed4db8b1d92c3cebbff77 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/combine_anagrams_latest/2514.rb | UTF-8 | 498 | 3.4375 | 3 | [] | no_license | def combine_anagrams(words)
anagramForms = Hash.new
words.each do |word|
anagramForms[word] = word.downcase.split(//).sort
end
groups=[]
anagramForms.hash_revert.each_value do |value|
groups.push(value)
end
groups
end
def anagram?(word1,word2)
word1.downcase.split(//).sort == w... | true |
c1316f63cf88bd0b35595021ab22f09c10a3a447 | Ruby | coding-git/ruby-basics | /loops/count_down.rb | UTF-8 | 114 | 3.484375 | 3 | [] | no_license | # Loops - exercise 4
def count_down(num)
puts num
if num > 0
count_down(num-1)
end
end
count_down(10)
| true |
95425ffe56a791e6b82b3d20ea6f9ab7d1edc17c | Ruby | dwoznicki/spoonacular | /lib/spoonacular/querify.rb | UTF-8 | 493 | 3.359375 | 3 | [
"MIT"
] | permissive | class Object
def querify
if self.is_a? String
return self.gsub(/,\s?/, "%2C").gsub(" ", "+")
elsif self.is_a? Array
return self.join("%2C").gsub(" ", "+")
elsif self.is_a? Hash
result = []
self.each do |key, value|
result << "#{key.to_s.to_camel_case}=#{value.querify}"
end
return result.jo... | true |
398db8bf9479f4aedfda1f5b02ecec63e87fbf89 | Ruby | ianagbip1oti/advent-of-code-2020 | /ruby/day08.rb | UTF-8 | 6,099 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'set'
INSTRUCTIONS = DATA.map(&:split).map { |op, arg| [op.to_sym, arg.to_i] }.freeze
def execute(instructions = INSTRUCTIONS)
executed = Set.new
ip = 0
acc = 0
while not executed.include? ip and ip < instructions.size
ins = instructions[ip]
executed << ip
case ins
in [:acc, arg]
... | true |
30255dd0ddd531d9b377185e508ccdaa30861b9d | Ruby | mateuszkosc/udemy | /podstawy/wyrazenia.rb | UTF-8 | 344 | 3.125 | 3 | [] | no_license | a = b = 2
p a
p b
a, b = 1, 2
p a
p b
a, b, *c = [1, 2, 3, 4, 5]
p a
p b
p c
x = 1..10
p x.to_a
p [*x]
# Łańcuchowe wywoływanie wyrażeń
y = [1, 3, 2, 4, 5, 1, 3, 4, 5, 6]
# wypisanie wartości unikalnych
p y.uniq
# posotrowanie wartosci unikalnych
p y.uniq.sort
# odwrócenie posortowanych wartości unikalnych
p y.un... | true |
0637ea2a690d8231e6040f8b1a513704c4a4c143 | Ruby | IanLawson8913/lesson_6 | /testing/assertions.rb | UTF-8 | 1,221 | 3.921875 | 4 | [] | no_license | # assert(test) # Fails unless test is truthy.
# assert_equal(exp, act) # Fails unless exp == act.
# assert_nil(obj) # Fails unless obj is nil.
# assert_raises(*exp) { ... } # Fails unless block raises one of *exp.
# assert_instance_of(cls, obj) # Fails unless obj ... | true |
febf48b6460447dd6776f85bb2fb3a5ac03f7e58 | Ruby | vagf0t/recursive | /spec/models/missing_integer_recursive_spec.rb | UTF-8 | 1,076 | 3.015625 | 3 | [] | no_license | require 'spec_helper'
describe Recursive::MissingIntegerRecursive do
context 'given an array with a gap' do
it 'should find the missing one' do
expect(subject.solution([1, 2, 5])).to eq 3
end
end
context 'given an array with no gap' do
it 'should find the next one' do
expect(subject.solu... | true |
074b0091b018885a886807de843d9f1643c89251 | Ruby | hari31582/jv | /spec/town_spec.rb | UTF-8 | 2,552 | 3.046875 | 3 | [] | no_license | # Test Town class
# Author: Haribhau Ingale
# Date: 30 April 2012
require 'csv'
require File.dirname(__FILE__)+'/../lib/town'
require File.dirname(__FILE__)+'/../lib/restaurant'
require File.dirname(__FILE__)+'/../lib/value_meal'
class FileReaderMoc
def read
<<-EOF
1, 1, i1
1, 2, i2
1, 3, i3
1, 4, i4
1, 4, i2... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.