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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
64c78703092a523263dd98fd479d8392aa83f71c | Ruby | shravanc/treasurehunt | /spec/models/treasure_hunt_spec.rb | UTF-8 | 1,792 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe TreasureHunt, type: :model do
context 'Validation check' do
let(:th) do
TreasureHunt.new(
current_location: [50.051227, 19.945704],
email: 'example@domain.com'
)
end
it 'Valid Obj' do
expect(th).to be_... | true |
73e8f1ec36464ae349e7a8ea52777b2f2e8e7c0f | Ruby | nsikanikpoh/ruby_dev | /orderweight.rb | UTF-8 | 285 | 2.765625 | 3 | [] | no_license | def order_weight(strng)
strng.split.sort_by { |n| [n.chars.map(&:to_i).reduce(:+), n]}.join(' ')
end
p order_weight("103 123 4444 99 2000") # "2000 103 123 4444 99")
p order_weight("2000 10003 1234000 44444444 9999 11 11 22 123") #, "11 11 2000 10003 22 123 1234000 44444444 9999")
| true |
33ec91272f0c5705aeb82eb4220ab9ca45bf92f8 | Ruby | kikicat-meows/aA_Classwork | /W5D5/movie_buff/skeleton/movie_buff/03_queries.rb | UTF-8 | 2,484 | 3.40625 | 3 | [] | no_license | def what_was_that_one_with(those_actors)
# Find the movies starring all `those_actors` (an array of actor names).
# Show each movie's title and id.
Movie.select(:id, :title)
.joins(:actors)
.where(actors: {name: those_actors})
.group('movies.id')
.having('COUNT(*) = ?', those_actors.l... | true |
90325b5ba9273b34996e8cade62556f9269a2fbd | Ruby | MonalisaC/array_equals | /lib/array_equals.rb | UTF-8 | 515 | 3.578125 | 4 | [] | no_license | # Determines if the two input arrays have the same count of elements
# and the same integer values in the same exact order
# def array_equals(array1, array2)
# return array1.nil? && array2.nil? if array1.nil? || array2.nil?
# return array1.sort == array2.sort
# end
def array_equals(array1, array2)
return array1.n... | true |
4cda85d960a14d56bee8f95fbdc80e318cb36aff | Ruby | matthewrudy/rude-bench | /ruby/define_method_vs_class_eval.rb | UTF-8 | 1,347 | 3.359375 | 3 | [] | no_license | <<-INTRO
Question:
Is define_method slower than an eval?
define_method :something do
end
class_eval do
def something
end
class_eval "def something; end"
def something
end
Answer:
define_method is quite a bit slower
user system total... | true |
313a682d9da3fa62812ab9f1c3db2a6fa0e0ddc2 | Ruby | GiorgiChanturia/e-procurement-site | /lib/aggregate_helper.rb | UTF-8 | 17,044 | 2.546875 | 3 | [] | no_license | # encoding: utf-8
module AggregateHelper
require "graph_helper"
class TenderTypeStat
def initialize(name)
@name = name
@count = 0
@successCount = 0
@value = 0
@averageBidDuration = 0
@averageWarningPeriod = 0
@averageBidders = 0
@averageBids = 0
@totalBidder... | true |
d524dbd5b27b44bcdfb1a15831324a3a8ca388a3 | Ruby | NextAcademy/wd-prepwork | /q4.rb | UTF-8 | 215 | 3.671875 | 4 | [] | no_license | # Declare a variable called "animals". This variable should:
# 1. Be a hash.
# 2. Store animals as a key.
# 3. Store corresponding animals' number of legs as a value.
animals = {dog: 4, chicken: 2, :burger => 0} | true |
db826cf16bf87adb5f0b77666c646add75cc280d | Ruby | mwagner19446/wdi_work | /w07/d04/Isaac/weather.rb | UTF-8 | 798 | 3.21875 | 3 | [] | no_license | require 'httparty'
require 'pry'
api_key = '2d48a02fe0070bce'
def current_temperature(city, state)
api_url = "http://api.wunderground.com/api/2d48a02fe0070bce/conditions/q/#{state}/#{city}.json"
from_api = HTTParty.get(api_url)
current_temp = from_api["current_observation"]["temp_f"]
puts "The current tempera... | true |
57bfce6b638eeb0ae9b8d137aa5545ba920f3dbc | Ruby | pyreta/poker.rb | /lib/hand.rb | UTF-8 | 14,022 | 3.46875 | 3 | [] | no_license | require_relative './card'
require_relative './deck'
require_relative './board.rb'
require 'pry'
class Hand
STARTING_RANKS = {
1 => ['AA', 'KK', 'JJ', 'QQ', 'AKs'],
2 => ['TT', 'AQs', 'AJs', 'KQs', 'AKo'],
3 => ['99', 'ATs', 'KJs', 'QJs', 'JTs', 'AQo'],
4 => ['88', 'KTs', 'QTs', 'J9s', 'T9s', '98s', '... | true |
a1882e4daf85e1e56a5bb7790fd1c3aa38fa4496 | Ruby | debonairism/health_check | /health_check.rb | UTF-8 | 1,269 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
class HealthCheck
require File.dirname(__FILE__) + '/health_check_options'
require File.dirname(__FILE__) + '/health_check_url'
require File.dirname(__FILE__) + '/penetrator'
require 'terminal-table'
def initialize
argument_passed ||= ARGV[0]
argument_passed.nil? ? @options = He... | true |
0266ce6799024c7deaa883a04c05d51d9566f664 | Ruby | EnricoGallus/ruby_intro | /04_Math.rb | UTF-8 | 209 | 3.453125 | 3 | [] | no_license | puts -5.53234
puts 2 - 4
puts 2**3
num = -20.487
puts ("my fav num " + (num % 3).to_s)
puts num.abs()
puts num.round()
puts num.ceil()
puts num.floor()
puts Math.sqrt(36)
puts 1.0 + 7
puts 10 / 7
puts 10 / 7.0 | true |
26f82d1f83659719fcbb66c56e50be72fd3206ee | Ruby | 30acres/quick_orders | /lib/orders/line_item.rb | UTF-8 | 1,273 | 2.5625 | 3 | [
"MIT"
] | permissive | module QuickOrders
class LineItem
include CsvHelpers
def initialize(order,index,lin)
@order = order.data
@line_item = order.data['line_items'][lin]
end
def details
{
line_item_quantity: line_item_quantity,
line_item_name: line_item_name,
line_item_price: line... | true |
8db0161696a8a412f8255ee1d6dd0e08f613ff5e | Ruby | takeshinoda/php2haml_preprocessor | /lib/php2haml_preprocessor/erb_converter.rb | UTF-8 | 1,445 | 2.8125 | 3 | [
"MIT"
] | permissive | module Php2hamlPreprocessor
class ErbConverter
def initialize(codes)
@codes = codes
end
def convert
@codes.inject('') do |erb, code|
erb + if code[:type] == :php
ptptag2erbtag(code[:code])
else
code[:code]
end
end
... | true |
7a457dee4f44c3af2bdb57c49b4585d23ac3de62 | Ruby | detonih/Code-Wars | /alternateCapitalization.rb | UTF-8 | 560 | 3.6875 | 4 | [] | no_license | def capitalize(s)
joinArrays = []
chars = s.split('')
alternateEvenChars = chars.map.with_index do |char, i|
if i % 2 == 0
char.upcase
else
char.downcase
end
end
alternateOddChars = chars.map.with_index do |char, i|
if i % 2 != 0
char.upcase
else
... | true |
d9f137dfe5901482e8751a8492b12c8396bf03d8 | Ruby | titofranco/patterns | /proxy/proxy_delegation.rb | UTF-8 | 1,838 | 3.640625 | 4 | [] | no_license | class BankAccount
attr_reader :balance
def initialize(starting_balance=0)
@balance = starting_balance
end
def deposit(amount)
@balance += amount
end
def withdraw(amount)
@balance -= amount
end
end
class BankAccountProxy
def initialize(real_object)
@subject = real_object
end
def ... | true |
ccb753e0d40c7aacce0da698aa49c65e5d38bd81 | Ruby | schleary/solar_system | /solar_system.rb | UTF-8 | 3,700 | 3.109375 | 3 | [] | no_license | class SolarSystem
attr_accessor :planets, :formation_date
def initialize(planets, formation_date)
@planets = planets
@formation_date = formation_date
end
def find(planet_name)
@planets.find{|planet|planet.name.downcase == planet_name}
end
end
class Planet
attr_accessor :zodiac, :name, :d... | true |
c5ed36442fd463fb656eb0b275809d23a6a9ef54 | Ruby | nahi/jruby-pki.appspot.com | /apps/WEB-INF/app.rb | UTF-8 | 3,559 | 2.65625 | 3 | [] | no_license | require 'rubygems'
require 'sinatra'
require 'openssl'
require 'digest'
get '/' do
result = []
result << "PKey test"
result << do_pkey
result << "BN test"
result << do_bn
result << "Digest test"
result << do_digest
result << "ext Digest test"
result << do_ext_digest
result << "Cipher test"
resul... | true |
a58108eb674b12ae2e61fbc39c2d36bcece29c65 | Ruby | mik9/fastlane-plugin-automated-test-emulator-run | /lib/fastlane/plugin/automated_test_emulator_run_mik/factory/adb_controller_factory.rb | UTF-8 | 1,950 | 2.515625 | 3 | [
"MIT"
] | permissive | module Fastlane
module Factory
class ADB_Controller
attr_accessor :command_stop,
:command_start,
:command_get_devices,
:command_wait_for_device,
:command_get_avds,
:command_get_installed_packages,
... | true |
6d870d96dbbc149e8418547929271efd52e62386 | Ruby | gnwankwo/apples-and-holidays-001-prework-web | /lib/holiday.rb | UTF-8 | 2,656 | 3.90625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def second_supply_for_fourth_of_july(holiday_hash)
# given that holiday_hash looks like this:
# return the second element in the 4th of July array
return holiday_hash[:summer][:fourth_of_july][1]
end
def add_supply_to_winter_holidays(holiday_hash, supply)
# holiday_hash is identical to the o... | true |
a8fe1c505945da3de74bff6702ba161a0e5fd52e | Ruby | onlinecursos/coursera-2016 | /RoR-Web-Development/01-RoR-Intro/Module02/44-module-as-mixin.rb | UTF-8 | 372 | 3.421875 | 3 | [] | no_license | module SayMyName
attr_accessor :name
def print_name
puts "Name: #{@name}"
end
end
class Person
include SayMyName
end
class Company
include SayMyName
end
person = Person.new
person.name = "Joe"
person.print_name # => Name: Joe
company = Company.new
company.name = "Google & Microsoft LLC"
co... | true |
4d09533836e78b6c36b04bafef9d237a96ac88c6 | Ruby | felixclack/teaching-vacancies | /spec/presenters/vacancy_presenter_spec.rb | UTF-8 | 9,618 | 2.5625 | 3 | [
"MIT"
] | permissive | require "rails_helper"
RSpec.describe VacancyPresenter do
subject { described_class.new(vacancy) }
describe "#expired?" do
context "when the vacancy has expired by now" do
let(:vacancy) { build(:vacancy, expires_at: 1.hour.ago) }
it "returns true" do
expect(subject).to be_expired
en... | true |
6de42e1faba3377583471b050249962a1c9ca303 | Ruby | RPiper93/learn_to_program | /ch12-new-classes-of-objects/party_like_its_roman_to_integer_mcmxcix.rb | UTF-8 | 608 | 3.5625 | 4 | [] | no_license | def roman_to_integer roman
roman = roman.upcase.reverse
number = 0
numerals = {"M" => 1000, "D" => 500, "C" => 100, "L" => 50, "X" => 10, "V" => 5, "I" => 1}
roman = roman.split ""
roman.each_index { |index|
letter = roman[index]
prev_letter = roman[index - 1]
divide = numerals[prev_letter]/numera... | true |
1dbfcfc145fd683fc6aefbe75e323e40c7cfe7e3 | Ruby | Terminator-Over-20/Instagram_API_JJM | /app.rb | UTF-8 | 8,422 | 2.625 | 3 | [] | no_license | require "sinatra"
require "sinatra/namespace"
require_relative 'models.rb'
require_relative "api_authentication.rb"
require "json"
require 'fog'
require 'csv'
require 'httparty'
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => 'youraccesskey',
:aws_secret_acc... | true |
d60ba9fbcc28230c08c61d00e70dbc7ed32918bb | Ruby | bgolub18/array_of_challenges | /donut_dibs.rb | UTF-8 | 575 | 3 | 3 | [] | no_license | donut_box1 = ["Boston Creme", "Boston Creme", "Boston Creme", "Choc Long John", "Choc Long John", "Vanilla Long John", "Vanilla Long John", "Old Fashioned", "Old Fashioned", "Old Fashioned", "French thing", "French Thing"]
donut_box2 = ["Choc Sprinkles", "Choc Sprinkles", "double choc cake", "double choc cake", "double... | true |
6fa1d85b03917646e5555b5f8e208b243c98ca64 | Ruby | sunny-mittal/project-euler | /ruby/maximum_path_sum_1.rb | UTF-8 | 844 | 3 | 3 | [
"MIT"
] | permissive | triangle_nums = %w( 75 95 64 17 47 82 18 35 87 10 20 04 82 47 65 19 01 23 75 03 34 88 02 77 73 07 63 67 99 65 04 28 06 16 70 92 41 41 26 56 83 40 80 70 33 41 48 72 33 47 32 37 16 94 29 53 71 44 65 25 43 91 52 97 51 14 70 11 33 28 77 73 17 78 39 68 17 57 91 71 52 38 17 14 91 43 58 50 27 29 48 63 66 04 68 89 53 67 30 73 ... | true |
93f960a97fe5bf653d41707cc5a85b3b839598ce | Ruby | clairesampson/CalculatorLab | /pythag.rb | UTF-8 | 475 | 3.90625 | 4 | [] | no_license | puts "Are you solving for the leg or the hypotenuse?"
choice = gets.chomp
if choice == 'hypotenuse'
puts "Solving for Hypotenuse:"
puts "Length of Leg 1?"
l1 = gets.to_f
puts "Length of Leg 2?"
l2 = gets.to_f
h = (l1**2 +l2**2)**0.5
puts "Hypotenuse:"
puts h
else
puts "Solving for Leg:"
puts "Le... | true |
71aabfaa48ee9de546f9930c13738d79333fa85c | Ruby | angelawenlo/my-select-online-web-prework | /lib/my_select.rb | UTF-8 | 182 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_select(collection)
i = 0
collections = []
while i < collection.length
if yield(collection[i]) == true
collections << collection[i]
end
i += 1
end
collections
end
| true |
01b6a35d632c4d42c4cfb96e3de9052f215a46e5 | Ruby | johnjmarks4/n_queens | /permutations/eight_queens.rb | UTF-8 | 856 | 3.375 | 3 | [] | no_license | require_relative 'board'
require_relative 'queen'
require 'benchmark'
def permutations_strategy
chess = Board.new
queens = []
(0..7).to_a.permutation.to_a.shuffle.each do |ary|
ary.each_with_index do |num, i|
chess.board[i][num] = Queen.new(i, num)
queens << [i, num]
end
if queens.length... | true |
8958cd671584735a95466a5d0477fc7ffbcdac98 | Ruby | JonathanWThom/personal-site | /app/services/github.rb | UTF-8 | 949 | 2.546875 | 3 | [
"MIT"
] | permissive | class Github
def initialize(user)
@user = user
end
### would prefer to not pass in an argument of the user, but that's what allowed me to test for failure condition of api
def top_starred
begin
results = RestClient::Request.execute(method: :get, url: "https://api.github.com/search/repositories?q=... | true |
820d8baae226697d6dd93be9c61c425625c94b32 | Ruby | kanpou0108/launchschool | /lesson_3/easy_2/q08.rb | UTF-8 | 259 | 3.671875 | 4 | [] | no_license |
# In the array:
#
# flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
# Find the index of the first name that starts with "Be"
flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
# p flintstones.index("Be")
p flintstones.index { |flintstone| flintstone[0, 2] == "Be" } | true |
1143ac99b48b8e11473a9af1bbb786fd3412a833 | Ruby | woodfishman/packman | /framework/system/network_manager.rb | UTF-8 | 1,023 | 2.578125 | 3 | [] | no_license | require "socket"
require "timeout"
require "resolv"
module PACKMAN
class NetworkManager
def self.delegated_methods
[:ip, :is_connect_internet?, :is_port_open?]
end
def self.ip
Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
end
def self.is_connect_inte... | true |
6a9815b281fdaef5824778705b1d1ad8a45099e2 | Ruby | DanielYouCan/test-guru | /app/addons/badges_rules.rb | UTF-8 | 956 | 2.78125 | 3 | [] | no_license | class BadgesRules
attr_reader :user, :test_passage
def initialize(user, test_passage)
@user = user
@test_passage = test_passage
end
def level_rule(badge_level)
self.all_in_level?(badge_level)
end
def category_rule(badge_category)
self.all_in_category?(badge_category)
end
def attempt_... | true |
ffd9f53639955c36e1f188bccc3d1e0d77b74c19 | Ruby | sakane133/Has-Many-Through-Template-dc-web-062419 | /lib/actor_movie.rb | UTF-8 | 305 | 2.84375 | 3 | [] | no_license | #class for Model3 goes here
#Feel free to change the name of the class
class ActorMovie
attr_accessor :movie, :actor
@@all = []
def initialize(movie, actor)
@movie = movie
@actor = actor
self.class.all << self
end
def self.all
@@all
end
end
| true |
eae62323b3839a8e826bd8b6674ce00e9cccee1b | Ruby | hbrulin/ft_transcendance | /srcs/app/models/war.rb | UTF-8 | 1,669 | 2.53125 | 3 | [] | no_license | class War < ApplicationRecord
has_many :guild_wars, dependent: :destroy
has_many :guilds, through: :guild_wars, source: :guild, foreign_key: :guild_id
accepts_nested_attributes_for :guilds
has_many :war_times, dependent: :destroy, :validate => false
enum status: [
:pending,
:confirmed,
:started,
:ended,
... | true |
acfc3eaa63020640cc1ada342f370a31a3ed1aba | Ruby | natchkebiailia/getaround_assignment | /backend/test/test_example.rb | UTF-8 | 492 | 2.53125 | 3 | [] | no_license | require 'test/unit'
require '../lib/rental_service.rb'
require './default_config.rb'
class TestExample < Test::Unit::TestCase
def test_discount_calculation
#for 0 days
actual = get_price_multiplier_for(0)
expected = 0
assert_equal expected, actual
#1 day
actual = get_price_multiplier_for(1)
... | true |
2b8348d49ce4ccb5134a1dedc952c7bb105a9910 | Ruby | mmcrockett/MikeReader | /app/models/feed.rb | UTF-8 | 1,483 | 2.609375 | 3 | [] | no_license | require 'rss'
class Feed < ApplicationRecord
has_many :entries
after_save :update_history
def retrieve
response = HTTParty.get(self.url)
if (200 == response.code)
@feed = RSS::Parser.parse(response.body, false)
else
raise "!ERROR: Unable to get '#{self.url}' '#{response}'."
end
... | true |
fccf63117777b4ab78d5cdd92c1e2dd35629a398 | Ruby | le3ah/sweata_weatha | /app/models/hourly_weather.rb | UTF-8 | 302 | 2.9375 | 3 | [] | no_license | class HourlyWeather
attr_reader :hourly_time,
:hourly_temperature,
:hourly_icon
def initialize(attributes)
@hourly_time = Time.at(attributes[:time]).strftime("%l %P")
@hourly_temperature = attributes[:temperature]
@hourly_icon = attributes[:icon]
end
end
| true |
55766347816fd353b2c11cd9de35adb921b643ad | Ruby | BioinformaticsArchive/metriculator | /bin/metriculator | UTF-8 | 2,431 | 2.6875 | 3 | [] | no_license | #!/usr/bin/env ruby
puts "Takes a RAW file, runs metrics on it, and parses the output into the database"
puts "Optionally, it will send an email alert to let you know the data processing has completed"
Rails_ENV = "development" # CHANGE: Change this when deploying
require 'optparse'
options = {}
metriculator_optpa... | true |
01f2b2a3bbf3d3d23e9379763d03b156b298b7ad | Ruby | aleclamson/methods-quiz2 | /methods_quiz2.rb | UTF-8 | 1,069 | 3.46875 | 3 | [] | no_license | module MethodsQuiz2
def without_doubles (num1, num2, no_doubles)
roll?(num1, num2, no_doubles) ? num1 = 1 : num1
no_doubles?(no_doubles) ? (num1 == num2 ? num1 + 1 + num2 : num1 + num2) : num1 + num2
end
def max_maybe (num1, num2)
equal(num1, num2... | true |
c83371623faa4654be95a1234fbc8984c8f20e72 | Ruby | anzaika/insectdb | /lib/result_file.rb | UTF-8 | 628 | 2.515625 | 3 | [] | no_license | require 'hirb'
class ResultFile
def initialize(name)
fname = name + "___" + Time.now.strftime('%s')
path = File.join(Dir.pwd, 'results', fname)
@f = File.open(path, 'w')
end
# Public: write string
def wheader(hash)
# @f << "## " + hash.map{|a| a.join(': ')}.join(", ") + "\n"
@f.write('hell... | true |
ee814cdafb57c3bb4c1ced44d8be87e6f21c67cb | Ruby | Xlaudius/Desafio_Latam_RoR | /Tests/W8_Ruby_test/test.rb | UTF-8 | 1,401 | 3.71875 | 4 | [] | no_license | def menu
puts 'Elija una de las siguientes opciones:'
puts '1. Generar archivo por alumno'
puts '2. Mostrar inasistencias'
puts '3. Mostrar nombres de alumnos aprobados'
puts '4. Salir'
end
def menu_option_1
content = File.open("alumnos.csv", 'r')
content.each_line do |line|
words = line.sp... | true |
b0323aac317a3d934d994f55e530943ef4511735 | Ruby | textmate/manual | /bin/gen_manual | UTF-8 | 6,480 | 2.609375 | 3 | [] | no_license | #!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -wKU
require 'optparse'
require 'fileutils'
require 'shellwords'
PROGRAM_NAME = File.basename(__FILE__)
class GenManual
attr_accessor :extension
def initialize(files)
@extension = true
@index = make_index(files)
end
def make_o... | true |
f70d8399222ff0807a30240766c49657bb4b1061 | Ruby | bachya/cliutils | /lib/cliutils/prefs/pref_validators/filepath_exists_validator.rb | UTF-8 | 434 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'pathname'
module CLIUtils
# A Validator to verify whether a Pref answer
# is a local filepath that exists.
class FilepathExistsValidator < PrefValidator
# Runs the Validator against the answer.
# @param [Object] text The "text" to evaluate
# @return [String]
def validate(text)
@is_... | true |
5f8bb1ca78ec29bcb0e60bdb937e942df2224f3d | Ruby | xavier/exercism-assignments | /ruby/word-count/phrase.rb | UTF-8 | 570 | 3.453125 | 3 | [] | no_license | class Phrase
def initialize(string)
@string = string
end
def word_count
OccurrenceCounter.for(normalized_words).to_hash
end
private
WORDS = /\w+/
def normalized_words
normalized_string.scan(WORDS)
end
def normalized_string
@string.downcase
end
end
class OccurrenceCounter
d... | true |
bc524ec89879ea1e1c781ef6f3690957916a027e | Ruby | ragaskar/alloallo-web | /spec/support/fake_allocations_client.rb | UTF-8 | 1,154 | 2.625 | 3 | [] | no_license | class FakeAllocationsClient
def initialize(fake_allocations)
@fake_allocations = fake_allocations
end
def get(endpoint, params = {})
function_to_call, arguments = endpoint_map(endpoint)
raise ArgumentError.new("Unknown Endpoint #{endpoint}") unless function_to_call
JSON.parse(send(function_to_ca... | true |
7372a5a463bd0525aa7c2edd74089e5492c38c8e | Ruby | jdegrand/AdventOfCode | /2017/Day8/8.rb | UTF-8 | 779 | 3.171875 | 3 | [] | no_license | file = 'input.txt'
input = File.read(file)
$lines = input.lines.map(&:chomp)
def day8_1
registers = Hash.new(0)
$lines.each do |l|
target_reg, op, val, _, cond_reg, cond_op, cond = l.split
if eval("#{registers[cond_reg]} #{cond_op} #{cond}")
registers[target_reg] += op == "inc" ? v... | true |
4deb5d76b88d142f3ce356c038efdb15f5ef4f39 | Ruby | anibelamerica/hotel | /lib/block.rb | UTF-8 | 1,641 | 3.0625 | 3 | [] | no_license | module Hotel
class Block
attr_reader :date_range, :blocked_rooms, :discounted_rate, :block_reservations, :block_id
def initialize(date_range, blocked_rooms, discounted_rate, block_id, block_reservations: [])
@date_range = date_range
@blocked_rooms = blocked_rooms
@discounted_rate = discou... | true |
67bfa711c92f1ead118dcd255248eedce5164447 | Ruby | Duncan-Marjoribanks/relationships-between-databases-cinema-modelling-exercise | /models/ticket.rb | UTF-8 | 1,100 | 3.109375 | 3 | [] | no_license | require_relative("../db/sql_runner")
require_relative("customer")
require_relative("film")
class Ticket
attr_accessor :customer_id, :film_id
attr_reader :id
def initialize(options)
@customer_id = options["customer_id"].to_i
@film_id = options["film_id"].to_i
@id = options["id"].to_i if options["id"]
end
def s... | true |
f7ced91e946751739d84ddcb737f424b6777b97d | Ruby | gunnarrunner/backend_mod_1_prework | /section2/exercises/else_and_if_ex2.rb | UTF-8 | 1,646 | 4.34375 | 4 | [] | no_license | # original value of 30
people = 20
# original value of 40
cars = 30
# original value of 15
trucks = 50
# elsif and else are saying the the same thing as if statement. If the statement holds true for that line then it will print out this line instead.
if cars > people
# outputs if true
puts "We should take the car... | true |
7954f8efd73ce0ed1e544897388761ab6161f089 | Ruby | pforpineapple-zz/LRTHW | /20-29/ex20_more.rb | UTF-8 | 177 | 3.390625 | 3 | [] | no_license | input = ARGV.first
# def print_all(f)
# puts f.read
# end
# opened_file = open(input)
# puts "This is the whole file: \n"
# print_all(opened_file)
puts open(input).seek(1) | true |
1342e8881202d4eb0157ee986357f2ef176a8b19 | Ruby | trustarun/crossover-ticketing | /app/pdfs/report_pdf.rb | UTF-8 | 1,572 | 2.796875 | 3 | [] | no_license | class ReportPdf < Prawn::Document
def initialize(tickets)
super()
@tickets = tickets
header
text_content
table_content
end
def header
# This inserts an image in the pdf file and sets the size of the image
image "#{Rails.root}/app/assets/images/crossover-headr.png", width: 530, height:... | true |
dd1e50b1c6fc4c9d5a4dd12167164c989a8915bd | Ruby | mdperry/encode-db-dump | /sideways_dump/make_table.rb | UTF-8 | 4,611 | 2.78125 | 3 | [] | no_license | #!/usr/bin/ruby
require File.join(File.dirname(__FILE__), 'table_helper')
# Transforms the modencode chado database into a format useful for encode3.
# Input:
# Location of output directory from dump_from_db.rb
# base path for outputs from get-headings.rb
# Output
# Tab separarated charts with headings providi... | true |
8f033c8cfb27cbaf77bb94bd5a2a3292298032d9 | Ruby | PizzaPowered/resque-picky_worker | /example.rb | UTF-8 | 597 | 2.59375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
$:.unshift File.expand_path("lib", File.dirname(__FILE__))
require "resque/picky_worker/override"
# Try not to trample on other things in redis
Resque.redis.namespace = "example:pickyworker"
# Make sure we've got some queues to choose from
Resque.redis.d... | true |
31a94a19c1a0cde7df1cc976ce05a1daa6ed6df7 | Ruby | hunaba/THP-exercice-ruby- | /exo_04.rb | UTF-8 | 79 | 2.78125 | 3 | [] | no_license | #il faut fermer avec guillemet sinon Γ§a marche pas
puts "Salut, ca farte ?
| true |
e6d29404717baab011398b436f43e947234f4e79 | Ruby | papss/Yet-Another-Deck-Builder | /lib/scryfall.rb | UTF-8 | 1,224 | 2.734375 | 3 | [] | no_license | require 'httparty'
class Scryfall
include HTTParty
format :json
base_uri 'api.scryfall.com'
# initialize attributes:
attr_accessor :id, :arena_id, :name, :set, :rarity, :colors, :mana_cost, :power,
:toughness, :legalities, :scryfall_uri, :image_uris, :card_type,
:card_text
... | true |
4ac64b8638738104ba5639fcbbcc5daeab638770 | Ruby | aml7733/cartoon-collections-v-000 | /cartoon_collections.rb | UTF-8 | 469 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def roll_call_dwarves(array)
array.each_with_index { |name, index| puts "#{index + 1}. #{name}"}
end
def summon_captain_planet(array)
array.collect { |call|
call[0] = call[0].upcase
call += "!"
}
end
def long_planeteer_calls(array)
array.each { |call| return true if call.length > 4}
false
end
def f... | true |
cabbbb64ead6fe95fd2f096d4f652de2d16d4af3 | Ruby | iaddict/mercurial.rb | /lib/mercurial/popen.rb | UTF-8 | 6,541 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'json'
require 'base64'
require 'timeout'
require 'posix/spawn'
# Error class
class MercurialError < IOError
end
module Mercurial
module Popen
include POSIX::Spawn
extend self
# Get things started by opening a pipe to hg_run, a Python process that
# talks to the Mercurial library. We'll... | true |
e8ec9cbbd0b7c2d58f25036596559e1f03058f3c | Ruby | pfarrell/buster | /lib/buster/connection.rb | UTF-8 | 138 | 2.546875 | 3 | [
"MIT"
] | permissive | class Connection
attr_accessor :conn, :pattern
def initialize(conn, opt={})
@conn = conn
@pattern = opt[:pattern]
end
end
| true |
8af8a7b82fc4947fbf909f9b062b72840e439656 | Ruby | MatthewJohn/typesense-website | /typesense.org/_plugins/code_block.rb | UTF-8 | 2,137 | 2.5625 | 3 | [] | no_license | module Jekyll
class CodeBlock < Liquid::Block
def initialize(tag_name, label, tokens)
@label = label.strip
super
end
def render(context)
content = super
blocks = content.split(/```$/)[0...-1]
num_blocks = blocks.length
output = "<ul class=\"nav nav-tabs mb-#{num_block... | true |
c6fc749819f7927dd7093cf5cd5f1c0ffe5dd4ee | Ruby | doctordeep/arachni | /spec/arachni/component/options/float_spec.rb | UTF-8 | 1,193 | 2.515625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'spec_helper'
describe Arachni::Component::Options::Float do
before( :all ) do
@opt = Arachni::Component::Options::Float.new( '' )
end
describe '#valid?' do
context 'when the value is valid' do
it 'returns true' do
@opt.valid?( '1' ).should be_true
... | true |
6fb89c3aff40df8951c94a4206cfb327023f8e15 | Ruby | webmonarch/aws-utilities | /test/summarize-ec2-spot-instance-history/run.rb | UTF-8 | 1,169 | 2.765625 | 3 | [] | no_license | # Simple test runner
require_relative '../utils'
require 'pathname'
Dir.chdir(File.dirname(__FILE__))
script = "../../scripts/summarize-ec2-spot-instance-history.rb"
parameters_prefix = '# Parameters: '
expected_prefix = '# Expected: '
Dir.glob("**/*.txt") do |test_input| # note one extra "*"
headings = File.rea... | true |
11090774a80196f457a0a05e3b720ae839db1c2a | Ruby | andrewebert/gensou | /lib/data.rb | UTF-8 | 230 | 2.75 | 3 | [] | no_license | require 'json'
class DataGrabber
def get(file)
JSON.parse(File.read("public/json/#{file}.json"))
end
def extract(file, keys)
data = get(file)
data.select {|key| keys.include? key}
end
end
| true |
e056842eb95550c0a874fb1dc2fa9b614e34156a | Ruby | choroba/perlweeklychallenge-club | /challenge-226/roger-bell-west/ruby/ch-1.rb | UTF-8 | 412 | 3.1875 | 3 | [] | no_license | #! /usr/bin/ruby
def shufflestring(st, mp)
r = " " * st.length
mp.each do |i|
r[mp[i]] = st[i]
end
return r
end
require 'test/unit'
class TestShufflestring < Test::Unit::TestCase
def test_ex1
assert_equal('challenge', shufflestring('lacelengh', [3, 2, 0, 5, 4, 8, 6, 7, 1]))
end
def test_ex2
... | true |
8d87b8e0011d00f3ca691532f4d44fdd851a16bf | Ruby | Nossonhuebner/chess | /chess/board.rb | UTF-8 | 2,840 | 3.359375 | 3 | [] | no_license | require_relative "piece.rb"
require_relative "display.rb"
require_relative "rook.rb"
require_relative "bishop.rb"
require_relative "king.rb"
require_relative "knight.rb"
require_relative "nullpiece.rb"
require_relative "pawn.rb"
require_relative "queen.rb"
require 'byebug'
class NoPieceError < StandardError ; end
cla... | true |
b3b04bf87e7536a6695ae2a5884e798c66ae8cc4 | Ruby | xathin/learn_ruby | /02_calculator/calculator.rb | UTF-8 | 162 | 3.515625 | 4 | [] | no_license | def add(a, b)
return a + b
end
def subtract(a, b)
return a - b
end
def sum(numbers)
total = 0
numbers.each { |x| total = total + x }
return total
end
| true |
ff824bc1d402760afa2b201d70003f68d18c35ed | Ruby | mindreframer/datastructures-algorithms-stuff | /github.com/mindreframer/source-concise-notes-ruby/Containers/List.rb | UTF-8 | 1,507 | 3.375 | 3 | [] | no_license | #
# This is the interface for all Lists
#
# Author: C. Fox
# Version: July 2011
require_relative "Collection"
class List < Collection
# Insert the indicated element at the indicated location
# @pre: -size <= index
# @post: size = (-old.size <= index < old.size) ? old.size+1 : index-old.size+1
# @result: s... | true |
047c87e8de438bcc70a89842737bde6411571a96 | Ruby | IronLanguages/rubyspec | /1.8/core/array/fixtures/classes.rb | UTF-8 | 891 | 3.125 | 3 | [
"MIT"
] | permissive | module ArraySpecs
def self.frozen_array
@frozen_array ||= [1,2,3]
@frozen_array.freeze
@frozen_array
end
def self.recursive_array
a = [1, 'two', 3.0]
5.times { a << a }
a
end
def self.head_recursive_array
a = []
5.times { a << a }
a << 1 << 'two' << 3.0
a
end
de... | true |
a5907b75c26f0b4c7741bde425dfce205022cc3a | Ruby | ptolemybarnes/ma-wk3-rps-online | /spec/rps-rounds.bkend_spec.rb | UTF-8 | 2,353 | 2.9375 | 3 | [] | no_license | require 'rps-rounds.bkend'
require 'rps.bkend'
describe RockPaperScissorRounds do
let(:rpsrounds) { RockPaperScissorRounds.new(["tom", "bob"]) }
let(:rps) { RockPaperScissor.new }
context 'the game can keep score' do
it 'can keep score' do
expect(rpsrounds.score).to eq({"tom" => 0, "bob" => 0})
... | true |
e661bfc01d07241d29c94a9e63e8cda66a57af75 | Ruby | LifeInDena/Ruby | /wiz.rb | UTF-8 | 1,375 | 3.359375 | 3 | [] | no_license | class Human
attr_accessor :health
attr_reader :intelligence
attr_reader :strength
attr_reader :stealth
def initialize
@health = 100
@stealth = 3
@intelligence = 3
@strength = 3
end
def info
puts "My Health: #{@health}"
puts "My Intelli... | true |
c50c466d20c7cb547b59653bf5b49d67277ba79e | Ruby | colinrubbert/course_work | /remove_dups.rb | UTF-8 | 223 | 3.5625 | 4 | [] | no_license | def unique(integers)
@unique = integers
sorted = []
@unique.each do |u|
if sorted.include?(u)
else
sorted << u
end
end
puts "#{sorted}"
end
unique([1, 5, 2, 0, 2, -3, -3, 1, 10])
| true |
b5aa2e3d5a4726adadc5a3f7ec25d0123ac72b20 | Ruby | ejatkin/student-directory | /directory2.rb | UTF-8 | 3,011 | 4.4375 | 4 | [] | no_license | def interactive_menu
students = []
loop do
# 1. print the menu and ask the user what to do
puts "1. Input the students"
puts "2. Show the students"
puts "9. Exit" # 9 because we'll be adding more items
# 2. read the input and save it into a variable
selection = gets.chomp
# 3. do what the user... | true |
7032c355b33859ba2c43b8c327e584eb3a09b4fa | Ruby | Peeja/abstraction | /lib/abstraction.rb | UTF-8 | 628 | 2.828125 | 3 | [] | no_license | class AbstractClassError < StandardError; end
class Class
def abstract
@abstraction_abstract_class = true
self.extend Module.new {
def new(*args, &block)
if @abstraction_abstract_class
raise AbstractClassError, "#{self} is an abstract class and cannot be instantiated"
else
... | true |
acf7c97b1f1a20a3fb3d14ee0de8840ad4463b6a | Ruby | lucascheung/adventofcode2018 | /day3/day3.rb | UTF-8 | 911 | 3.15625 | 3 | [] | no_license | a = {}
File.open('day3.input').each_line do |line|
num = line.split(/\W/)
a[num[1].to_i] = [num[4].to_i, num[5].to_i, num[7].split('x')[0].to_i, num[7].split('x')[1].to_i]
end
matrix = Hash.new(0)
#part 1
a.each do |_key, value|
(1..value[2]).each do |width|
(1..value[3]).each do |height|
matrix[value... | true |
f6f078607d2b72ce5477675bb422204642475aa7 | Ruby | kamater/wepark | /app/helpers/application_helper.rb | UTF-8 | 244 | 2.703125 | 3 | [] | no_license | module ApplicationHelper
def average(garage)
all_rating = []
garage.reviews.each do |review|
all_rating << review.rating
end
sum = all_rating.sum
all_rating.count == 0 ? 0 : (sum / all_rating.count).round
end
end
| true |
d96cb5c4f7a251feac121fbacdd2c3bc72c9d630 | Ruby | wcomfort/module-one-final-project-guidelines-dc-web-091619 | /app/models/doctor.rb | UTF-8 | 3,360 | 3.296875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class Doctor < ActiveRecord::Base
has_many :reviews
def self.doctors_specialties
arr = Doctor.all.map(&:specialty).uniq
array = arr.map{|spe| spe.downcase}
array
end
def self.sort_by_specialty(specialty_input)
docs = []
Doctor.all.each do |docto... | true |
a1203c51d7b2de5e1a93888289d423b38e38a12b | Ruby | TomPoulton/gchq-puzzle-1 | /bin/un_puzzle.rb | UTF-8 | 509 | 2.8125 | 3 | [] | no_license | require 'YAML'
require_relative '../lib/puzzle/grid'
require_relative '../lib/puzzle/solver'
puts 'Creating grid ...'
debug = false
puzzle = YAML.load_file File.expand_path('../../puzzle.yml', __FILE__)
row_patterns = puzzle['row-patterns']
column_patterns = puzzle['column-patterns']
filled_cells = puzzle['filled-cel... | true |
abdcf54530954e6c8f68242bdcab1efd7aad8a30 | Ruby | njonsson/trapeze | /lib/trapeze/literals.rb | UTF-8 | 2,834 | 3.28125 | 3 | [
"MIT"
] | permissive | # Defines Trapeze::Literals.
require File.expand_path("#{File.dirname __FILE__}/string_matcher")
# Converts objects into their Ruby-literal representations.
class Trapeze::Literals
# Returns a singleton instance of Trapeze::Literals with literal
# representations for known classes.
def self.built_in
unle... | true |
2ea3d88fa4d4400cc5fd8d3e9f4ad5482867892b | Ruby | step21/dashpi | /src/jobs/weather.rb | UTF-8 | 3,036 | 2.71875 | 3 | [] | no_license | # encoding: utf-8
require 'net/http'
require 'xmlsimple'
require 'time'
require 'date'
SCHEDULER.every '1h', first_in: 0 do |_job|
response = Net::HTTP.get('www.yr.no', '/place/Germany/North_Rhine-Westphalia/Wuppertal/forecast_hour_by_hour.xml')
xml = XmlSimple.xml_in(response)
location = xml['location'][... | true |
ed0dbb889647d501fd066318b4dac950c05fa7d1 | Ruby | vogelbek/RubyFall2013 | /week2/exercises/mad_libs.rb | UTF-8 | 201 | 3.796875 | 4 | [
"Apache-2.0"
] | permissive | animals = []
sounds = []
puts "Name an animal"
animals.push gets.chomp
puts "What sound does it make?"
sounds.push gets.chomp
puts "The #{animals[0]} goes #{sounds[0]}. But what does the fox say???" | true |
66bfea1ebc7887cbb9bc4665386f1a7aab38ce60 | Ruby | cnxtech/olubalance | /app/models/account.rb | UTF-8 | 964 | 2.53125 | 3 | [
"MIT"
] | permissive | # An account which will store many transactions and belongs to one user
class Account < ApplicationRecord
# Define Constants
NO_ACCOUNT_DESC = "It looks like you don't have any accounts added. To add an account, \
click the add account button at the top of the page :)".freeze
NO_INACTIVE_DES... | true |
2de2654e04220872b6254032b3fa4d737ada4ceb | Ruby | saravanan12153/CD_ruby_oop_misc_assignments | /iterators.rb | UTF-8 | 2,239 | 4.5625 | 5 | [] | no_license | # .any? Returns boolean. Passes each element of the collection to the given block. The method returns true if the block ever returns a value other than false or nil. It goes through your values and evaluates a boolean if the values contained meet a criteria.
puts ["ant", "bear", "cat"].any? {|word| word.length >= 3}
... | true |
54068a2ec1ed0cc6fec3df9049b6cd1150c7f5c3 | Ruby | TylerBrock/books | /Agile Web Development with Rails/work/depot/rake/ruby/1.9.1/gems/activerecord-3.0.10/lib/active_record/relation/predicate_builder.rb | UTF-8 | 1,309 | 2.59375 | 3 | [
"MIT"
] | permissive | module ActiveRecord
class PredicateBuilder
def initialize(engine)
@engine = engine
end
def build_from_hash(attributes, default_table)
predicates = attributes.map do |column, value|
table = default_table
if value.is_a?(Hash)
table = Arel::Table.new(column, :engine =... | true |
2d5abae1bdccdbcc897753c548f6ae2dfca83bc4 | Ruby | gotascii/crags | /lib/crags/category.rb | UTF-8 | 512 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Crags
class Category
extend Fetcher
attr_reader :name, :url
def initialize(name, abbr)
@name = name
@url = "/#{abbr}"
end
def self.doc
fetch_doc(Config.category_url)
end
def self.links
doc.search("div.col a").select do |link|
(link["href"] =~ /foru... | true |
cadfce2a973eefdc8cd16670cb5d36e1903cfead | Ruby | myExperiment/myExperiment | /config/initializers/nitems.rb | UTF-8 | 229 | 2.78125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause",
"MIT"
] | permissive | # Some gems use Array#nitems which isn't in Ruby 1.9 so I need this:
# From http://stackoverflow.com/a/8205275/509839
if ! Array.method_defined?(:nitems)
class Array
def nitems
count{|x| !x.nil?}
end
end
end
| true |
65a6a08452a182381ebd3a379f1f0a916d785482 | Ruby | BlueColorPencils/mood-analysis | /mood-analysis.rb | UTF-8 | 1,688 | 4.25 | 4 | [] | no_license | FEELINGS = {
happy: %w(yay good great),
sad: %w(terrible awful horrible)
}
def analyze_mood(words)
happy = 0
sad = 0
words.downcase!
# nopunc = words.delete("!.,#")
nopunc = strip_punctuation(words)
nopunc.split(" ").each do |word|
if FEELINGS[:happy].include? word
happy += 1
elsif FEELIN... | true |
1b92925364499d3f232efa0058adeff15c6e1909 | Ruby | jmaeda/elevator | /person.rb | UTF-8 | 166 | 3.21875 | 3 | [] | no_license | class Person
attr_reader :intended_floor
def initialize(floor)
@intended_floor = floor
end
def get_intended_floor
return intended_floor
end
end | true |
96f821cb68f52dab019cfc0f11b95700cbb08634 | Ruby | Brazenbillygoat/playlist-maker-cli-app | /app/models/song.rb | UTF-8 | 322 | 2.734375 | 3 | [] | no_license | require_relative '../../config/environment.rb'
class Song < ActiveRecord::Base
has_many :songplaylists
has_many :playlists, through: :songplaylists
end
def display_all_songs
puts "\nSong Choices:"
Song.all.each do |song|
puts "#{song.id} #{song.name} - #{song.artist}"
end
end
... | true |
65a53c7e2523bbe117f08caa29e2d850e7337c26 | Ruby | Markhenn/LS-RB101 | /Exercises/Easy 8/ex10.rb | UTF-8 | 642 | 4.375 | 4 | [] | no_license | # Get The Middle Character
# Problem
# input: string
# output: string
# method returns the middle character/s
# for odd strings 1
# for even strings 2
# Data Structure / Algorithm
# if size odd
# return string at position half size
# else
# return string at poistion half size -1 to half size
def center_of(text)
... | true |
687c76589dc31b423d2abd99b612681aefe34add | Ruby | manu9812/codum-academy | /codingChallenge/Command.rb | UTF-8 | 749 | 3.109375 | 3 | [] | no_license | class Command
attr_reader :commandType, :row_size, :column_size, :x, :y, :color, :x1, :y1, :x2, :y2
def initialize instructionArray:
@commandType = instructionArrangement[0]
if instructionArrangement.size == 3
@row_size = instructionArrangement[2].to_i
@column_size = instructionArrangem... | true |
df77e5efd7ba5ba6f8a58ef3cf63aa6afb8e64db | Ruby | Krafalski/GA-NYC-Bowie | /w10/d04/classwork/linked.rb | UTF-8 | 1,330 | 3.375 | 3 | [
"MIT"
] | permissive | class Stack
attr_accessor :stack
attr_reader :length
def initialize
@stack = []
end
def push (something)
@stack = @stack.push (something)
end
def pop
@stack.pop
end
def isEmpty?
#if @stack == []
#puts "this stack is empty"
@stack.empty?
end
end
def size
@le... | true |
7ebf54445445680a1f7c273bb415ece2350af1ae | Ruby | hlxwell/leetcode-ruby | /zigzag.rb | UTF-8 | 1,403 | 3.265625 | 3 | [] | no_license | require "benchmark"
### O(n^2)
# def convert(s, num_rows)
# return s if num_rows == 1
# result = ""
# matrix = []
# str_arr = s.split ''
# row_index = 0
# unit_size = num_rows - 1
# while str_arr.size > 0
# matrix << Array.new(num_rows, nil)
# unit_row_index = row_index % unit_size
# (num_row... | true |
70caf7044f45959c44c02f150eb95bed3a3daf38 | Ruby | LisaHJung/programming-univbasics-4-square-array-denver-web-033020 | /lib/square_array.rb | UTF-8 | 133 | 3.1875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
i=0
newarray = [ ]
while i<array.length do
newarray.push(array[i]**2)
i+=1
end
newarray
end | true |
47a44bbefdccac03b619f1e0c52cba8648b4a223 | Ruby | Lo1176/rails-mister-cocktail | /db/seeds.rb | UTF-8 | 384 | 2.59375 | 3 | [] | no_license | # frozen_string_literal: true
require 'open-uri'
# require 'json'
puts 'deleting ingredients ...'
Ingredient.delete_all
puts 'creating ingredients ...'
url = 'https://www.thecocktaildb.com/api/json/v1/1/list.php?i=list'
ingredients = JSON.parse(open(url).read)
ingredients['drinks'].each do |ingredient|
Ingredient.... | true |
1c23052c8354a13e18a36bb03d02f50ea8ab3c96 | Ruby | personinma/pa3 | /maze.rb | UTF-8 | 3,144 | 4.03125 | 4 | [] | no_license | # Author: Steven Hu
# Maze class for PA03. Breaks a maze string out into a
# maze of n * m size. Maze can check for solution from a
# starting (x,y) coordinate to an ending (x,y) coordinate
require_relative 'node'
class Maze
attr_reader :maze, :temp
def initialize(n, m)
@wall_row = (n*2) + 1
@wall_col = (m*2... | true |
06b764eb0a593aed4bf446e0bad03b74ab39d6cd | Ruby | leonardogbxv/hello-ruby | /syntax/unless.rb | UTF-8 | 169 | 2.890625 | 3 | [] | no_license | book_status = 'not reading'
unless book_status == 'reading'
check_book = 'can'
else
check_book = "can't"
end
puts "Now you #{check_book} return the books to me..." | true |
6447829faa57f2858e2f02328972f19c7e5b41c7 | Ruby | bjeanes/TVRenamer | /NSObject_ext.rb | UTF-8 | 269 | 2.546875 | 3 | [] | no_license | # NSObject_ext.rb
# TVRenamer
#
# Created by Bodaniel Jeanes on 5/02/10.
# Copyright 2010 Bodaniel Jeanes. All rights reserved.
class NSObject
def returning(value, &block)
block.call(value)
value
end
def blank?
nil? || self == ""
end
alias with returning
end | true |
5fd769e04fb8a5592f4e54ef6b26d841ba212cdb | Ruby | marksands/mapreduce | /lib/classes/word_counter.rb | UTF-8 | 144 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | class WordCounter < MapReduce::Mapper
def self.map(map_data)
map_data.split.map do |word|
yield(word.downcase, 1)
end
end
end
| true |
aa6c6fa13e84e8c896e44f5a23cbc0c8883cbd9d | Ruby | nickdesaulniers/metaprogramming_ruby | /class_extension_mixin.rb | UTF-8 | 469 | 3.390625 | 3 | [] | no_license | # Class Extension Mixin
# Enable a module to extend its includer through a Hook Method.
module M
module ClassMethods
def my_method
'a class method'
end
end
module InstanceMethods
def my_method
'an instance method'
end
end
def self.included base
base.extend ClassMethods
ba... | true |
cf6d0d2ad0163f1bcab31f28353fec60279b1cc8 | Ruby | souljuse/Tic-Tac-Toe | /lib/player.rb | UTF-8 | 225 | 3.109375 | 3 | [] | no_license | class Player
attr_reader :name
def initialize (player_name, weapon = 'x')
@name = player_name
@weapon = weapon
end
attr_reader :weapon
def move(game, place)
game.insert_move(place, @weapon)
end
end
| true |
87d405f6a01cee605a41f4cbf8e47d2b46b2534b | Ruby | piotr-galas/play-with-ruby | /arrays/convert_elements.rb | UTF-8 | 284 | 2.671875 | 3 | [] | no_license | require './helper'
@alphabet = ['a','b','c','d', 'e']
print_to_console(@alphabet.reverse, 'alphabet.reverse')
print_to_console(@alphabet.reverse!, 'alphabet.reverse!')
print_to_console(@alphabet.shuffle, 'alphabet.shuffle')
print_to_console(@alphabet.shuffle!, 'alphabet.shuffle!') | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.