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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ad34778728c055470eb5e389531d9dee6bd289ad | Ruby | AbbiAld/anagram | /app/controllers/index_controller.rb | UTF-8 | 530 | 3.140625 | 3 | [] | no_license | get '/' do
erb :index
end
post '/' do
@word = params[:word]
def empty_input?(input)
if input.empty?
raise Exception.new("Oops! Looks like your didn't enter a word. Please enter a word!")
end
end
begin
!empty_input?(@word)
redirect "/anagrams/#{@word}"
rescue Exception => error
@error = error.messa... | true |
268a05d69479dd2d102bd3cadc5e3ac58c4e7db7 | Ruby | Zhao-Andy/shine | /db/seeds.rb | UTF-8 | 1,638 | 2.75 | 3 | [] | no_license | # Helper method to create a billing address for a customer
def create_billing_address(customer_id,state)
billing_address = Address.create!(
street: Faker::Address.street_address,
city: Faker::Address.city,
state: state,
zipcode: Faker::Address.zip
)
CustomersBillingAddress.create!(customer_... | true |
8ca92bcb1fcb5c1e23f26d53ea14346393a83c9d | Ruby | atlochowski/git_test | /Odin_ruby/caesar.rb | UTF-8 | 342 | 3.765625 | 4 | [] | no_license | def cipher(strings, num)
arr = []
strings.each_char { |n| arr << n.ord}
arr.each do |n|
if (97..122).include?(n)
n > 122 - num ? n = 96 + (num - (122 - n)) : n += num
elsif (60..90).include?(n)
n > 90 - num ? n = 64 + (num - (90 - n)) : n += num
else
n
end
letter = n.chr
print letter
end
end
cipher... | true |
39f02216e7959f9bc9f5004618cdcbfab569744c | Ruby | snoremac/buildlight | /lib/drivers/delcom_904008.rb | UTF-8 | 1,428 | 2.71875 | 3 | [] | no_license | require 'usb'
class Light
VENDOR_ID = 0x0fc5
PRODUCT_ID = 0xb080
INTERFACE_ID = 0
OFF = "\x00"
GREEN = "\x01"
RED = "\x02"
YELLOW = "\x04"
def initialize
@device = USB.devices.find {|device| device.idVendor == VENDOR_ID && device.idProduct == PRODUCT_ID}
raise "Unable to... | true |
9554b8b2bd7397e7d2e16fe3e1ffa98a5081cabc | Ruby | jimjh/genie-tangle | /lib/tangle/tty.rb | UTF-8 | 2,192 | 2.8125 | 3 | [] | no_license | require 'thread'
require 'active_support/core_ext/class/attribute'
require 'tangle/ssh'
module Tangle
# This class is designed to be thread-safe tty factory. During
# initialization, the success of the connection is unknown; however, on
# failure, the dead terminal is removed from the +TTY.terms+ array.
class... | true |
5eeda72f5c9cb0b2759e162bd91507b5e75adcbf | Ruby | johanneswuerbach/dynamodb-stream-enumerator | /lib/dynamodb/stream/enumerator/shard_reader.rb | UTF-8 | 759 | 2.546875 | 3 | [
"MIT"
] | permissive | require "dynamodb/stream/enumerator/version"
require "aws-sdk-dynamodbstreams"
module Dynamodb
module Stream
class Enumerator < ::Enumerator
class ShardReader
def initialize(client, shard_iterator)
@client = client
@shard_iterator = shard_iterator
end
def finish... | true |
03cd1ae56849762770e747a88fff91b90b1d051a | Ruby | uten0906/myself | /spec/models/user_spec.rb | UTF-8 | 2,874 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
describe "nameのバリデーション確認" do
context "半角英数字ではバリデーションされる" do
it "1文字目は半角文字、2文字以降半角英数字である" do
expect(@user).to be_valid
end
it "1文字目が数字である" do
@user.name = "0test"
... | true |
e3be30a5bbd83f068bc3d8972441f295024d0a9a | Ruby | Kphillycat/todos | /todo8/deli_spec.rb | UTF-8 | 560 | 3.265625 | 3 | [] | no_license | require './deli'
describe Deli, "#take_a_number" do
my_deli = Deli.new
it "should take customer's name and return array with their number and name" do
expect(my_deli.take_a_number("KDizzle")).to eq(["1. KDizzle"])
end
end
describe Deli, "#now_serving" do
my_deli = Deli.new
my_deli.line = ["1. KDizzle",... | true |
e581b1d2ac4a9d287fd4f41c5dce76a4f1fb2f9f | Ruby | Dofassh/airplane-challenge-2 | /airport.rb | UTF-8 | 845 | 3.8125 | 4 | [] | no_license | require 'weather'
class Airport
DEFAULT_CAPACITY = 30
def initialize(weather, capacity = DEFAULT_CAPACITY)
@weather = weather
@capacity = capacity
@planes = []
end
def land(plane)
raise 'Capacity is full : Cannot land plane' if capacity_full
raise 'Weather is stormy :... | true |
1dabb7732aa79472434dda05aa74109b172e1ef6 | Ruby | nomlab/swimmy | /lib/swimmy/service/pollen_service.rb | UTF-8 | 1,199 | 2.71875 | 3 | [
"MIT"
] | permissive | # coding: utf-8
require 'date'
require 'csv'
require 'net/http'
module Swimmy
module Service
class Pollen
class CityCodeException < StandardError; end
class PollenException < StandardError; end
def fetch_info(address, date)
begin
city_code = Service::CityCode.new.address_to... | true |
ba65b4dd75d37a3bfe67d0551360144bc5814a40 | Ruby | Streetbees/home_network_identity | /test/test_home_network_identity.rb | UTF-8 | 2,114 | 2.578125 | 3 | [] | no_license | require 'minitest/autorun'
require 'home_network_identity'
class HomeNetworkIdentityTest < Minitest::Test
def test_country
plmn = 60301
home_network_identity = HomeNetworkIdentity.new(plmn: plmn)
assert_equal "Algeria", home_network_identity.country
end
def test_iso_country_code_GG
plmn = 23403
... | true |
efa6d65a226c149b3070bf1d211a7071480ce4ef | Ruby | christopheleray/learn_ruby_rspec | /02_calculator/calculator.rb | UTF-8 | 226 | 3.484375 | 3 | [] | no_license | def add(x, y)
return x + y
end
def subtract(x, y)
return x - y
end
def sum(x)
return x.sum
end
def multiply(x, y)
return x * y
end
def power(x, y)
return x ** y
end
def factorial(x)
(1..x).reduce(:*) || 1
end
| true |
3112ab5b37f1bc43a0c344ad8966a9f63da4054f | Ruby | bfoz/sketch | /test/sketch/builder/repeat.rb | UTF-8 | 1,195 | 2.765625 | 3 | [
"BSD-3-Clause"
] | permissive | require 'minitest/autorun'
require 'sketch/builder/repeat'
describe Sketch::Builder::Repeat do
subject { Sketch::Builder::Repeat.new([0,0]) }
it 'must simply repeat' do
subject.build([0,4], 4) do |step|
forward step
end.must_equal [[0,1], [0,2], [0,3], [0,4]].map {|a| Point[a] }
end
it 'must e... | true |
326fe73dd00366952fb17af10a5e5c7753e14e29 | Ruby | lizwilkins/go_fish_with_Thomas | /lib/game.rb | UTF-8 | 142 | 2.609375 | 3 | [] | no_license | class Game
def initialize
end
def over?
draw_pool.
players.each do |player| player.hand.length
draw_pool.
end
end
end | true |
9b5d919bc66f375733d86b691843bb32f9008035 | Ruby | e46and2/square_array-v-000 | /square_array.rb | UTF-8 | 109 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
array_squared = []
array.each { |i| array_squared << i ** 2 }
array_squared
end | true |
f86f93c9ecfaf15f72fd8dfb58883985a28aa9c7 | Ruby | bwanicur/nattysearch | /app/services/petfinder_service/queries/organization.rb | UTF-8 | 366 | 2.5625 | 3 | [] | no_license | module PetfinderService
module Queries
class Organization
def initialize(pf_client, pf_org_id)
@client = pf_client
@org_id = pf_org_id
raise PetfinderService::Queries::Error.new('Petfinder Shelter ID is required') unless @org_id.present?
end
def run
@client.sh... | true |
080aee12116228449e2a5ee2c051ac620dd9f9c5 | Ruby | AugustGiles/onitama-project-3-backend | /db/seeds.rb | UTF-8 | 5,964 | 2.921875 | 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 |
594ae40affbede1b4b1c2454bab73922251bea1c | Ruby | Patmando73/API_Project | /database_instance_methods.rb | UTF-8 | 2,255 | 3.4375 | 3 | [] | no_license | require "active_support"
require "active_support/inflector"
module DatabaseInstanceMethods
# Get the value of a field for a given row.
#
# field - String of the column name.
#
# Returns the String value of the cell in the table.
def get(field)
table_name = self.class.to_s.pluralize.underscore
re... | true |
c06ab9e3c4a16b56085719ebba274f229af954e9 | Ruby | RobinvdGriend/hangman | /lib/hangman/ai.rb | UTF-8 | 355 | 2.640625 | 3 | [
"MIT"
] | permissive | module Hangman
module AI
DICTIONARY_PATH = "lib/hangman/ai/dictionary.txt"
def self.generate_from_dictionary
line_count = %x{wc -l #{DICTIONARY_PATH}}.split.first.to_i
random_line = rand(line_count)
File.open(DICTIONARY_PATH) do |f|
(random_line - 1).times { f.gets }
f.gets.... | true |
746d55f1f58c33b8b588377ab9e28ad776e4fb76 | Ruby | RubyDaRosess/RuBY-Week2 | /exo_07.rb | UTF-8 | 94 | 3.09375 | 3 | [] | no_license | print "Choisis un nombre ~> "
user_num = gets.to_i
1.upto(user_num) {|user_num| puts user_num} | true |
d77b9ef3abf859230c7b9a05a9ffc95735c65198 | Ruby | ajn123/market_example | /lib/checkout.rb | UTF-8 | 1,232 | 3.421875 | 3 | [] | no_license |
class Checkout
attr_accessor :item_count
attr_accessor :discounts
attr_accessor :products
def initialize
@cart = []
@item_count = Hash.new(0)
@discounts = {}
@products = {}
end
def add_discount(product, code, amount, type, optio... | true |
951323870f1c458ce4d013bfc92a970b685468ee | Ruby | MarkFChavez/vehicle_coding_ph-ruby | /lib/vehicle_coding_ph/checker.rb | UTF-8 | 1,215 | 2.59375 | 3 | [
"MIT"
] | permissive | module VehicleCodingPh
class Checker
def self.call(plate_no, datetime = Time.now)
return allowed_anywhere if weekend?(datetime)
return allowed_anywhere if not coding?(plate_no, datetime)
allowed_areas = []
not_allowed_areas = []
hour_of_the_day = datetime.hour
VehicleC... | true |
f734728b45071c81a0a9a0f3b52e826e6eac7b6a | Ruby | cremno/mruby-allegro | /llapi/primitives.rb | UTF-8 | 1,360 | 3.09375 | 3 | [] | no_license | def al_draw_line(x1, y1, x2, y2, color, thickness)
Al.draw_line(x1, y1, x2, y2, color, thickness)
end
def al_draw_triangle(x1, y1, x2, y2, x3, y3, color, thickness)
Al.draw_triangle(x1, y1, x2, y2, x3, y3, color, thickness)
end
def al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, color)
Al.draw_filled_triangle(x... | true |
d6f356ef4573e2787615a4b1970a61bbfa6f58a5 | Ruby | TheConductor/Study | /study_plan/ruby_code/lib/remove_duplicates_from_array.rb | UTF-8 | 819 | 3.703125 | 4 | [] | no_license | class RemoveDuplicatesFromArray
attr_accessor :array
def remove_duplicates(array)
array_start_size = array.size # used to insure whole array is itterated over
items_removed = 0 # used to adjust the index of the for loop to the index of the element that needs to be removed as indexs will not match up wi... | true |
9b8bdc309923e16d9eb5a4918bf23df04a040cf6 | Ruby | reo0306/RubySliver | /lesson/4/4-36.rb | UTF-8 | 330 | 2.6875 | 3 | [] | no_license | class Baz1
def public_method1; 1; end
public
def public_method2; 2; end
protected
def protected_method1; 1; end
def protected_method2; 2; end
private
def private_method1; 1; end
end
p Baz1.new.public_method1
p Baz1.new.public_method2
#p Baz1.new.protected_method1
#p Baz1.new.protected_method2
p Baz1.new.privat... | true |
0c0a23348e9d5b17dae6eab9c2472c5b25f4dedc | Ruby | caseyscarborough/github | /lib/github_api_v3/client.rb | UTF-8 | 6,069 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'base64'
require 'json'
require 'github_api_v3/client/commits'
require 'github_api_v3/client/contents'
require 'github_api_v3/client/events'
require 'github_api_v3/client/feeds'
require 'github_api_v3/client/gists'
require 'github_api_v3/client/gitignore'
require 'github_api_v3/client/issues'
require 'github_ap... | true |
a8fce2092f030d647010e882489323e29a77682f | Ruby | nagatea/nagatea_bot | /lib/cheesecake.rb | UTF-8 | 1,265 | 2.9375 | 3 | [] | no_license | require 'open-uri'
require 'mechanize'
class Cheesecake
def initialize
@now = Time.now
end
def get_cheesecake(month = @now.month, day = @now.day) #チズケの閉館時間を取得する
unless Date.valid_date?(@now.year, month.to_i, day.to_i)
return "#{month}月#{day}日は存在しませんが"
end
if month.to_i < 10
mon = "... | true |
05fbd14715aeaf68062908b4b24140ce9984615f | Ruby | sahilda/the-truck-stop-sf | /lib/hipchatResponse.rb | UTF-8 | 1,160 | 2.734375 | 3 | [] | no_license | require_relative './truckStopDataPull.rb'
require 'json'
class HitchatResponse
def self.build_response
response = {}
response['color'] = 'green'
response['message'] = TruckStopDataPull.new.get_trucks
response['notify'] = 'false'
response['message_format'] = 'text'
response.to_... | true |
990e8608add96d9b8536270f04fb91dd4c5f93fc | Ruby | collabnix/dockerlabs | /vendor/bundle/ruby/2.6.0/gems/rubocop-0.93.1/lib/rubocop/cop/layout/line_length.rb | UTF-8 | 8,584 | 2.84375 | 3 | [
"Apache-2.0",
"CC-BY-NC-4.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
require 'uri'
module RuboCop
module Cop
module Layout
# This cop checks the length of lines in the source code.
# The maximum length is configurable.
# The tab size is configured in the `IndentationWidth`
# of the `Layout/IndentationStyle` cop.
# It al... | true |
e2988146dca2bf8b2d9709f510bb2d889354d45c | Ruby | SlothSimon/HousePricing | /app/models/shops_houses.rb | UTF-8 | 341 | 2.53125 | 3 | [] | no_license | require 'csv'
class ShopsHouses < ActiveRecord::Base
belongs_to :house
belongs_to :shop
def self.to_csv
attributes = %w{id shop_id house_id}
CSV.generate(headers: true) do |csv|
csv << attributes
ShopsHouses.all.each do |col|
csv << attributes.map { |attr| col.send(attr) }
en... | true |
3627db67527c3c3d342b5742a18bdbfca6b73862 | Ruby | MicaW/lrthw | /chap01/ex3.rb | UTF-8 | 828 | 4.5 | 4 | [] | no_license | #Writes string
puts "I will now count my chickens:"
# Calculates and writes how many hens and roosters
puts "Hens #{25.0 + 30.0 / 6.0}"
puts "Roosters #{100.0 - 25.0 * 3.0 % 4.0}"
#Writes string
puts "Now i will count the eggs"
#Calculates and writes
puts 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0
#Writes ... | true |
66549a0581424b2f39203ed315219c506918a1eb | Ruby | Rik280491/programming-univbasics-nds-nds-to-insight-understand-lab-london-web-120919 | /lib/nds_explore.rb | UTF-8 | 416 | 2.859375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'directors_database'
# Call the method directors_database to retrieve the NDS
def pretty_print_nds(nds)
pp nds
end
def print_first_directors_movie_titles
first_movies = directors_database[0][:movies]
inner_index = 0
while inner_index < first_movies.length ... | true |
11998e3e44569a77aa8fc09350a0cf971d4f9b09 | Ruby | peoplesmeat/DecksterRails | /app/helpers/deckster/other_helper.rb | UTF-8 | 1,287 | 2.765625 | 3 | [
"MIT"
] | permissive | module Deckster
module OtherHelper
def color_average *colors_to_avg
n = colors_to_avg.count
totals = colors_to_avg.reduce({r: 0, b: 0, g: 0}) do |accum, str|
p = {}
p[:r], p[:g], p[:b] = str.split(/([0-9a-fA-F]{2})/).select { |x| not x.empty? }.map { |s| Integer(s, 16) }
accum... | true |
31a4e379d201cf7a1c899221aeeb5e7611863e57 | Ruby | Emilie-D/Decouverte_Ruby_2 | /exo_20.rb | UTF-8 | 199 | 3.0625 | 3 | [] | no_license | puts "Salut, bienvenue dans ma super pyramide ! Combien d'étage veux-tu ?"
print ">"
user_number = gets.chomp.to_i
puts "Voici la pyramide :"
i = 0
while i < user_number
i += 1
puts "#" * i
end | true |
7628754d4517f9418bd8bb77a60c3351034cb39b | Ruby | coffeencoke/mince | /lib/mince/data_model/timestamps.rb | UTF-8 | 1,690 | 2.640625 | 3 | [
"MIT"
] | permissive | module Mince
module DataModel
require 'active_support/concern'
require_relative '../data_model'
# = Timestamps
#
# Timestamps can be mixed into your DataModel classes in order to provide with fields
# to store when records are created and updated.
#
# Example:
# require 'mince/d... | true |
180a646deadfee1b3a4e841c0def129c1b9758dc | Ruby | loic-roux-404/playbook-template | /.manala/vg-facade/tools.rb | UTF-8 | 376 | 3.0625 | 3 | [
"BSD-3-Clause"
] | permissive | # Ruby complements
class ::Hash
def deep_merge(second)
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end
def to_struct
Struct.new(*keys.map(&:to_sym)).new(*values.to_struct)
end
end
class ::Array
def to_struct
map { |value| value.respo... | true |
69f770521d549e68f2fc2a39bd686d6b16f3484c | Ruby | thangngoit/random_japanese_string | /lib/random_japanese_string.rb | UTF-8 | 885 | 2.984375 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
require "random_japanese_string/version"
require "yaml"
class RandomJapaneseString
HIRA = YAML.load_file(File.expand_path(File.join('..', 'data', 'hiragana.yml'), __FILE__))
KATA = YAML.load_file(File.expand_path(File.join('..', 'data', 'katakana.yml'), __FILE__))
KANJI = YAML.load_f... | true |
45694d01d47e2defc1b2cf9d8ad813ce32b43fea | Ruby | khkhROZALIYakhkh/fat-librarians | /lib/shipping/base.rb | UTF-8 | 299 | 2.9375 | 3 | [] | no_license | module Shipping
class Base
attr_accessor :weight
def initialize weight = nil
@weight = weight.nil? ? 1 : weight.to_f
end
def name
self.class.name.split('::').last
end
def cost
weight * 0.1
end
def days
1
end
end
end | true |
6ccee7be28329264e74bbadd06bb4ab303c2d51e | Ruby | oggy/command_rat | /spec/spec_helper.rb | UTF-8 | 1,708 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'spec'
require 'command_rat'
require 'fileutils'
require 'rbconfig'
module SpecHelper
def self.included(mod)
mod.before do
@files_to_cleanup = []
end
mod.after do
@files_to_cleanup.each do |name|
FileUtils.rm_f name
end
end
end
def temp_dir
File.dirname(__F... | true |
6fb77ab32fcca2eca7a7fd5482a316378f574796 | Ruby | jpedro-50/ESSBetRuby | /views/game_view.rb | UTF-8 | 694 | 2.734375 | 3 | [] | no_license | class GameView
def create
puts "\n ---- Inserir Jogo ---- \n"
puts "Insira os dados do Jogo {Identificador,Equipa1,Equipa2,data,IdentificadorBookie}\n"
end
def update
puts "\n ---- Actualizar Jogo ---- \n"
puts "Insira os novos dados do Jogo {Equipa1,Equipa2,data,estado}"
end
def show(id,tea... | true |
8e7036b22e7e8352c5bb99fa70bdd05f8bed5568 | Ruby | vochong/project-euler | /ruby/euler002.rb | UTF-8 | 148 | 3.28125 | 3 | [] | no_license | f1 = 1
f2 = 2
sum = 2
while f1 + f2 <= 4000000 do
tmp = f2
f2 += f1
f1 = tmp
if f2.even?
sum += f2
end
end
puts sum
| true |
14132c418021f75d6d1e06558c5cb40362c63b90 | Ruby | branfull/fte_2103 | /lib/event.rb | UTF-8 | 1,318 | 3.578125 | 4 | [] | no_license | class Event
attr_reader :name,
:food_trucks
def initialize(name)
@name = name
@food_trucks = []
end
def add_food_truck(food_truck)
@food_trucks.push(food_truck)
end
def food_truck_names
@food_trucks.map do |food_truck|
food_truck.name
end
end
# refactor if time... | true |
78715bb104f1dacf6520a681f3d3ffcff2ee3697 | Ruby | peterylai/code-challenges | /leetcode/63_unique_paths_2.rb | UTF-8 | 1,313 | 4.03125 | 4 | [] | no_license | # Follow up for "Unique Paths":
# Now consider if some obstacles are added to the grids. How many unique paths would there be?
# An obstacle and empty space is marked as 1 and 0 respectively in the grid.
# For example,
# There is one obstacle in the middle of a 3x3 grid as illustrated below.
# [
# [0,0,0],
# [0... | true |
a2e50ca90dfcc7eadbbf147c0f4a15b0e00c06d8 | Ruby | jhwebbjr/currencyconverter | /cxs_app.rb | UTF-8 | 1,692 | 3.25 | 3 | [] | no_license | require 'pry' # => true
require_relative 'Currency' # => true
us_dollar = Currency.new(1000, "usd") # => #<Currency:0x007fbcff12fac0 @amount=1000, @currency_code="usd">
five_us_dollar = Currency.new(5000, "usd") # => #<Currency:0x007fbcff127938 @amount=5000, @currency_code="usd">
naija_naira... | true |
2d320c8584715b4fc1e61f2398b1e42f2af20ba2 | Ruby | douglasnec/school | /app/helpers/students_helper.rb | UTF-8 | 406 | 2.78125 | 3 | [] | no_license | module StudentsHelper
def values(person)
if person.birth.nil?
""
else
person.birth.strftime('%d/%m/%Y').to_s
end
end
def type_contact(value)
case value
when 1
' (Responsible)'
when 2
' (Student)'
when 3
' (Contact)'
when 4
'... | true |
d44b59ea9a5b56ed7764dc0b5b70d4ba5c97bce4 | Ruby | lrsdev/dog-admin | /db/seeds.rb | UTF-8 | 3,486 | 2.609375 | 3 | [] | no_license | # Basic seeds
# Dog Status Values:
# 0: Off lead
# 1: On lead
# 2: No dogs
#
# Region values:
# 0: Southland
# 1: Otago
# 2: Canterbury
# 3: Westland
# 4: Marlborough
# 5: Nelson
# 6: Wellington
# 7: Hawke's Bay
# 8: New Plymouth
# 9: Auckland
#
# Geolocation Points are Longitude/Latitude
ablurb = "If this is in produ... | true |
086636db77d6fbb9a7529a350117a88945d5feea | Ruby | liuderek97/Day4-Challenges | /category_checker.rb | UTF-8 | 1,277 | 3.59375 | 4 | [] | no_license | data = {"chocolate things" => ["chocolate cake", "hot chocolate", "choc"], "liquids" => ["water", "hot chocolate", "cola", "juice"], "lollies" => ["skittles", "M&Ms", "licorice"]}
puts "The categories you can choose from are #{data.keys}. Please choose one of the categories"
user_choice = gets.chomp
if data.has_key?("... | true |
b8fad5399f17d5846664bb00b9e5592a409ffa51 | Ruby | seatgeek/shippinglogic | /lib/shippinglogic/fedex/response.rb | UTF-8 | 2,515 | 3 | 3 | [
"MIT"
] | permissive | require "shippinglogic/fedex/error"
module Shippinglogic
class FedEx
# Methods relating to receiving a response from FedEx and cleaning it up.
module Response
SUCCESSFUL_SEVERITIES = ["SUCCESS", "NOTE", "WARNING"]
private
# Overwriting the request method to clean the response and h... | true |
6f3399634afb52ee4016d8fd3a0d86ec6c923e03 | Ruby | darthschmoo/fun_with_version_strings | /lib/version_strings/api.rb | UTF-8 | 1,016 | 2.765625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module FunWith
module VersionStrings
# methods that can be called directly upon the module FunWith::VersionStrings
module API
# if no string is given, the given object is assumed to have a root path and
# to have a file "VERSION" immediately underneath that root. That's standard for
# my ge... | true |
d7d33fec4ff9973b963fda94066e59bc6567bedc | Ruby | rbrother/ReactionSimulator | /ReactionSimulator/Simulate.rb | UTF-8 | 1,686 | 3.34375 | 3 | [] | no_license | require 'reaction'
class Simulation
attr_reader :reagents, :reactions
def initialize(*molecules) # list of { :name => 'H2O(l)', :conc => 55.55 }
@reagents = molecules.map { |m| [ m[:name], Reagent.new(m[:name],m[:conc]) ] }.to_hash
@reactions = Reaction.find_reactions( reagents )
e... | true |
f4dbc00b307a20161f06cd1879b5cbd81d3dfea3 | Ruby | odysseus/wot_ruby | /code_files/tank_group.rb | UTF-8 | 386 | 3.046875 | 3 | [] | no_license | require_relative './tank.rb'
class TankGroup
attr_accessor :group, :db, :name
def initialize dict
@db = TankStore.db
@group = []
dict.each do |k,v|
tank = Tank.new(v)
tank.db = @db
@group.push(tank)
end
end
def self.to_s
"TankGroup"
end
def first
@group.first
... | true |
cb84d2325b1da2b25abf4c1b0249344585547376 | Ruby | jpsilva20/collections_practice-online-web-sp-000 | /collections_practice.rb | UTF-8 | 767 | 3.921875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(array)
array.sort do |a, b|
a <=> b
end
end
def sort_array_desc(array)
array.sort do |a, b|
-(a <=> b)
end
end
def sort_array_char_count(array)
array.sort do |a, b|
a.length <=> b.length
end
end
def swap_elements(array)
array[1], array[2] = array[2],array[1]
arra... | true |
2ef364d8461156c5109a71e5f528daa02260cc9d | Ruby | raskhadafi/vesr | /lib/vesr/reference_builder.rb | UTF-8 | 726 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'vesr/validation_digit_calculator'
module VESR
class ReferenceBuilder
def self.call(customer_id, invoice_id, esr_id)
new(customer_id, invoice_id, esr_id).call
end
attr_reader :customer_id, :invoice_id, :esr_id
def initialize(customer_id, invoice_id, esr_id)
@customer_id = custom... | true |
d6870898790798b76e02919ea70dcac223950bd3 | Ruby | SimonDein/launch | /course_101/exercises/easy_3/searching_101.rb | UTF-8 | 560 | 4.34375 | 4 | [] | no_license | # Write a program that solicits 6 numbers from the user -
# then prints a message that describes whether or not the 6th number appears amongst the first 5 numbers.
obtained_numbers = []
# solution 1
5.times do |iteration|
puts "=> Enter the #{(iteration + 1)}. number"''
num = gets.chomp.to_i
obtained_numbers <<... | true |
03acc392f885fefb9440e0c5110bf50b99ee63b1 | Ruby | bureaucratix/array-methods-lab-seattle-web-career-042219 | /lib/array_methods.rb | UTF-8 | 611 | 3.9375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_include(array, element)
array.include?(element)
end
def using_sort(array)
array.sort
end
def using_reverse(array)
array.reverse
end
def using_first(array)
array.first
end
def using_last(array)
array.last
end
def using_size(array)
array.length
end
=begin
Determine if an array contains a partic... | true |
3b7e473513638b2c89e2dda609511265e45961e5 | Ruby | rails/rails | /activerecord/lib/active_record/aggregations.rb | UTF-8 | 14,702 | 3.75 | 4 | [
"MIT",
"Ruby"
] | permissive | # frozen_string_literal: true
module ActiveRecord
# See ActiveRecord::Aggregations::ClassMethods for documentation
module Aggregations
def initialize_dup(*) # :nodoc:
@aggregation_cache = @aggregation_cache.dup
super
end
def reload(*) # :nodoc:
clear_aggregation_cache
super
... | true |
9cf4b587bf03b1134d34c62357abab4cdbed87bc | Ruby | kjkkuk/homeworks | /HW_05/Aleksei_Makar/student.rb | UTF-8 | 784 | 2.890625 | 3 | [] | no_license | require_relative 'human'
require_relative 'authorization'
require_relative 'homework'
require_relative 'api'
require 'uri'
require 'net/http'
# creates a student and describes his behavior
class Student < Human
include Authorization
def create_homework(source:, title:)
Homework.new(homework_source: source, st... | true |
a3f86e6d36d845124990348fa46674b0441122de | Ruby | bataylor976/puppet-samba | /spec/support/augeas.rb | UTF-8 | 1,180 | 2.828125 | 3 | [
"MIT"
] | permissive | require "delegate"
module Augeas
class Change
attr_reader :target, :name, :delimiter
def initialize(target, name, value = nil, delimiter = "\"")
@target = target
@name = name
@value = value
@delimiter = delimiter
end
def to_s
"#{action} #{delimiter}target[. = '#{target... | true |
a12628f245adcc2585d107bc0f031083ee60b87f | Ruby | GordonNY/collections_practice_vol_2-001-prework-web | /collections_practice.rb | UTF-8 | 1,111 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # your code goes here
def begins_with_r(arr)
arr.all? { |e| e.start_with?("r") }
end
def contain_a(arr)
arr.select { |e| e.include?("a")}
end
def first_wa(arr)
arr.detect { |e|
if e.class === "String"
e.start_with?("wa")
else
false
end
}
end
def remove_non_strings(arr)
arr.reject! {... | true |
e886121527a2a2a7348a14f8101e15036e5c60d3 | Ruby | sky-uk/mirage | /features/support/command_line.rb | UTF-8 | 862 | 2.5625 | 3 | [] | no_license | require 'tempfile'
require 'wait_methods'
module CommandLine
include Mirage::WaitMethods
def run command
output = Tempfile.new("child")
Dir.chdir SCRATCH do
process = ChildProcess.build(*("#{command}".split(' ')))
process.detach
process.io.stdout = output
process.io.stderr = output... | true |
88086c67f77299a5020f311b74ba4cea70b776f2 | Ruby | mikeapp/disco | /app/models/resource.rb | UTF-8 | 2,352 | 2.5625 | 3 | [] | no_license | require 'net/http'
class Resource < ApplicationRecord
validates :object_id, presence: true
validates :object_type, presence: true
def create_event_if_changed
response = request(object_id, true)
response = request(object_id) if response.code == '405'
process_response(response)
end
private
de... | true |
d6497a9443d730e645199a0a98eb49572351cb73 | Ruby | MarielJHoepelman/activerecord-tvland-v-000 | /app/models/actor.rb | UTF-8 | 673 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #* Associate the `Actor` model with the `Character` and `Show` model. An actor should have many characters and many shows through characters.mh
#* Write a method in the `Actor` class, `#full_name`, that returns the first and last name of an actor.
#* Write a method in the `Actor` class, `#list_roles`, that lists all of... | true |
da9423fee58a8b142a40134a23cc1e3009bb1a8a | Ruby | raganwald-deprecated/rewrite | /pkg/rewrite-0.3.0/lib/rewrite/by_example/length_one.rb | UTF-8 | 1,196 | 2.90625 | 3 | [
"MIT"
] | permissive | $:.unshift File.dirname(__FILE__)
module Rewrite
module ByExample
# Natches a sequence containing one item. Wraps an entity matcher,
# with the wrapped matcher matching the one item.
#
# Confusing? Consider SymbolEntity.new(:foo). It matches a single
# entity, :foo. Whereas LengthOne.new(... | true |
09844cc9ffa9a6609747e2ec6ea83825b9fbcf14 | Ruby | jovelabs/jumpkick | /lib/jumpkick/logger.rb | UTF-8 | 900 | 2.515625 | 3 | [
"MIT"
] | permissive | require "logger"
class Jumpkick::Logger < ::Logger
SEVERITIES = Severity.constants.inject([]) {|arr,c| arr[Severity.const_get(c)] = c; arr}
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = Regexp.last_match[1]
line = Regexp.last_match[2]
method = Regexp.last_match[3]
... | true |
70b8c3d4eee29c15852c16c1fc1ffbe34dcd9377 | Ruby | tvaroglu/ruby-exercises | /command-query/exercises/lib/children/children.rb | UTF-8 | 326 | 3.265625 | 3 | [] | no_license | class Children
attr_accessor :children
def initialize()
@children = Array.new
end
def <<(child)
if child.class == Child
children << {
:name => child.name,
:age => child.age
}
end
end
def eldest()
return children.max_by do |child|
child[:age]
end
end... | true |
1681494b54005dfd96ef7f75cd8e618b72ea2165 | Ruby | jcovell/my-first-repository | /more_stuff/regex.rb | UTF-8 | 1,110 | 4.21875 | 4 | [] | no_license | # Creating regular expressions starts with the forward slash character (/). Inside two forward slashes you can place any characters you would like to match with the string. We can use the =~ operator to see if we have a match in our regular expression. Let's say we are looking for the letter "b" in a string "powerball... | true |
160659b18e77809c37fa31d99f99e4180e7d658d | Ruby | kayline/backbone_task_lists | /db/seeds.rb | UTF-8 | 348 | 2.71875 | 3 | [] | no_license | first_list = List.new
first_list.title = "A Task List"
first_list.description = "An example list for playing around"
first_list.save
task1 = Task.new
task1.description = "A thing to do"
task2 = Task.new
task2.description = "Another thing that needs doing"
tasks = [task1,task2]
tasks.each do |t|
t.save
first_list.tas... | true |
35b2ce5222d49b2fcf7b33d9f1f30e9004f73996 | Ruby | ivanbrennan/Rspec-Code-Coverage | /jukebox_spec.rb | UTF-8 | 2,062 | 3.015625 | 3 | [] | no_license | require 'simplecov'
SimpleCov.start
require 'json'
require 'rspec'
require_relative 'jukebox'
require_relative 'song'
test_songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The... | true |
4b1f69170ebaabc85e880fd5a4157b66aef321dd | Ruby | geethh007/July18-22Work | /RubyTesting/Conditions.rb | UTF-8 | 526 | 3.78125 | 4 | [] | no_license | #require 'A2'
#obj= A2.new
#obj.checkNature(-9)
require 'A1'
obj=A1.new(10,5)
s=obj.sub(20,30)
puts obj.mul(s,100)
r=obj.sum(20,10)
t=obj.sub(20,10)
puts obj.mul(r,t)
obj.table(9)
puts""
obj.reverseTable(9)
puts ""
obj.forLoopTripleDot(4)
puts ""
obj.forLoopDoubleDot(2)
puts""
#approach-1
arr1= Array.new(5)
... | true |
36ae2bfe180f85740477953fa290973d9b748035 | Ruby | jsoranno/castaway | /lib/castaway/element/text.rb | UTF-8 | 1,582 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'castaway/element/base'
module Castaway
module Element
class Text < Element::Base
def initialize(production, scene, string)
super(production, scene)
@string = string
@gravity = 'Center'
@font = 'TimesNewRoman'
@font_size = 24
@background = 'transpar... | true |
053b455278ee7d644cd2238e9c253c28c25ad293 | Ruby | xoptov/trading-core-ruby | /lib/trading_core/models/trade.rb | UTF-8 | 1,900 | 3.171875 | 3 | [] | no_license | require 'rate'
module TradingCore
module Model
module Trade
include Rate
attr_reader :origin_id, :currency_pair, :type, :created_at
TYPE_SELL = :sell
TYPE_BUY = :buy
# @param origin_id Integer
# @param currency_pair CurrencyPair
# @param type Symbol
... | true |
7a8060ca2a43c9be492090c78b5b1f4a51ab6972 | Ruby | eduardopoleo/ctci | /linked_list/sum_list.rb | UTF-8 | 1,704 | 3.5 | 4 | [] | no_license | require_relative './linked_list'
def sum_list(head1, head2)
# current = head1
# number1 = 0
# multiple = 1
#
# while current != nil
# number1 += current.id * multiple
# multiple *= 10
# current = current.next
# end
#
# current = head2
# number2 = 0
# multiple = 1
#
# while current !... | true |
81821901436f5d0158b2e944fac1e7b9b047c1e2 | Ruby | sergey-elkin/yandex_dictionary_api | /spec/spec_yandex_dictionary_api.rb | UTF-8 | 836 | 2.546875 | 3 | [
"MIT"
] | permissive | require "spec_helper"
describe YandexDictionaryApi do
before do
$interface = YandexDictionaryApi::ApiInterface.new(ENV["API_KEY"])
end
it "should return a list of supported languages" do
res = $interface.get_langs
res.include?("en-en")
end
it "should return a class contains translation and in... | true |
82a677152d92cfb4303f783e8492c8ebc3c4ea8c | Ruby | TimotheRuffino/S3_J3_Scraping_to_files | /lib/scrap_mairies.rb | UTF-8 | 2,744 | 3.015625 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'google_drive'
require 'csv'
# require 'pry' #binding.pry
class MailMairie
attr_accessor :what_db, :mairie_hash
def initialize(what_db)
@what_db = what_db
end
def create_hash_of_name_and_mail
$annuaire = Nokogiri::HTML(open("http://annuaire-des-mairies.... | true |
f1e1b001c265ac9850c392d946b37b01cdb5f1ff | Ruby | unders/eschaton | /slices/google_maps/google/pane.rb | UTF-8 | 1,477 | 2.671875 | 3 | [
"MIT"
] | permissive | module Google
# Represents a pane that can be added to the map using Map#add_pane. Useful when building your own map controls that
# contain html.
class Pane < MapObject
# ==== Options:
#
# * +text+ - Optional
# * +partial+ - Optional
#
# * +css_class+, Optional, defaulted to 'pane'... | true |
16f767ec821ae2e727a3ac50ab5be695a1d393d6 | Ruby | nazwhale/ruby-kickstart | /session3/challenge/2_hashes.rb | UTF-8 | 679 | 4.0625 | 4 | [
"MIT"
] | permissive | # Given a nonnegative integer, return a hash whose keys are all the odd nonnegative integers up to it
# and each key's value is an array containing all the even non negative integers up to it.
#
# Examples:
# staircase 1 # => {1 => []}
# staircase 2 # => {1 => []}
# staircase 3 # => {1 => [], 3 => [2]}
# staircase 4... | true |
dd717a554448ab84fa786a8c7df31d4122978598 | Ruby | andrewparrish/citibike_planner_api | /app/services/api_services/citibike_api_service.rb | UTF-8 | 475 | 2.78125 | 3 | [] | no_license | require 'uri'
require 'net/http'
require 'json'
class CitibikeApiService
BASE_URL = "https://feeds.citibikenyc.com"
def initialize(endpoint)
@data = nil
@endpoint = endpoint
@uri = URI(BASE_URL + endpoint)
end
def perform
get_data
process_data
end
private
def process_data
rais... | true |
2a7f660d46daa4b80b9445a3f222bc96632b6aba | Ruby | grimyoung/chess | /board.rb | UTF-8 | 14,180 | 3.1875 | 3 | [] | no_license | module Chess
class Board
attr_accessor :grid,:white_attack,:black_attack,:white_castled,:black_castled,:enpassant, :enpassant_pawn_pos, :legal_moves
#top left is (0,0) bottom right is (7,7), (row,column)
def initialize
@grid = Array.new(6){Array.new(8)}
@grid[0] = back_rank('b', [0,0])
... | true |
f10ee9d5d6eba0069e586bfccd4c58777f99e27b | Ruby | mwunsch/redwood | /test/test_redwood.rb | UTF-8 | 6,218 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'helper'
class TestRedwood < Test::Unit::TestCase
describe 'Node' do
test 'has a name' do
node = Redwood::Node.new(:test)
assert_equal :test, node.name
end
test 'can be a root element' do
node = Redwood::Node.new
assert node.root?
end
test 'add a child'... | true |
b940a499dcc665c88490dd7543c34f401bd791cc | Ruby | dry-rb/dry-types | /lib/dry/types/constructor/function.rb | UTF-8 | 6,117 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
require "concurrent/map"
module Dry
module Types
class Constructor < Nominal
# Function is used internally by Constructor types
#
# @api private
class Function
# Wrapper for unsafe coercion functions
#
# @api private
class Saf... | true |
509b808bf217c9d7b609959e7d87279824f34f30 | Ruby | davgit/samson | /app/models/terminal_executor.rb | UTF-8 | 1,177 | 2.921875 | 3 | [
"Apache-2.0"
] | permissive | require 'pty'
require 'shellwords'
# Executes commands in a fake terminal. The output will be streamed to a
# specified IO-like object.
#
# Example:
#
# output = StringIO.new
# terminal = TerminalExecutor.new(output)
# terminal.execute!("echo hello", "echo world")
#
# output.string #=> "hello\r\nworld\r\n"
#
c... | true |
68b02af1983a58eee3875d27bb878950e574ba0f | Ruby | FreddieBoi/Warbands | /app/models/member.rb | UTF-8 | 1,722 | 2.734375 | 3 | [] | no_license | # == Schema Information
# Schema version: 20110603071110
#
# Table name: members
#
# id :integer not null, primary key
# name :string(255) not null
# level :integer default(0), not null
# experience :integer default(0), not null
# health :integer ... | true |
7caac7064e3d3be99f07bb3cc67193fd23bf0185 | Ruby | iseitz/Account-validator-Ruby | /lib/user_account_validator.rb | UTF-8 | 1,068 | 3.21875 | 3 | [] | no_license | require_relative 'invalid_username'
require_relative 'invalid_email'
class UserAccountValidator
attr_reader :name, :username, :email, :user_hash
attr_accessor :errors
def initialize ( user_hash )
@user_hash = user_hash
@name = user_hash[:name]
if !username_invalid?
@username = user_hash[:user... | true |
91ca0315a2eda563412a0274a1ff9ad2e0bc8c86 | Ruby | yantene/rutty | /app/executors/executor_environment/base.rb | UTF-8 | 1,307 | 2.71875 | 3 | [] | no_license | module ExecutorEnvironment
# ExecutorEnvironment::* がメソッドの共通化のためのモジュール。
# extend して利用する。
module Base
# 対応する言語の Docker イメージの id を Redis に格納する際の key
# @return [String] key
def redis_key
%W[
executor_environment
#{self::LANGUAGE}
#{self::VERSION}
image_id
].joi... | true |
de58fe9ae7f47c77c02ee277d682d41809a4ee63 | Ruby | ljwhite/neos | /near_earth_objects_test.rb | UTF-8 | 1,101 | 2.65625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require 'pry'
require_relative 'near_earth_objects'
class NearEarthObjectsTest < Minitest::Test
def test_a_date_returns_a_list_of_neos
results = NearEarthObjects.call('2019-03-30')
assert_equal '(2019 GD4)', results[:astroid_list][0][:name]
end
def te... | true |
4a20b2372978eef1c247be9731b188282b216154 | Ruby | haruboh/my_send_mail | /app/main.rb | UTF-8 | 1,874 | 2.65625 | 3 | [] | no_license | # coding:utf-8
# 相対パスでrequireするために$LOAD_PATHにパスを追加
$LOAD_PATH << File.dirname(__FILE__)
require 'yaml'
require 'socket'
require 'mail'
class Send_mail
def initialize
config = YAML.load_file(CONFIG)
@host = Socket.gethostname
@dir = config["dir"]
@count = config["file_count"].to_i
@mail_charset =... | true |
ae29c91f5eec7fd88fa7a127086ad1f902631f63 | Ruby | SBlines/tddblackjack | /deck.rb | UTF-8 | 1,062 | 3.46875 | 3 | [] | no_license | # encoding: utf-8
class Deck < Array
attr_accessor :cards
SUITS = [:clubs, :diamonds, :hearts, :spades]
def initialize
super
SUITS.each do |suit|
ace = Card[:value => 11, :suit => suit, :card => "ace"]
push(ace)
(2..10).each do |n|
card = Card[:value => n,... | true |
678a57b11328aceca06d2f71411b634266138359 | Ruby | ChristopherBeltran/playlister-sinatra-v-000 | /app/models/song.rb | UTF-8 | 567 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ActiveRecord::Base
belongs_to :artist
has_many :song_genres
has_many :genres, through: :song_genres
def slug
title = self.name
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
slug
end
def self.find_by_slug(slug)
unslug = slug.gsub('-', ' ').gsub(/\S+/, &:capi... | true |
29d2ed2a1893b7fbdeffde598b71cec2fdf05884 | Ruby | jacobhamblin/minesweeper | /minesweeper.rb | UTF-8 | 1,638 | 4 | 4 | [] | no_license | ##TODO
##1. victory? -done
##2. defeat? -done
##3. show a lot if zero -done
##4. identify flag input
##5. make input easier
require_relative "board"
require_relative "cell"
class Minesweeper
def initialize
puts "\n\n\nWelcome to Minesweeper!"
run
end
def reset
puts 'Play again? y/n'
input = get... | true |
ecbda48f94afdd08d16c2bbf6eb452409b1bbc76 | Ruby | radu-constantin/small-problems | /easy1/array_average.rb | UTF-8 | 245 | 3.3125 | 3 | [] | no_license | def average (array)
counter = 0
sum = 0
loop do
sum += array[counter]
counter += 1
break if counter == array.size
end
sum / array.size
end
puts average([1, 5, 87, 45, 8, 8]) == 25
puts average([9, 47, 23, 95, 16, 52]) == 40
| true |
c9ac5ed338c1c5507c84a1c84c832e7c1b62c57e | Ruby | AmyWeiner/happi_tails | /client.rb | UTF-8 | 335 | 3.578125 | 4 | [] | no_license | # This file defines the Client class. A client object must have
# a name, a number of children, an age, and a number of pets.
class Client
attr_reader :name, :num_children, :age, :num_pets
def initialize(name, num_children, age, num_pets)
@name = name
@num_children = num_children
@age = age
@num_pets = nu... | true |
c9e98d589ea7cc76a0a769aec350d3227f4ebbad | Ruby | yoyohashao/enveomics | /Scripts/rbm.rb | UTF-8 | 4,431 | 2.78125 | 3 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/env ruby
#
# @author: Luis M. Rodriguez-R
# @update: Aug-25-2015
# @license: artistic license 2.0
#
require 'optparse'
require 'tmpdir'
o = {len:0, id:0, fract:0, score:0, q:false, bin:"", program:"blast+", thr:1,
nucl:false}
ARGV << "-h" if ARGV.size==0
OptionParser.new do |opts|
opts.banner = "
Fi... | true |
fe23a146ea7251f49c86ef71240eb38b9d9e5c10 | Ruby | CarmichaelLucas/rspec-basic | /spec/matchers/comparacao/comparacao_spec.rb | UTF-8 | 912 | 2.734375 | 3 | [] | no_license | describe 'Matchers de Comparação' do
it '#>' do
expect(5).to be > 1
end
it '#>=' do
expect(5).to be >= 2
expect(5).to be >= 5
end
it '#<' do
expect(1).to be < 5
end
it '#<=' do
expect(1).to be <= 5
expect(1).to be <= 1
end
it '#be_between inclusive' do
expect(5).to b... | true |
94e6ccd763d34f5a9203de6cb674e2f93c0aaf61 | Ruby | Yuta123456/AtCoder | /Ruby/tmp1/クイズ.rb | UTF-8 | 73 | 2.984375 | 3 | [] | no_license | q = gets.chomp.to_i
if q == 1
puts "ABC"
else
puts "chokudai"
end | true |
3117cf06d862a96268b104b94be25d1c543f2fc5 | Ruby | totosha16/Parser | /Old/get_raw.rb | UTF-8 | 299 | 2.796875 | 3 | [] | no_license | input = File.open "input.csv", "r"
while (line = input.gets)
arr=line.strip.split(';')
data={:url=>arr[0],
:cssP=>arr[1],
:xpathP=>arr[2],
:cssD=>arr[3],
:xpathD=>arr[4],
:kP=>arr[5]}
data.each do |k,v|
data[k]=nil if data[k]==""
end
puts data.inspect
end
input.close
gets | true |
691d619767d3379fbc8c0249515cbb038aee7ec0 | Ruby | veronicacheung/kwk_2017 | /Day_4/notes/oo.rb | UTF-8 | 2,165 | 3.515625 | 4 | [] | no_license | # chloe = {
# :username=>"chloe123"
# :password=>"chloeiscool1"
# :email=>"chloe@chloeiscool.com"
# :phone=>"555-555-5555"
# :age=>13
# }
# class User
# attr_reader :username, :password
# #this is always initialize
# def initialize (username,password)
# #the @ sign represents a... | true |
2fd4fc806ae977e94718cc751c6fcaf5f12fbbc4 | Ruby | dlove24/yfs | /bin/yfs.rb | UTF-8 | 2,655 | 2.59375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
### Copyright (c) 2013 David Love <david@homeunix.org.uk>
###
### Permission to use, copy, modify, and/or distribute this software for
### any purpose with or without fee is hereby granted, provided that the
### above copyright notice and this permission notice appear in all copies.
###
### THE SOF... | true |
1f6bfbe5125030cd3fe843c7a5284317420c4a2d | Ruby | xavierloos/codewars | /Ruby/spec/greater_than_spec.rb | UTF-8 | 747 | 3.34375 | 3 | [] | no_license | require "greater_than"
describe "greater_than" do
it "should return a type of number" do
expect(greater_than 5, [4,5,6,7]).to be_a_kind_of(Numeric)
end
it "should raise an error if the first argument is not a valid number or negative" do
expect{greater_than "5", [4,5,6,7]}.to raise_error "Invalid numb... | true |
59a02db6ff908a92b3f51724afaf144d28ed05bb | Ruby | darkelv/lessons | /Lesson_3/station.rb | UTF-8 | 330 | 3.265625 | 3 | [] | no_license | class Station
attr_reader :trains, :station_name
def initialize(station_name)
@station_name = station_name
@trains = []
end
def accept_train(train)
@trains << train
end
def send_train(train)
trains.delete(train)
end
def show_trains(type)
trains.select{|train| train.type == type}
... | true |
02f7ee98348d6429eefdd318eae10453939084eb | Ruby | cybdoom/RoR-events_insider | /app/models/location.rb | UTF-8 | 2,198 | 2.734375 | 3 | [] | no_license | # == Schema Information
#
# Table name: locations
#
# id :integer not null, primary key
# original_address :string
# geocoded_address :string
# country_code :string(2)
# region_code :string
# subregion_code :string
# city :string
# street :string
# street... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.