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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
4ca4b04b38f8f8386e5e9bf835215e3c739614ac | Ruby | ruby-stars/beginners-lessons | /lesson3/functional.rb | UTF-8 | 77 | 3.265625 | 3 | [] | no_license | # Example of functional programming
def add(a,b)
a + b
end
puts add(1,2)
| true |
0b13feb445e141834c9081d2788679e2df2aa010 | Ruby | PayLeap/Ruby-SDK | /lib/MerchantManageCustomer.rb | MacCentralEurope | 2,934 | 2.625 | 3 | [] | no_license | require 'rubygems'
require 'httparty'
#This service operation allows you to add, update, and delete customer information.
class MerchantManageCustomer
#This method returns string response
#url - Base url of service
#Username - Your PayLeap API login ID.
#Password - Your PayLeap API transaction key.
#TransType ... | true |
361967f2eefce60bf7bc4b615e5ad67d96711d09 | Ruby | deckboy/hw-acceptance-unit-test-cycle | /rottenpotatoes/spec/movie_spec.rb | UTF-8 | 544 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
describe Movie do
it 'should find movies with the same director' do
movie1 = Movie.create(title: 'Test1', director: 'Director 1')
movie2 = Movie.create(title: 'Test2', director: 'Director 1')
results = Movie.similar_movies(movie1.id)
expect(results).to eq([mov... | true |
426c0018143eded64ffd63597c75cb09ec15ed2c | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/df8a7c3bade94c79af9989d6204c6538.rb | UTF-8 | 586 | 3.671875 | 4 | [] | no_license | class Bob
def hey(msg)
msg.delete!("\n")
response_to_message(msg)
end
def response_to_message(msg)
if is_yelling?(msg) && has_letters?(msg)
'Woah, chill out!'
elsif is_a_question?(msg)
'Sure.'
elsif is_nothing?(msg)
'Fine. Be that way!'
else
'Whatever.'
end
e... | true |
8404e1e1ecf304181a9b0cd4da29f87d6a7b141d | Ruby | kruegsw/LaunchSchool_RB109 | /small_problems/mult_of_3_and_5.rb | UTF-8 | 177 | 3.59375 | 4 | [] | no_license | def multisum(num)
sum = 0
(1..num).each { |num| sum += num if num % 3 == 0 || num % 5 == 0 }
sum
end
puts multisum(3)
puts multisum(5)
puts multisum(10)
puts multisum(1000)
| true |
82a00fe889b099f7fc6f9a800815d72092c8c199 | Ruby | StephanieCunnane/Launch_School_Challenges | /simple_linked_list/simple_linked_list.rb | UTF-8 | 2,855 | 4 | 4 | [] | no_license | # Let's create a singly linked list to contain the range 1..10 and provide
# methods to reverse a linked list and convert to and from arrays
#
# So each Element object will have 2 instance variables:
# @value
# @next_node
#class Element
# attr_reader :datum, :next
#
# def initialize(datum, next_node=nil)
# @d... | true |
4b453e38b932f92207c20867b473bcbb251c4987 | Ruby | tmock12/plan_your_ce | /spec/decorators/course_decorator_spec.rb | UTF-8 | 927 | 2.515625 | 3 | [] | no_license | require 'spec_helper'
describe CourseDecorator do
let(:address) { Fabricate(:course_address) }
let(:course) { Fabricate(:course, course_address: address) }
subject{ CourseDecorator.new(course) }
its(:audience) { should == "stranded islanders, shipwrecked persons" }
its(:phone) { should == '678-867-5309' }
... | true |
6fd09907c6c155dc4a0115d465156ae92439ba51 | Ruby | sandiks/ruby_code | /0metaprogramming/instance_eval.rb | UTF-8 | 253 | 3.3125 | 3 | [] | no_license | string = "String"
string2 = "String"
string2.instance_eval do
def new_method
self.reverse
end
end
p string2.new_method
obj = "11111112222"
other = obj.dup
p obj == other #=> true
p obj.equal? other #=> false
obj.equal? obj #=> true | true |
e9fe06ebd26f07ea13e0b91160f7d16b1228f539 | Ruby | tomcha/sinatras | /lib/sinatras/command.rb | UTF-8 | 4,120 | 2.6875 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
module Sinatras
#コマンドライン処理を行うクラス
# @auther tomcha_
class Command
def execute
options = Options.parse!(@argv)
sub_command = options.delete(:command)
tasks = case sub_command
when 'new'
new(options)
end
end
def self.run(... | true |
4066c40f7356c78448e3e484da4dce1cbcb06ac8 | Ruby | D4L/projectEuler | /src/problem-46/ylov.rb | UTF-8 | 529 | 3.234375 | 3 | [] | no_license | public
def ylov
i = 3
primes = Array.new([3])
exists = 1
while exists == 1
exists = 0
i += 2
(3..Math.sqrt(i).ceil).each do |k|
break if i % k == 0
if k == Math.sqrt(i).ceil
primes.push i
exists = 1
end
end
if exists == 1
next
end
# at this po... | true |
1d95660b78fecaa27ff0a344ef434ec1929d0d0c | Ruby | tamaxyo/bonus-drink | /bonus_drink.rb | UTF-8 | 394 | 3.546875 | 4 | [] | no_license | class BonusDrink
def self.total_count_for(amount)
return 0 if amount < 0
total_count = amount
empty_bottles = amount
while empty_bottles > 2
bonus_drink = empty_bottles / 3
total_count += bonus_drink
empty_bottles = bonus_drink + empty_bottles % 3
end
return total_cou... | true |
5005caa3cfcfa25c05bbbdcea37e8ca3b4b7588f | Ruby | BrianHGrant/shoe-distribution-tracker | /spec/store_spec.rb | UTF-8 | 1,022 | 2.765625 | 3 | [
"MIT"
] | permissive | require ('spec_helper')
describe(Store) do
describe('#brands') do
it('will return the brands sold by a specific store') do
test_store = Store.create({:name => 'Good for your sole Shoes'})
test_brand = Brand.create({:name => 'Kennebunkport Kicks'})
test_brand2 = Brand.create({:name => 'Siddartha... | true |
d313072a62c7bac2074fd6ef56c2216fc845eea9 | Ruby | tono77/presencial18 | /ruleta.rb | UTF-8 | 829 | 3.6875 | 4 | [] | no_license | class Roullette
attr_accessor :apuesta, :azar
def initialize(apuesta)
@r = (1..10).to_a
@azar = @r[rand(@r.length)]
@apuesta = apuesta
end
def play()
@azar == @apuesta ? true : false
end
def apuesta
file = File.open('roulette_history.txt','a')
file.puts(@azar)
file.close
F... | true |
5ff981aef5102d57000daff5fce5af7e92d5999e | Ruby | travisariggs/IntroToRuby | /Chapter12/roman_to_int.rb | UTF-8 | 598 | 3.984375 | 4 | [] | no_license | def roman_to_int(roman)
digit_hash = { 'i' => 1,
'v' => 5,
'x' => 10,
'l' => 50,
'c' => 100,
'd' => 500,
'm' => 1000
}
total = 0
prev = 0
roman.reverse.each_char do |c|
val = digit_hash[c.downcase]
... | true |
3ee67d1cc6a95a5f3c664c1639ab91294bf704a4 | Ruby | reqshark/commandlinetools | /sysadmin/backup/rubycookbook/10-Metaprogramming/10 - Avoiding Boilerplate Code with Metaprogramming.rb | UTF-8 | 1,218 | 3.90625 | 4 | [] | no_license | class Fetcher
def fetch(how_many)
puts "Fetching #{how_many ? how_many : "all"}."
end
def fetch_one
fetch(1)
end
def fetch_ten
fetch(10)
end
def fetch_all
fetch(nil)
end
end
#---
class GeneratedFetcher
def fetch(how_many)
puts "Fetching #{how_many ? how_many : "all"}."
end
[... | true |
ce7fed6550d27d435cc8b750e26cf02889ec33e7 | Ruby | Elucidation/Project-Euler-As-one | /ProjectEuler_156.rb | UTF-8 | 652 | 3.140625 | 3 | [] | no_license | #a = 5
#puts /#{a}/ =~ '25910'
fn = 0;
d = 1;
@maxN = 100
#maxN = ARGV[0].to_i + 1 unless ARGV[0].nil?
def f(n,d) # returns total number of times d shows up in range 0..n including n
total = 0
(n+1).times do |k|
total += k.to_s.count(d.to_s)
end
return total
end
def s(d) # sum of all the solutions for w... | true |
20a3b91f977ed927e9a862fac7ada5f4a04a3209 | Ruby | DarkLaughter/ttt-4-display-board-rb-nyc-fasttrack-020120 | /lib/display_board.rb | UTF-8 | 502 | 3.953125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Define display_board that accepts a board and prints
# out the current state.
def display_board(display_board = [" "," "," "," "," "," "," "," "," "])
puts " #{display_board[0]} | #{display_board[1]} | #{display_board[2]} "
puts "-----------"
puts " #{display_board[3]} | #{display_board[4]} | #{display_board[5]... | true |
465562ebd021f64ac945f8335697c0bcb10abf0e | Ruby | bosmanpa/sql-library-lab-chicago-web-100719 | /lib/querying.rb | UTF-8 | 1,314 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def select_books_titles_and_years_in_first_series_order_by_year
"SELECT books.title, books.year
FROM books
WHERE books.series_id = 1
ORDER BY books.year;"
end
def select_name_and_motto_of_char_with_longest_motto
"SELECT characters.name, characters.motto
FROM characters
ORDER BY length(characters.motto) DESC
limit 1;"... | true |
54f14217a3541c1105112a2eda305da4c83f3755 | Ruby | minhnghivn/idata | /lib/idata/detector.rb | UTF-8 | 2,007 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'csv'
# Set UTF-8
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
class Array
def to_h
h = {}
self.each do |e|
h[e.first] = e.last
end
return h
end
end
module Idata
class Detector
DEFAULT_DELIMITER = ","
COMMON_DELIMITERS = [DEFAULT_... | true |
df91ff0568bc7d05ed17e88cfb35d612f0a0ad24 | Ruby | kelseyde/ruby_karaoke_bar | /karaoke_bar.rb | UTF-8 | 1,659 | 3.546875 | 4 | [] | no_license | require_relative("room")
require_relative("guest")
require("pry")
class KaraokeBar
attr_accessor(:name, :rooms, :total_guests, :total_capacity, :cash)
def initialize(name, rooms, total_guests, total_capacity, cash)
@name = name
@rooms = rooms
@total_guests = total_guests
@total_capacity = total_c... | true |
69a3ab28b71179d4eb064e6693a42dd04cfc6f75 | Ruby | carolinaevevarela/D_Ciclos | /solo_pares.rb | UTF-8 | 66 | 2.984375 | 3 | [] | no_license | n = ARGV[0].to_i
n.times do |i|
if i.even?
puts i
end
end
| true |
ef8f68ac853322e12cbd68de0084ddd274234a64 | Ruby | fatoumatadiaby/looping-while-until-onl01-seng-ft-052620 | /lib/until.rb | UTF-8 | 523 | 3.921875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_until
levitation_force = 6
until levitation_force == 10
puts "Wingardium Leviosa"
levitation_force += 1
end
end
# Let's get the second test passing by coding our solution in `until.rb`:
# Fill out the content of the `using_until` method to `puts` the desired phrase, "Wingardium Leviosa", until our le... | true |
24ccdd82491a14ce50e893ca5bf796fc96feda9a | Ruby | cuongnc-dev/jobready_test_ruby | /spec/main_spec.rb | UTF-8 | 2,441 | 2.84375 | 3 | [] | no_license | require_relative "../main"
describe Main do
subject(:main) {Main.new}
context "Correct output 1" do
it "Calculate total price output 1 product 1" do
expect(main.send :calculate_total_price_one_product, 0).to eq 12.49
end
it "Calculate total price output 1 product 2" do
expect(main.send :c... | true |
dbe9967a0a68644f85a4c4ecf0ca075a5583f082 | Ruby | BkBky/clon_quora | /app/controllers/questions.rb | UTF-8 | 1,226 | 2.578125 | 3 | [] | no_license |
get '/show_question/:question_id' do
question_id2 = params[:question_id]
@quest_id = Question.where(id: question_id2)
@user_login = current_user.name
erb :show_question
end
#Create a question on database
post '/create_question' do
question= params[:question]
p quest = Question.new(question: questi... | true |
bc14ebcdbf6a4afc6578821d2b46bfab510ae553 | Ruby | keitaroemotion/benri | /lib/clean.rb | UTF-8 | 736 | 3.21875 | 3 | [] | no_license | def executeClean(config)
list = getlist config
list.keys.each do |key|
print "key: "
print "#{key} ".green
print "to: #{list[key][1]} "
puts
end
print "which key?: "
key = $stdin.gets.chomp
to = list[key][1]
def cleanDir(dir)
Dir["#{dir}/*".gsub("//... | true |
876ceee9f4b3827b415718fd6eee487aa30f87eb | Ruby | DougEverly/jruby-jms | /lib/jms/map_message.rb | UTF-8 | 2,655 | 2.921875 | 3 | [
"Apache-2.0"
] | permissive | ################################################################################
# Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# ... | true |
0b6cab7274237103b58c73bb6b6db6a699f8dcb9 | Ruby | theCuriousJi/CityFinder | /db/seeds.rb | UTF-8 | 760 | 2.640625 | 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 rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
68f90bc637b0580240fb1b9dea9ed3b995b441d8 | Ruby | ypoons02/WDI_13_HOMEWORK | /Wendy Chen/wk04/1-mon/loops.rb | UTF-8 | 1,115 | 4.53125 | 5 | [] | no_license | #Title: Guess The Number
#Activity:
#You are to generate a basic "guess my number" game.
#The computer will pick a random number between 0 and 10.
#The user will guess the number until they guess correctly.
#puts "Enter a number";
#a = gets.chomp
#b = Random.new.rand(0..10)
#while a.to_i != b do
# puts "Keep gues... | true |
353e57c9fa6ead561e16538d1c7d6502ba2960d7 | Ruby | tblanchard01/bank_tech_test | /lib/Account.rb | UTF-8 | 1,118 | 3.890625 | 4 | [] | no_license | require 'date'
require_relative 'Transaction'
require_relative 'Display'
class Account
attr_reader :balance
def initialize(balance = 0.00, display = Display.new)
@balance = balance
@statement = []
@display = display
end
def show_balance
@display.show_balance(@balance)
end
def deposit(v... | true |
54eef115f994ea9c040e35b5165c7d73f0a5dcc5 | Ruby | spasham/Ruby | /ex11.rb | UTF-8 | 198 | 3.625 | 4 | [] | no_license | print "How old are you..?"
age = gets
puts "How tall are you..?"
height = gets
print "How much do you weight..?"
weight = gets
puts "So, yor are #{age} old, #{height} tall and #{weight} heavy."
| true |
2064bc0a783f14e84b092d96e65a0c1df519e8ac | Ruby | hazthompson/ar-exercises | /exercises/exercise_4.rb | UTF-8 | 815 | 3.078125 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
puts "Exercise 4"
puts "----------"
# Your code goes here ...
Surrey = Store.create(name: 'Surrey', annual_revenue: 224000, mens_apparel: 0, womens_apparel: 1)
Whistler = Store.create(name: 'Wh... | true |
fefa5a35df805fdfad75891880954005b8d52841 | Ruby | gearjosh/number_longifier | /lib/longifier.rb | UTF-8 | 2,787 | 4.28125 | 4 | [] | no_license | class Numeral
def initialize(num)
@number = num
end
def number
@number
end
def to_words
tweens_and_teens = {
'10' => 'ten',
'11' => 'eleven',
'12' => 'twelve',
'13' => 'thirteen',
'14' => 'fourteen',
'15' => 'fifteen',
'16' => 'sixteen',
'17' => '... | true |
34b9e93e7a7248388c415a0e36a527ad1df44267 | Ruby | k28/ruby_math_puzzle | /first_time/q38_01.rb | UTF-8 | 436 | 2.96875 | 3 | [] | no_license | #! ruby -Ku
D0 = 0b1111110
D1 = 0b0110000
D2 = 0b1101101
D3 = 0b1111001
D4 = 0b0110011
D5 = 0b1011011
D6 = 0b1011111
D7 = 0b1110000
D8 = 0b1111111
D9 = 0b1111011
patterns = [D0, D1, D2, D3, D4, D5, D6, D7, D8, D9]
min = 63 # 毎回ビットを判定させた時の値
patterns.permutation(patterns.size){|p|
sum = 0
(p.size - 1).times{|j|
... | true |
772fb95e2252ded0b1fe99650a76f4e8e3db28bd | Ruby | pablovilas/asp-course-examples | /2019/s1/s1c2/ruby/4-inheritance.rb | UTF-8 | 1,383 | 4.375 | 4 | [] | no_license | # ================================
# inheritance
#
# classes can inherit values and
# behavior from another class. this
# is one of the primary strengths
# of object oriented programming.
# ================================
# ================================
# simple inheritance
# ================================
cla... | true |
64b8927c1deb2d1a967a1dd5fe93e429897d4253 | Ruby | zfletch/data-structures | /spec/array-stack/array_stack_spec.rb | UTF-8 | 875 | 3.203125 | 3 | [
"MIT"
] | permissive | require 'array-stack/array_stack'
RSpec.describe ArrayStack do
subject(:stack) { ArrayStack.new }
describe "#empty?" do
it { should be_empty }
context "the stack is not empty" do
before { stack.push(5) }
it { should_not be_empty }
end
end
describe "#inspect" do
specify { expect(... | true |
dc7fd6e335f38edc82b36a3ca06fd6068ec559ba | Ruby | Nu-hin/remote_ruby | /lib/remote_ruby/connection_adapter/cache_adapter.rb | UTF-8 | 928 | 2.5625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module RemoteRuby
# An adapter which takes stdout and stderr from files and ignores
# all stdin. Only used to read from cache.
class CacheAdapter < ConnectionAdapter
def initialize(connection_name:, cache_path:)
super
@cache_path = cache_path
@connection_name =... | true |
a7c296b4378639bba586bffe465465ed39b935c1 | Ruby | zailleh/WDI-Classwork | /05-ruby/intro/survey.rb | UTF-8 | 550 | 4.1875 | 4 | [] | no_license | ## Basic Ruby Interaction and Coding.
# Initital greeting
puts "Welcome to the survey."
print "What is your Name? : "
name = gets.chomp # user input
# name = name.chomp #.chomp removes the last new line from the end of a string
# print out the name
puts "\nHello #{ name }."
print "What is your Surname? : "
surnam... | true |
79d7272d51051d82523a77ba097c3802b482fc07 | Ruby | MZaimanov/Inception | /Lesson_1/area_triangle.rb | UTF-8 | 278 | 3.296875 | 3 | [] | no_license | puts "Привет, посчитаем площадь треугольника!!!"
puts "Введите основание"
base = gets.chomp.to_f
puts "Введите высоту"
height = gets.chomp.to_f
puts "Площадь треугольника #{0.5 * base * height}"
| true |
3b1adbf2d22514266cb29a837dfb42ab205b543c | Ruby | lmirosevic/GBPushNotificationsService | /test/push_test_gcm.rb | UTF-8 | 1,552 | 2.65625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | #!/usr/bin/ruby
######################## SETUP ########################
API_KEY = '<insert GCM API KEY HERE>'
REGISTRATION_ID = '<insert Android device registration ID here>'
#######################################################
#get gem
require 'gcm'
#connect to Google
gcm = GCM.new(API_KEY)
#something like this... | true |
8aa21867c24d507807d7c0b8bd24fca182b5e667 | Ruby | youssefrafra/rails-longest-word-game | /app/controllers/games_controller.rb | UTF-8 | 1,391 | 2.84375 | 3 | [] | no_license | class GamesController < ApplicationController
def new
alphabet = [*("A".."Z")]
@letters = Array.new(rand(8..12)).map { |el| el = alphabet.sample }
end
def score
@answer = params[:answer]
@grid = eval(params[:grid])
url = "https://wagon-dictionary.herokuapp.com/#{@ans... | true |
ade7951ca25c91fdc7bfc051cdcd64a7e559659c | Ruby | joekabucho/ruby-web-app | /04_pig_latin/pig_latin.rb | UTF-8 | 998 | 3.625 | 4 | [] | no_license | #write your code here
def translate(string)
result =''
string.split.each do |word|
if(word[0] =='a' || word[0]=='e'|| word[0]=='i'|| word[0]=='u'|| word[0]=='o')
word += 'ay'
elsif(word[1] =='a' || word[1]=='e'|| word[1]=='i'|| word[1]=='u'|| word[1]=='o')
if(word[0] == '... | true |
776655ede41b3c0949798d7dba00f1e49ea51c0e | Ruby | dKotetunov/TasksManager | /app/models/task.rb | UTF-8 | 1,141 | 2.546875 | 3 | [] | no_license | # == Schema Information
#
# Table name: tasks
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# name :string(255)
# description :string(255)
# project_id :integer
# status :string(255)
# user_id :integer
# hours :integer
# started_... | true |
f525b92fb3855a6509a838045fdc32f94adea6ac | Ruby | jankmet/capx | /lib/capx/runner.rb | UTF-8 | 1,832 | 2.515625 | 3 | [
"MIT"
] | permissive | module Capx
class Runner
PATTERN = /server:?\s+[\'\"]([\w\-\.]+)[\'\"],\s+user:?\s+[\'\"]([\w\-\.]+)[\'\"]/
DIR_PATTERN = /set :deploy_to,\s+[\'\"](?<path>(.+)\/([^\/]+))[\'\"]/
def initialize(options)
@stage = options[:stage]
@switch = options[:switch]
@user = options[:user]
... | true |
c4f9ac0ed4678e7fc25c60768099cf675faf064f | Ruby | papapabi/project-euler | /1.rb | UTF-8 | 242 | 3.28125 | 3 | [] | no_license | require "benchmark"
time = Benchmark.measure do
puts "The sum of all multiples of 3 or 5 below 1000 is #{1.upto(999).inject(0) { |result, i| (i % 3 == 0 or i % 5 == 0) ? result + i : result}}"
end
puts "Time elapsed (in seconds): #{time}"
| true |
759d02ee6c3801281980bf75cf337174ab19d839 | Ruby | Raf-Batista/movies_nearby | /lib/movies_nearby/theater.rb | UTF-8 | 435 | 3.03125 | 3 | [
"MIT"
] | permissive | class MoviesNearby::Theater
@@all = []
attr_accessor :name, :movies
def initialize(theater_hash)
self.name = theater_hash[:name]
self.movies = MoviesNearby::Movie.create_from_collection(theater_hash[:movies])
@@all << self
end
def self.create_from_collection(theater_array)
theater_array.each d... | true |
6b14815fd04e92c245e267070e226ca6549e3cac | Ruby | mosleymos/CtCI-6th-Edition-Ruby | /Chap_1_Arrays_and_Strings/Q1_06_String_Compression.rb | UTF-8 | 533 | 3.3125 | 3 | [
"MIT"
] | permissive | def string_compression(string)
container = [
[]
]
word = string.split('')
word.each do |letter|
if container[-1] == []
container[-1] << letter
elsif container[-1][0] == letter
container[-1] << letter
else
container << []
container[-1] << letter
end
end
compressed... | true |
abbec40010eb7b69e2b05827efeaeb136dd7c4f2 | Ruby | vanduynamite/aA_coursework | /alphacourse/paul_vanduyn_rpn_calculator/lib/00_rpn_calculator.rb | UTF-8 | 1,265 | 4.03125 | 4 | [] | no_license | class RPNCalculator
def initialize()
@stack = []
end
def push(val)
@stack << val.to_f
end
def plus
calculator_empty if @stack.length < 2
@stack = @stack[0...-2] << @stack[-2] + @stack[-1]
end
def minus
calculator_empty if @stack.length < 2
@stack = @stack[0...-2] << @stack[-... | true |
a280a1b9b0349cb9306124227a530c0826544b7b | Ruby | ronaldinha/backend_challenge | /backend/level3/main.rb | UTF-8 | 857 | 2.734375 | 3 | [] | no_license | require "json"
require "byebug"
require "date"
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
# your code
DATA_FILENAME = "data.json"
OUTPUT_DIRECTORY = "result"
OUTPUT_FILENAME = "output.json"
data = JSON.parse(File.read(DATA_FILENAME), { symbolize_names: true })
expected_output = JSON.pars... | true |
1173f24cb65571369fb3fc9c7f6b447fa497f319 | Ruby | ruby-stars/lessons | /Exercises/4.10.2016/homework2.rb | UTF-8 | 357 | 3.6875 | 4 | [] | no_license | def reverse_arr1(arr)
arr2 = []
i = arr.length - 1
while i >= 0
arr2 << arr[i]
i -= 1
end
arr2
end
def reverse_arr2(arr)
arr2 = []
arr.each { |element| arr2.unshift(element) }
arr2
end
def reverse_arr3(arr)
arr.reverse
end
arr = Array.new(10) { rand(10..100) }
p arr
p reverse_arr1(arr)
p r... | true |
4d25f2a19c80d620634d0fbe59cefeded8ad0277 | Ruby | thiagoa/credits_app | /app/models/credits_expirer.rb | UTF-8 | 2,381 | 2.96875 | 3 | [] | no_license | class CreditsExpirer
def self.call(*args)
new(*args).call
end
def initialize(expiration_date)
@expiration_date = expiration_date
end
def call
Credit.transaction do
expire_due_credits
mark_credits_as_processed
end
end
private
def expire_due_credits
values_for_insert = ... | true |
f63a43d267ba7a39ec43088ade270edce1ed58c8 | Ruby | SandyHendry/Codeclan-Course | /day_2/start_point/country_functions.rb | UTF-8 | 2,531 | 3.375 | 3 | [] | no_license | def name_of_first_country( countries )
return countries.first[ "name" ]
end
def population_of_first_country( countries )
return countries.first[ "population" ]
end
def borders_of_first_country( countries )
return countries.first[ "borders" ].size
end
def total_population( countries )
total = 0
for count... | true |
7aecb7e4901733023f9d091d9e84a0d084aed931 | Ruby | jconde42/chess | /lib/pieces/rook.rb | UTF-8 | 2,077 | 3.171875 | 3 | [] | no_license | class Rook < Piece
def set_position(arr)
@position = arr
@moved = true
end
def set_moves(board)
x = @position[0]
y = @position[1]
# moves up
(y+1..7).each do |row|
if !valid_coordinate?([x,row])
break
end
if !board.arr[x][row].nil? && board.arr[x][row].team != ... | true |
509ae9f2de583ac230b23bbec63d558be0c6306c | Ruby | charlietag/trello-utils | /trello.rb | UTF-8 | 2,089 | 2.53125 | 3 | [] | no_license | #!/usr/local/bin/ruby
require 'yaml'
require 'trello'
include Trello
require_relative 'lib/filelock'
#-----------------------------
# Script lock
#-----------------------------
script = Filelock.new
script.lock
#-----------------------------
# Setup Trello
#-----------------------------
config_file = File.dirname(__F... | true |
9136eaec013b5361e1e7be85a900a716258dd7f3 | Ruby | fhhopkinson/WDI_project_2 | /app/controllers/pieces_controller.rb | UTF-8 | 1,167 | 2.6875 | 3 | [] | no_license | # INDEX
get "/pieces" do
# authorize!
@pieces = Piece.all
erb :"pieces/index"
end
# New
get "/pieces/new" do
authorize!
@piece = Piece.new
erb :"pieces/new"
end
# SHOW
get "/pieces/:id" do
# authorize!
@piece = Piece.find(params[:id])
erb :"pieces/show"
end
#Create
post "/pieces" do
authorize!
... | true |
5a6dc5752b41cf8fceaf28db012d65b1be0cfb86 | Ruby | greghuber/phase-0-tracks | /ruby/hashes.rb | UTF-8 | 2,499 | 4.3125 | 4 | [] | no_license | # Program to allow interior designer to enter details of a given client:
# Convert responses to input questions so that:
# name, city, and decor theme are strings,
# age, number of chilren, and sq ft of home are integers, and
# whether the client was a referral, whether the home is a single family as
# opposed to mul... | true |
fc72aa2429a5dfce26c679322d4bb79b36b7a821 | Ruby | Mikeydlane/todonot | /lib/todo.rb | UTF-8 | 151 | 3.1875 | 3 | [] | no_license | require "pry"
class Todo
def initialize(file_name)
@todos = File.read(file_name).split("\n")
end
def add(todo)
@todos << todo
end
end
| true |
e142659fb34c93bce9e95c34476eabcdb52ce9cf | Ruby | dannyradden/module_3_assessment | /app/services/best_buy_service.rb | UTF-8 | 519 | 2.5625 | 3 | [] | no_license | class BestBuyService
attr_reader :connection
def initialize
@connection = Faraday.new("https://api.bestbuy.com/v1/")
end
def stores(location)
parse(connection.get("stores(area(#{location},25))",
{ format: 'json',
show: 'storeId,storeType,name,city,distance,pho... | true |
e4ff43228800fc320355c76d108d76338c35002d | Ruby | cifarquhar/animal_shelter | /models/bio.rb | UTF-8 | 1,021 | 3.296875 | 3 | [] | no_license | require_relative('../db/sql_runner')
require_relative('animal')
class Bio
attr_reader :id, :animal_id
attr_accessor :biography
def initialize(options)
@id = options['id'].to_i if options['id']
@animal_id = options['animal_id']
@biography = options['biography']
end
def self.map_bios(sql)
bi... | true |
fb01df8a1010f045118326a3ec7da2047172d570 | Ruby | lshapz/activist_dashboard | /lib/auth.rb | UTF-8 | 742 | 2.671875 | 3 | [] | no_license | require 'jwt'
class Auth
def self.issue(payload)
JWT.encode payload, Rails.application.secrets[:secret_key_base], 'HS256'
end
def self.decode(token)
JWT.decode(token, Rails.application.secrets[:secret_key_base], true, { :algorithm => 'HS256' })
end
end
# class Auth
# ALGORITHM = 'HS256'
# def se... | true |
36b23c425eb088c42276939b8db9b3669f39192c | Ruby | hkdnet/misc | /atcoder/abc126/f.rb | UTF-8 | 394 | 2.90625 | 3 | [] | no_license | m, k = gets.chomp.split(' ').map(&:to_i)
def print_ans(*arr)
puts arr.join(' ')
end
if k >= 2**m
puts '-1'
else
case m
when 0
if k == 0
print_ans(0, 0)
else
puts '-1'
end
when 1
if k == 0
print_ans(0, 0, 1, 1)
else
puts '-1'
end
else
a = (0...(2**m)).to_... | true |
909fdcf0f8656bae8b379ef0dfa83eb2246b5ae5 | Ruby | uk-gov-mirror/UKGovernmentBEIS.beis-report-official-development-assistance | /app/services/update_user_in_auth0.rb | UTF-8 | 437 | 2.671875 | 3 | [
"MIT"
] | permissive | require "./lib/auth0_api"
class UpdateUserInAuth0
attr_accessor :user
def initialize(user:)
self.user = user
end
def call
return unless synchronise?
auth0_client.update_user(
user.identifier,
email: user.email,
name: user.name,
)
end
private
def auth0_client
@au... | true |
56e237f2e3bc9114a52f3445ec25100ffb444fcd | Ruby | rothberry/leet | /ruby/defang_i_paddr.rb | UTF-8 | 348 | 3.40625 | 3 | [] | no_license | # @param {String} address
# @return {String}
# ? Given a valid (IPv4) IP address, return a defanged version of that IP address.
# ? A defanged IP address replaces every period "." with "[.]".
def defang_i_paddr(address)
address.split(".").join("[.]")
end
p defang_i_paddr("1.1.1.1")
# Output: "1[.]1[.]1[.]1"
# p de... | true |
96ba905e68f5ce7e54bd6959145e37603439557f | Ruby | thagomizer/Euler | /068s/magic_ring.rb | UTF-8 | 1,690 | 3.5 | 4 | [] | no_license | # Consider the following "magic" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.
# Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be descri... | true |
0f354b12b16198cc3fd917cc925faea4e96c23e7 | Ruby | njohnson7/launch-school-courses | /launch_school_170/lesson4_working_with_sinatra/practice.rb | UTF-8 | 1,038 | 2.59375 | 3 | [] | no_license | require 'sinatra'
get '/' do
'Hello world!'
end
get '/advice' do
'ADVICE!'
end
get 'hello/:name' do |n|
"Hello #{n}!"
end
get 'say/*/to/*' do
params['splat']
end
class Stream
def each
100.times { |i| yield "#{i}\n" }
end
end
get('/stream') { Stream.new }
get '/template' do
erb "<%= Time.now %>"... | true |
3bf8bd52fc68699409d04e99bab71a4164b4dd51 | Ruby | pbstriker38/line-of-credit | /spec/models/user_spec.rb | UTF-8 | 2,317 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe '#set_up_user' do
before(:all) do
@user = User.new(
first_name: 'Bill',
last_name: 'Miller',
email: 'bill.miller@example.com',
password: 'password'
)
@user.set_up_user
end
it "sets the ... | true |
1c6bfe3d360bacccad067ecfd09d94f316977051 | Ruby | bricooke/whenisthat.net | /test/whenisthat_test.rb | UTF-8 | 2,354 | 2.6875 | 3 | [] | no_license | require 'rubygems'
require 'test/unit'
require 'rack/test'
require 'whenisthat.rb'
class WhenIsThatTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
WhenIsThat::Base.new
end
def test_loads_initial_page
get '/'
assert last_response.ok?
end
def test_simple_conversion
post '/w... | true |
11aa51d3aaf692d34525ccf3c7293f74db8c0106 | Ruby | aconstantinou123/music_store_project | /models/artist.rb | UTF-8 | 3,361 | 3.15625 | 3 | [] | no_license | require_relative('../db/sql_runner.rb')
class Artist
attr_accessor :id, :name, :genre, :logo
def initialize(options)
@id = options['id'].to_i
@name = options['name']
@genre = options['genre'].to_s
@logo = options['logo'].to_s
end
def self.delete_all()
sql = "DELETE FROM artists"
SqlR... | true |
4e2e88013d52ed8bd0d80e9e7a93ced7db87132e | Ruby | deepatel/csc517project1 | /test/unit/vote_test.rb | UTF-8 | 1,276 | 2.5625 | 3 | [] | no_license | require 'test_helper'
class VoteTest < ActiveSupport::TestCase
test "vote must have a user" do
u1 = User.first
u2 = User.last
p = Post.new(:user => u1, :data => "post from u")
p.save
v = Vote.new(:post => p)
assert ! v.valid?
v.user = u2
assert v.valid?
end
test "vote must have... | true |
8e59872d750777812dff87287a3a8b03d630d7bb | Ruby | sdelay01/hb | /helpers/captcha_helper.rb | UTF-8 | 590 | 2.546875 | 3 | [] | no_license | require 'open-uri'
module CaptchaHelper
def captcha_pass?
session = params[:captcha_session].to_i
answer = params[:captcha_answer].gsub(/\W/, '')
open("http://captchator.com/captcha/check_answer/#{session}/#{answer}").read.to_i.nonzero? rescue false
end
def captcha_session
@captcha_session ||=... | true |
1cb842501ed4830de82786f709950f4f18903c09 | Ruby | monchu5492/ruby-enumerables-cartoon-collections-lab-seattle-web-102819 | /cartoon_collections.rb | UTF-8 | 544 | 3.28125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves(dwarf_array)
d_array = dwarf_array
counter = 1
d_array.each {
|element, index| p "#{counter}. #{element}"
counter += 1
}
end
def summon_captain_planet(calls)
caals = calls.map {
|chants| "#{chants.capitalize}!"
}
end
def long_planeteer_calls(long_calls)
lcalls = long... | true |
34d72f4b24c6bba7eb06d4fa99da53d925ab0c0f | Ruby | xarisd/ruby-basics | /source/01_taste/08a_no_symbols.rb | UTF-8 | 345 | 3.984375 | 4 | [
"MIT"
] | permissive | UP = 1
DOWN = 2
RIGHT = 3
LEFT = 4
def look(direction)
if direction == UP
puts "looking up"
elsif direction == DOWN
puts "looking down"
elsif direction == RIGHT or direction == LEFT
puts "looking sideways"
else
puts "Hey! what are you doing? LOOK AT ME!"
end
end
look(UP)
look(DOWN)
look(LEFT... | true |
016c0eb4a4048568e7774b1d683ca2ff83509d83 | Ruby | Incertotempore/SPINNER | /db/seeds.rb | UTF-8 | 1,588 | 2.671875 | 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 |
dad4c2b540f25a5bfdb9afb9f564af785f9b2d44 | Ruby | thomasdwood/chess | /spec/board_spec.rb | UTF-8 | 6,190 | 3.109375 | 3 | [] | no_license | require './lib/board.rb'
RSpec.describe Board do
test = Board.new
board = test.instance_variable_get(:@board)
context 'When New Game Started' do
describe 'places all the black pieces' do
it 'places only black pieces' do
(0..1).each do |r|
(0..7).each do |p|
expect(board... | true |
4cf5a58efb070a9535d47f593ea513c014965b8f | Ruby | brenoperucchi/tdlib-ruby | /lib/tdlib/types/chat_event.rb | UTF-8 | 561 | 2.703125 | 3 | [
"MIT"
] | permissive | module TD::Types
# Represents a chat event.
#
# @attr id [Integer] Chat event identifier.
# @attr date [Integer] Point in time (Unix timestamp) when the event happened.
# @attr user_id [Integer] Identifier of the user who performed the action that triggered the event.
# @attr action [TD::Types::ChatEventAct... | true |
07ea94308df49d14ba900dda6c151ceeb855d12f | Ruby | Frajdi/Minesweeper_game-Ruby- | /minesweeper.rb | UTF-8 | 1,475 | 3.6875 | 4 | [] | no_license | require_relative "board"
require_relative "tile"
class Minesweeper
def initialize
@board = Board.new
@board.bombing
@board.tile_placement
end
def valid_pos?(pos)
pos.is_a?(Array) && pos.length == 2 && pos.all? { |x| x.between?(0, 8) } && !@board[pos... | true |
8651960f1091852ece5631c38555cb28af1e2aa6 | Ruby | reframeit/merb | /merb-core/spec/public/router/generation/params_spec.rb | UTF-8 | 2,718 | 2.578125 | 3 | [
"MIT"
] | permissive | require File.join(File.dirname(__FILE__), '..', "spec_helper")
describe "When generating URLs," do
describe "passing params in anonymously to routes" do
before(:each) do
Merb::Router.prepare do
match("/:first/:second/:third").name(:ordered)
end
end
it "should match the pa... | true |
e62392199f1b48a9c1c72ffb2881e93d2154f539 | Ruby | ksdaly/restclient_wrapper | /service.rb | UTF-8 | 1,621 | 2.609375 | 3 | [] | no_license | module Service
extend ActiveSupport::Concern
included do
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
TIMEOUT = 1
OPEN_TIMEOUT = 3
FORMAT = 'application/json'
cattr_accessor :resource
self.resource = RestClient::Resource.new(SERVICES... | true |
ca2755075414b1784d2ff16be3e63e78afda784c | Ruby | chemistrytocode/Makers-Academy | /Week_Projects/sinatra/lib/app.rb | UTF-8 | 331 | 2.578125 | 3 | [] | no_license | require 'sinatra'
require 'pry'
get '/' do
"Hello World"
end
get '/secret' do
"Different Message!"
end
get '/random-cat' do
@name = ["Amigo", "Oscar", "Viking"].sample
erb :index
end
post '/named-cat' do
p params # prints to server log
@name = params[:name]
erb :index
end
get '/cat-form' do
erb :ca... | true |
8a3bd09e13141a20470195d6cfc1c361b8454bb7 | Ruby | xing/pdf_cover | /lib/pdf_cover.rb | UTF-8 | 3,947 | 2.84375 | 3 | [
"MIT"
] | permissive | require "pdf_cover/version"
require "pdf_cover/converter"
# This module provides methods for CarrierWave::Uploader::Base subclasses and
# for ActiveRecord models that want to include attachments to simplify the
# generation of JPEG images from the first page of a PDF file that is uploaded
# by the users.
# Include thi... | true |
635b1f5610e611962f9fdf5699e71d673a5895a8 | Ruby | rossfoley/advent-of-code | /2015/day24.rb | UTF-8 | 526 | 3 | 3 | [] | no_license | packages = File.read('day24-input.txt').lines.map(&:to_i)
weight = packages.reduce(:+) / 3
# Part 1
possibilities = packages.combination(6).to_a.reject do |c|
c.reduce(:+) != weight
end.map do |c|
[c.size, c.reduce(:*)]
end.sort do |a, b|
a[1] <=> b[1]
end
puts possibilities.inspect
# Part 2
weight = packages.... | true |
032c95ec6a5f1eac2e3c402aca594835b85505d1 | Ruby | santatramaximin/Ruby | /exo9.rb | UTF-8 | 113 | 3.125 | 3 | [] | no_license | puts "Bonjour, presentez-vous ?"
print ">"
nom = gets.chomp
print ">"
prenom = gets.chomp
puts "#{nom} #{prenom}" | true |
f3f2cb15012db635fa9d0153b4cb20ba916e65be | Ruby | Miradorn/exercism | /ruby/hexadecimal/hexadecimal.rb | UTF-8 | 438 | 3.578125 | 4 | [] | no_license | # Implements Base16 to Base10 conversion
class Hexadecimal
VALUE = '0123456789abcdef'.each_char
.each_with_index
.map { |l, v| [l, v] }.to_h.freeze
def initialize(value)
@value = value
end
def to_decimal
return 0 unless @value =~ /\A[0-9a-f]*\Z/
... | true |
8760667d48ee0a40bc91b8159dd2a79f77dd3c81 | Ruby | justdroo/mirror-mirror | /src/lecture/01_data_types_and_variables/variables_04_mutability.rb | UTF-8 | 149 | 3.171875 | 3 | [] | no_license | name = "Drew"
# => "Drew"
name.upcase
# => "DREW"
name
# => "Drew"
cappedName = name.upcase
# => "DREW"
name
# => "Drew"
cappedName
# => "DREW"
| true |
bc70bd45182df59d2abe5d19dd10019403bd59fd | Ruby | vanegg/Rubylearning | /S2D3/corregir_clase_getterssetters.rb | UTF-8 | 587 | 4 | 4 | [] | no_license | #Corrige el código de la clase Window.
#No uses attr_reader, attr_writer o attr_accessor. Haz pasar las pruebas.
class Window
def initialize (color, size)
@color = color
@size = size
end
#getters
def color
@color
end
#setters
def size=(new_size)
@size = new_size
end
def open
... | true |
6e8840bf4f1ca78d1370db3c8252753f1e3d0eae | Ruby | MysJif/rb101-rb109 | /easy_8/repeater.rb | UTF-8 | 451 | 3.6875 | 4 | [] | no_license | def repeater(string)
string.chars.map { |char| char *= 2}.join('')
end
def double_consonants(string)
string.chars.map do |char|
if char.downcase.match?(/[a-d|f-h|j-n|p-t|v-z]/)
char *= 2
else
char
end
end.join('')
end
puts double_consonants('String') == "SSttrrinngg"
puts double_consonan... | true |
efaba5cbec3a6bcd38f2ec7749f7186cbade6b86 | Ruby | lgrover/FinModeling | /specs/company_spec.rb | UTF-8 | 2,393 | 2.546875 | 3 | [] | no_license | # company_spec.rb
require 'spec_helper'
describe FinModeling::Company do
before(:each) do
end
describe "initialize" do
it "takes a SecQuery::Entity and creates a new company" do
entity = SecQuery::Entity.find("aapl", {:relationships=>false, :transactions=>false, :filings=>true})
FinModeling::C... | true |
d944ec9e6e274986938e01cd672eec85f2332ae2 | Ruby | HalRockwell/Calc-Stuff | /calc_stuff.rb | UTF-8 | 377 | 4.1875 | 4 | [] | no_license | puts "Welcome to The Calculator. \nUse '+' for addition, '-' for subtraction, '*' for multiplication, '/' for divison, \n'**' for exponentation. \nOnly use two numbers for now. Enter 'quit' to quit."
input = gets.chomp
def math(user_input)
new = user_input.split(" ")
new[0] = new[0].to_f; new[2] = new[2].to_f
... | true |
0cb156ad40f59b923fcc22d64dacd4bbabac8f4b | Ruby | konradrog/Ruby_Introduction | /Zadania_02_OOP/sieve_of_erastosthenes.rb | UTF-8 | 805 | 3.734375 | 4 | [] | no_license | class Erasto
attr_accessor :board, :board_final
def initialize(begining,ending)
table = (begining..ending)
@board = (table.map { |el| [el, true]}).to_h
@board_final = []
end
def calculate
board_final = @board
while board_final.has_value?(true)
first_el = board_final.keys.first
... | true |
ede9535c352eb95544696bdb5a89848e697a4ef9 | Ruby | eamono1/saas_berkeley | /ruby/homework/hw1/lib/fun_with_strings.rb | UTF-8 | 1,561 | 4.03125 | 4 | [] | no_license | module FunWithStrings
def palindrome?
# remove all characters not letters
str = self.downcase.gsub(/[^a-z]/, '')
str.reverse == str
end
# return a hash whose keys are words, and values are number of times
# the word has appeared
def count_words
# clean up string
str = self.downcase.gsub(/... | true |
bc274e9d003c662974e5eff981ba88a703451d8b | Ruby | Sheena-Marie/ruby-practice | /homework.rb | UTF-8 | 1,745 | 4.375 | 4 | [] | no_license | # create a dictionary (hash) of 10 cities where the city name would be a string and the key
# the area code would be the hash.
# get input from teh user on teh city name. (use gets.chomp method)
#display the city names to the user that are available in the ditionary.
#display the area code based on user's city choi... | true |
ccc8bf69b84f51ce38c4a2333f99870253978fdf | Ruby | AdreyuVILCA/Fundamentosde-ProgramacionG1 | /AreaTriangulo.rb | UTF-8 | 231 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | #Definir Variables y otros
pust "Hola"
#Datos de entrada por dispositivos de entrada
print"Ingrese base"
b= gest.to_i
print"Ingrese Altura"
h=gest.to_i
#Proceso
area=(b*h)/2
#Datos de Salida
pust"El area del Triangulo es:#(area)" | true |
d855316fd8af0abe7a2b298898b990d64e15f30a | Ruby | dwinniford/adagio_tea_sale | /lib/adagio_tea_sale/tea.rb | UTF-8 | 2,675 | 2.796875 | 3 | [
"MIT"
] | permissive | class AdagioTeaSale::Tea
attr_accessor :name, :sale_price, :original_price, :large_price, :rating, :small_quantity, :large_quantity, :price_per_cup, :percent_off, :info, :caffeine, :brewing, :url
@@all = []
def initialize
@@all << self
end
def self.all
@@all
end
def self.create_from_... | true |
83db1dd0b105ea50bfdefe8e083480d9940e5292 | Ruby | jcbalcita/algorithms | /heaps-heapsort/lib/heap.rb | UTF-8 | 2,022 | 3.65625 | 4 | [] | no_license | class BinaryMinHeap
def initialize(&prc)
self.store = []
self.prc = prc || Proc.new { |x, y| x <=> y }
end
def count
store.length
end
def extract
raise "cannot extract" if count == 0
store[0], store[store.length - 1] = store[store.length - 1], store[0]
popped = store.pop
self.cl... | true |
13267897b04ef5030bfbf63bf9079018f90297b9 | Ruby | ifyouseewendy/algs4ruby | /lib/algs4ruby/sorting/merge.rb | UTF-8 | 2,116 | 3.15625 | 3 | [
"MIT"
] | permissive | module Algs4ruby
class Sorting
class Merge < Base
# = O(NlgN)
#
# = Stable
#
# = Out-of-place
#
# Using auxiliary arrays.
#
# = Practical Improvements
#
# + Sort manually (Insertion) for small arrays.
# + No merge if already sorted.
... | true |
e66b44f9e04a807faabe6edbc735b4daa2422121 | Ruby | wemrekurt/Ruby | /bolunurmu.rb | UTF-8 | 273 | 3.59375 | 4 | [] | no_license | def bolhesap(x,y)
if x%y==0 then
puts "#{x} sayisi #{y} sayisina kalansiz bolunur"
else
a=x%y
puts "#{x} sayisi #{y} sayisina bolunmez ve kalan= #{a}"
end
end
bolhesap(73,24)
dizi=[1,2,3,4,5]
puts dizi[0]
bilgi = ['isim'=>"Emre",'soyisim'=>"Kurt"]
| true |
f81825821553e12097f2b542d6a5d6d3ee1b410d | Ruby | Robright20/drivy_test | /level2/main.rb | UTF-8 | 1,231 | 3.15625 | 3 | [] | no_license | require 'json'
require './lib/cars'
require './lib/rentals'
require './lib/discounts'
#gives the number of rental days
def number_of_days(rental)
number_of_days = (rental.end_date - rental.start_date)
number_of_days = number_of_days.to_i + 1
end
#gives the number of rental days multiplied by the car's price per day... | true |
81f797b7f8aed49031e02aa883a25996060c2e21 | Ruby | AmirArreaza/TechnicalTestRuby | /bitmap_test.rb | UTF-8 | 640 | 2.78125 | 3 | [] | no_license | require 'test/unit'
require_relative "bitmap_editor"
class BitmapEditorTest < Test::Unit::TestCase
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
# Do nothing
end
# Called after every test method runs. Can be used to tear
# down fixture information.
... | true |
db8e7b2e117f9f4f42f3079bfa66b9db6ebf765d | Ruby | ivanvanderbyl/skyscraper | /lib/sky_scraper.rb | UTF-8 | 1,345 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require "rubygems"
require "nokogiri"
require 'open-uri'
require 'blockenspiel'
autoload :Scrapeable, File.join(File.dirname(__FILE__), 'scrapeable')
autoload :ORM, File.join(File.dirname(__FILE__), 'orm')
# Load all our models
Dir.glob(File.join("..", 'models', '*.rb')).each{ |model| require model}
class Block
in... | true |
6c304653ba5b12aeaa1458c46aedcba2f4099c37 | Ruby | DaseulChun/codecore_notes | /W6D2_ruby_oop/car.rb | UTF-8 | 1,146 | 3.796875 | 4 | [] | no_license | # Exercise: Car blueprints
class Car
attr_accessor :model, :type, :capacity
# Mthods can have default values for its argyments
# by using assignment syntax in the argument
# declaration position.
# This makes the argument optional. If not provided,
# the default value will be used.
def initialize(mode... | true |
8cc45711d75a13d5a5bffa3467ee35fc504656b8 | Ruby | JakubowskiA/my-each-nyc-web-060319 | /my_each.rb | UTF-8 | 83 | 3.078125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def my_each(array)
i = 0
while i<array.size
yield(array[i])
i += 1
end
array
end
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.