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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9c3233e9a14c2c75641a89123d73ebea2e5ee1c7 | Ruby | rust/jpmobile-mail | /lib/jpmobile-mail/mobile/softbank.rb | UTF-8 | 747 | 2.5625 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
# =SoftBank携帯電話
# J-PHONE, Vodafoneを含む
module Jpmobile::Mobile
# Vodafone, Jphoneのスーパクラス。
class Softbank < AbstractMobile
# メールエンコーディング情報
def mail_encoding
["shift_jis", true] # shift_jis 変換
end
end
# ==Vodafone 3G携帯電話(J-PHONE, SoftBank含まず)
# スーパクラスはSoftbank。
class... | true |
7597f7df246882795056cd55263d0fc3cdead3c8 | Ruby | enthusiastick/rails_payroll | /app/models/sale.rb | UTF-8 | 350 | 3.109375 | 3 | [] | no_license | class Sale
attr_accessor :last_name, :sale_value
def self.read_sales(filename)
sales = []
CSV.foreach(filename, headers:true) do |row|
sales << Sale.new(row["last_name"], row["gross_sale_value"].to_f)
end
sales
end
def initialize(last_name, sale_value)
@last_name = last_name
@sal... | true |
7d0170737055481beb78d77110c843ac94d500db | Ruby | fortytools/skippr-api-app | /lib/skippr_api.rb | UTF-8 | 6,420 | 2.78125 | 3 | [] | no_license | require 'digest/md5'
require 'singleton'
require 'active_support/json'
require "net/http"
require "uri"
require "timeout"
module SkipprApi
# Authenticates requests for the skippr API
class AuthFactory
include Singleton
attr_reader :secure
attr_reader :domain
attr_reader :port
attr_reader :app... | true |
12b3f89799a2d638b0b4de651631e7bc3676e2f2 | Ruby | chalzstrassen/checkers | /piece.rb | UTF-8 | 3,701 | 3.34375 | 3 | [] | no_license | class Piece
PAWN_DELTAS = [
[1, 1],
[1, -1]
]
W_PAWN_DELTAS = [
[-1, -1],
[-1, 1]
]
KING_DELTAS = [
[ 1, 1],
[ 1, -1],
[-1, 1],
[-1, -1]
]
attr_accessor :pos
attr_reader :color
def is_king?
@is_king
end
def symbol
if is_king?
{ :w => '☆', :b => ... | true |
77e462e1380cf3a82b09d75459de9d4fae392b2f | Ruby | malachispencer/codewars | /ruby/6kyu/is-integer-array.rb | UTF-8 | 1,529 | 4.40625 | 4 | [] | no_license | =begin
Codewars. 20/04/20. 'Is Integer Array?' 6yku. Here we create a method that checks
if every element in an array is an integer or float with no decimals, in which
case we return true. In all other cases, we must return false. Inputs can be nil
or strings instead of an array, in which case we must also return fa... | true |
b51ab5e194db22140671cbec6b115a699287777a | Ruby | yanganna68/sinatra-nested-forms-lab-superheros-web-010818 | /app/controllers/application_controller.rb | UTF-8 | 557 | 2.515625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'sinatra/base'
class App < Sinatra::Base
set :views, Proc.new { File.join(root, "../views/") }
get '/' do
erb :super_hero
end
post '/teams' do
# binding.pry
team = params["team"]
members = team["members"]
@team = Team.new(team["name"], team["motto"])
@hero1 = Hero.new(members[... | true |
242f9acc2b9a673dfd67227bb6c785a38b677494 | Ruby | LukasBarry/trump_tweet_generator | /trump_tweets.rb | UTF-8 | 1,134 | 2.984375 | 3 | [] | no_license | SHAME_WORD = [
'Shame', 'Sad', 'Bad', 'Smart', 'Dumb', 'Liar', 'Win', 'Too bad', 'Fail',
'Mean'
].freeze
POLITICAL_FIGURES = ['Obama', 'Comey'].freeze
ORGANIZATIONS = ['Media', 'CNN', 'Fox', 'NBC', 'Breitbart'].freeze
ADVERBS = ['very', 'much', 'more', 'really'].freeze
ADJECTIVE = [
'prestigious', 'stupid', 'weak... | true |
bbb8a3b570024abeb96e0568ad02eb430ea00f14 | Ruby | 7Pikes/document_number | /spec/models/price_adjustment_spec.rb | UTF-8 | 895 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe PriceAdjustment do
it 'uses non-default column' do
price_adjustment = PriceAdjustment.create
expect(price_adjustment.document_number).not_to be_nil
end
it 'starts from predefined value' do
price_adjustment = PriceAdjustment.create
expect(price_adjustment.document_n... | true |
8eb1e99979b44bba849a3276433607cfcb2f50cd | Ruby | ggruic/sdmx2sql | /parse_sdmx_series.rb | UTF-8 | 4,536 | 2.625 | 3 | [] | no_license | # --------------------------------------------------------------------------------
# Args
# SERIES_FILE - name of file with DDL (series)
# FORMAT - SQLLITE
# KEY_FAMILY - name of field with DSD (xml)
#
# ruby parse_sdmx_series.rb example_sdmx_data.xml SQLITE NA_SEC+ESTAT+v2_0+1.5.xml
# ---------------------------... | true |
023dc9c247031f296f72d0ea037f6d552159b084 | Ruby | djspiewak/buildr | /spec/core/util_spec.rb | UTF-8 | 2,167 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with this
# work for additional information regarding copyright ownership. The ASF
# licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use... | true |
2dd7df34e611d9cf0efe338c8ab4cea032b7123c | Ruby | eslcomputertraining/nokogiri | /try_out_case_statement.rb | UTF-8 | 393 | 3.140625 | 3 | [] | no_license | weather_station = 'sunny'
case weather_station
when 'sunny'
puts "it's a sunny day. wear shades."
when 'cloudy'
puts "it may be cold, wear a light coat."
when 'rainy'
puts "wear a rain coat or bring an umbrella."
when 'snowy'
puts "wear snow attire."
when 'thunder'
puts "stay inside."
when 'haily'
puts "play rai... | true |
78c08c45939956439c48ed42cd7d5d77e399da21 | Ruby | luisgarate/ruby-robots | /mejuri-robot/app/services/buyer_robot.rb | UTF-8 | 665 | 2.875 | 3 | [] | no_license | class BuyerRobot
@limit_cars = 10
@models = ["Altima", "Fiesta", "M3", "X5", "S5", "Civic", "M5", "CR-V", "X3", "Navigator"]
@broker = BrokerRobot.new
def self.buy_cars
cars_buyed = 0
cars_allowed_to_buy = @limit_cars - cars_buyed
while cars_allowed_to_buy > 0
wanted_amount = rand(1..cars_al... | true |
fcce10ee14502b50abbefe50037121b181b907a1 | Ruby | named-data-mobile/android-crew-staging | /library/cmd/build_options.rb | UTF-8 | 1,890 | 2.71875 | 3 | [] | no_license | require_relative '../global.rb'
require_relative '../utils.rb'
require_relative '../arch.rb'
require_relative '../platform.rb'
require_relative '../command_options.rb'
class BuildOptions
extend CommandOptions
attr_accessor :platforms, :abis, :num_jobs
attr_writer :source_only, :build_only, :no_install, :no_cl... | true |
7079cc38fa4e13ec5bd8b5f571a0bcafe541882a | Ruby | pwdunham/data_driven_selenium | /jsonread.rb | UTF-8 | 630 | 3 | 3 | [] | no_license | # JSON Parsing example
require "rubygems"
require "json"
string = '
{
"desc": {
"someKey": "someValue",
"anotherKey": "value"
},
"main_item": {
"stats": {
"a": 8,
"b": 12,
"c": 10
}
}
}'
parsed = JSON.parse(string) # returns a hash
p ... | true |
0522bd21dc6b4d2ba649ac024ffb502b314ef54f | Ruby | wowenstine/ruby_prework | /arrays.rb | UTF-8 | 168 | 3.515625 | 4 | [] | no_license | puts 'enter as many words as you like and I\'ll sort them alphabetically'
wordlist = []
while (words = gets.chomp) !=''
wordlist.push(words)
end
puts wordlist.sort!
| true |
f60cd4428d815051b87985aa89bc6ac41586846f | Ruby | Kah919/oo-practice-concerts | /app/models/band.rb | UTF-8 | 557 | 3.265625 | 3 | [] | no_license | class Band
attr_accessor :name
attr_reader :hometown
@@all = []
def initialize(name, hometown)
@name = name
@hometown = hometown
@@all << self
end
def self.all
@@all
end
def play_in_venue(venue, date)
Concert.new(date, self, venue)
end
def concerts
Concert.all.select { |c... | true |
0f845498a93a041b0c232b111b57f04e53eb5619 | Ruby | thebyus/Session1 | /blackjacklearn2.rb | UTF-8 | 101 | 3.515625 | 4 | [] | no_license | num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
num.each do |element|
puts element if element > 5
end
| true |
56bf5222d8d395e3343df90aeda8b4e7050827aa | Ruby | sagartalla/rigse | /db/seeds.rb | UTF-8 | 2,147 | 2.6875 | 3 | [
"MIT"
] | permissive | # Make a district
site_district = Portal::District.find_or_create_by_name(APP_CONFIG[:site_district])
site_district.description = "This is a virtual district used as a default for Schools, Teachers, Classes and Students that don't belong to any other districts."
site_district.save!
# Make a school within the district
... | true |
0a6e38cfa1df45ea9dd19fafe9977d8b6a6d690d | Ruby | rodolfobandeira/ruby-studies | /imitating-multiple-inheritance.rb | UTF-8 | 426 | 3.578125 | 4 | [] | no_license | # Create your module here!
module MartialArts
def swordsman
puts "I'm a swordsman."
end
end
class Ninja
include MartialArts
def initialize(clan)
@clan = clan
end
end
class Samurai
include MartialArts
def initialize(shogun)
@shogun = shogun
end
end
# Ok, now both classes inherit by... | true |
cfc45788107044ef8ed04a87cec5a2bc770eb8da | Ruby | BSatyaKishore/sensortag_sample | /led.rb | UTF-8 | 385 | 2.890625 | 3 | [] | no_license | require 'bundler/setup'
require 'pi_piper'
class LED
def initialize(pin:)
@pin = PiPiper::Pin.new(pin: pin, direction: :out)
end
def on
@pin.on
end
def off
@pin.off
end
def flash
loop do
@pin.on
sleep 1
@pin.off
sleep 1
end
end
end
if $0 == __FILE__
led... | true |
4104c97dfda2d13cf4d7ec9684f56335ec4d0233 | Ruby | russolsen/ham_radio_question_pool | /programs/words2.rb | UTF-8 | 774 | 3.546875 | 4 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
#
require_relative 'quiz'
require 'json'
require 'set'
def parse_words(s)
Set.new(s.downcase.split)
end
def count_word(m, w)
m[w] = 0 unless m[w]
m[w] += 1
end
path = ARGV.shift
questions = Quiz.json_load(path)
correct_map = {}
incorrect_words = Set.new
questions.each do |q|
answers ... | true |
94bb19552f5cb793f10068ab11f2d8c29a3110ce | Ruby | paulbiit/heroku-architecture-certification-slack-bot | /app/slash_commands/study.rb | UTF-8 | 1,701 | 2.6875 | 3 | [] | no_license | require 'quiz'
module SlashCommands
class Study
ALPHABET = ('A'..'Z').to_a.freeze
DEFAULT_QUIZ = Quiz.all.first
attr_reader :request
def initialize(request)
@request = request
end
def quiz
DEFAULT_QUIZ
end
def question
@question ||= request.interactive? ? inferre... | true |
f84b525c63b63f990822b4e6e4fdc6eee6a1dfcd | Ruby | byjord10/dmv_fest | /lib/scraper.rb | UTF-8 | 454 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'pry'
require 'nokogiri'
require 'httparty'
class Scraper
attr_accessor :event_list_url
BASE_PATH = "http://metromontage.com"
event_list_url = (BASE_PATH + "/list-of-music-festivals-in-d-c-maryland-and-northern-virginia/")
def self.scrape_events(event_list_url)
doc = HTTParty.get(event_list_url)
... | true |
a8a2e0df3ad81b191a672ca5b1ac1b55b1244de7 | Ruby | intokozo/Thinknetica | /Lession_2/5.rb | UTF-8 | 657 | 3.625 | 4 | [] | no_license | puts "Введите число"
date = gets.chomp.to_i
if date < 1 || date > 31
puts "Ввели некорректные данные, попробуем еще раз"
return
end
puts "Введите месяц"
month = gets.chomp.to_i
if month < 1 || month > 12
puts "Ввели некорректные данные, попробуем еще раз"
return
end
puts "Введите год"
year = gets.chomp.to_i
... | true |
cf85151368ed46a0d49e0bf7787b6a3e8134e3c8 | Ruby | TooManyBees/Av-Verify | /lib/sections/line_by_line_object.rb | UTF-8 | 1,333 | 3.203125 | 3 | [] | no_license | # A line by line object simply takes the contents of an entry and parses
# it line by line, comparing the structure of the current line to the
# structure of the expected line.
require_relative "../helpers/tilde"
class LineByLineObject
include Parsable
include TheTroubleWithTildes
attr_reader :contents, :line_... | true |
345555c16cc541f6375feff5c7c1d3687a141dc1 | Ruby | davidqhr/gezi_craft | /heros/mengmeng.rb | UTF-8 | 442 | 2.671875 | 3 | [] | no_license | # coding: utf-8
class Mengmeng < OO
def initialize
@name = "蒙蒙"
@skill_name = "可以点餐啦"
@skill_description = "除祥旦外 ,所有人自己加血"
super
end
def skill player
player.heros.each do |id, hero|
hero.add_current_health(14)
end
self.skill_used = true
"蒙蒙摊开一桌子菜,player#{player.position}的英雄们... | true |
c807e2904ecffb7d6e4b9d9ffd053aa2520aa898 | Ruby | rfleur01/RB101-109 | /Small_Problems/med_1/rotate3.rb | UTF-8 | 548 | 4.03125 | 4 | [] | no_license | def rotate_array(array)
array[1..-1] + [array[0]]
end
def rotate_rightmost_digits(number, digits)
number_array = number.to_s.chars
number_array[-digits..-1] = rotate_array(number_array[-digits..-1])
number_array.join.to_i
end
def max_rotation(number)
counter = number.to_s.size
if counter > 1
loop do
... | true |
e8e372dfdaf6f53bfa430c03fbd0b7ef499be12b | Ruby | senthillkumar/ladon | /spec/common/timing/timer_spec.rb | UTF-8 | 3,564 | 3.015625 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
require 'ladon'
module Ladon
module Timing
RSpec.describe Timer do
let(:timer_name) { 'some_name' }
subject(:timer) { Timer.new }
describe '#new' do
it { is_expected.to have_attributes(entries: []) }
end
describe '#for' do
context 'when given ... | true |
d87cf5be0eebb2f7933d3b3349e19959585334de | Ruby | thbar/ironruby-labs | /wpf/003_magic_with_wpf_toolkit.rb | UTF-8 | 689 | 3.078125 | 3 | [] | no_license | $LOAD_PATH << File.dirname(__FILE__)
$LOAD_PATH << File.dirname(__FILE__) + '/magic/lib'
require 'wpf'
require 'wpf_toolkit'
require 'magic'
# a little model
class Item
attr_accessor :name, :price
def initialize(name, price)
@name = name.to_clr_string # without to_clr_string, the string appears empty (no ... | true |
d29533b45ddd04e8258de007d0d29b79f61bc33d | Ruby | kadru/ia | /game_state.rb | UTF-8 | 3,886 | 3.1875 | 3 | [] | no_license | # Encoding: utf-8
module Tictactoe
class GameState
DIAGONAL_ID = 'd'
REVERSE_DIAGONAL_ID = 'rd'
COLUMN_PREFIX = 'c'
ROW_PREFIX = 'r'
attr_reader :player_piece, :opponent_piece, :winner, :board
def initialize(player_piece, opponent_piece)
validate_arguments(player_piece, opponent_piece... | true |
52c4b1e3dfd10c8076f6bc3b6801ab18b4c236b9 | Ruby | Diane2109/learn_ruby_rspec | /06_pig_latin/pig_latin.rb | UTF-8 | 453 | 3.125 | 3 | [] | no_license | def translate(str)
a = str.split
b=[]
a.collect do |mot|
i=0
if mot[0].match(/[aeoi]/)
mot
else
while !mot[i].match(/[aeoi]/)
i +=1
end
mot = mot[i..-1] + mot[0..i-1]
end
pouet = mot + 'ay'
b << pouet
end
p b.join(' ')
end
translate("apple")
translate("banana")
translate("cherry")... | true |
5cb432f1ea159e566c72075de2e25ae24fd645fb | Ruby | BJSherman80/war_or_peace | /test/deck_test.rb | UTF-8 | 1,175 | 2.6875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/deck'
class DeckTest < Minitest::Test
def test_it_exists
card4 = Card.new(:spades, "3", 3)
card5 = Card.new(:kings, "13", 13)
card6 = Card.new(:diamond, "7", 7)
array_of_cards = [card4, card5, card6]
deck = Deck.new(array_of_card... | true |
5e591c02dab4f37dadb3a8cab1b2836f591a2b92 | Ruby | zangzing/server | /eventmachine/lib/load_logger.rb | UTF-8 | 815 | 2.65625 | 3 | [] | no_license | require 'logger'
def load_logger
cfg = AsyncConfig.config
log_type = cfg[:log_type]
case log_type
when 'stdout'
logger = Logger.new(STDOUT)
when 'file'
logger = Logger.new(cfg[:log_path])
when 'syslog'
logger = Syslogger.new(cfg[:log_app_name])
else
logger = Logger.new(ST... | true |
4f8f7a8693219ee86e9ae96babc12b2e0b84dcdc | Ruby | luckyrolls/Tealeaf_precourse | /chap_7/leap.rb | UTF-8 | 312 | 3.625 | 4 | [] | no_license |
while true do
puts "Enter Start Year"
start_year = gets.chomp().to_i
if start_year != 0 then break end
end
puts "Enter End Year"
end_year = gets.chomp().to_i
for i in start_year..end_year
if
i.%(400) == 0
then puts i
else
if i.%(4) == 0 and i.%(100) != 0
then puts i
end
end
end
| true |
296c7378db380e1240bc649268aa246e7eaab88c | Ruby | jonleung/ujumbo_api | /lib/api_client.rb | UTF-8 | 1,422 | 2.890625 | 3 | [] | no_license | require 'httparty'
require 'show_in_browser'
class ApiClient
include HTTParty
host = "localhost:3000"
base_uri host
HOST = host
def initialize(options={})
@user_token = options[:user_token]
@client_token = options[:client_token]
@name = options[:name]
end
def self.normalize_parameters(valu... | true |
db4cc98c99ec2893c147db5fd6916b8de2db3b8c | Ruby | johnjvaughn/ls_course_130 | /Challenges/Advanced1/poker.rb | UTF-8 | 2,473 | 3.546875 | 4 | [] | no_license | class Hand
RANKS_A_HIGH = { '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6,
'7' => 7, '8' => 8, '9' => 9, 'T' => 10,
'J' => 11, 'Q' => 12, 'K' => 13, 'A' => 14 }.freeze
HAND_RANKINGS = { [1, 4] => 9, [2, 3] => 8, [1, 1, 3] => 3, [1, 2, 2] => 2,
[1, 1, 1, 2... | true |
866971ba1508c725a4624d090ca3ccfb091e2f35 | Ruby | rhec/graphite | /lib/graphite/client.rb | UTF-8 | 3,171 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'eventmachine'
require 'rufus-scheduler'
module Graphite
class Client
# Expects a string in the form of "hostname:port_num" where port_num is optional, and a prefix
# to identify this server. Example:
# Graphite::Client.new("graphite.example.com", "yourapp.#{Rails.env}.instances.#{hostname}... | true |
f3ec4ad51a424997e97124a7f0ab340202a4516c | Ruby | sandersbrad/bubble_sort | /bubble_sort_by2.rb | UTF-8 | 460 | 3.546875 | 4 | [] | no_license | def bubble_sort(array)
switch = true
while switch == true
switch = false
array = array.map do |x|
if array.index(x) < array.length - 1
case z = yield(x,array[(array.index(x) + 1)])
when z > 0
switch = true
y = array[(array.index(x) + 1)]
array[(array.index(x) + 1)] = x
x = y
else
... | true |
a6d633e4f8c4baaf85b06e8c53199381f04764e3 | Ruby | ashraffares/bubble | /bubble.rb | UTF-8 | 831 | 3.96875 | 4 | [
"MIT"
] | permissive | # First task
def bubble_sort(array)
loop do
sorted = false
(array.length - 1).times do |i|
if array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]
sorted = true
end
end
break unless sorted
end
array
end
unsorted_array = [5, 2, 100, 101, 6, 1]
p bubbl... | true |
fd03d758823afd7432cebcd4ec8a8e5618c59f0d | Ruby | cphoniball/donutbot | /spec/day_of_week_spec.rb | UTF-8 | 1,571 | 3.609375 | 4 | [] | no_license | require 'timecop'
require 'pry'
require_relative '../src/day_of_week'
RSpec.describe DayOfWeek do
describe ".new" do
context "day of week is a string" do
it "parses day of the week to an integer" do
expect(described_class.new("Sunday").day_of_week).to eq(0)
expect(described_class.new("Tuesd... | true |
9404181a9c186084005beb2f573491559f2703c2 | Ruby | codelation/rails-templates | /saas/models/organization.rb | UTF-8 | 2,190 | 2.59375 | 3 | [] | no_license | class Organization < ActiveRecord::Base
include Subscriber
# Relationships
has_many :admin_invitations
has_many :memberships, class_name: "OrganizationMembership"
# Validations
validates_presence_of :name
validates_presence_of :subscription_plan_id, on: :create
# Callbacks
after_create :create_init... | true |
4589d89b0eeb40ebfd318b59fe8879c15e845dc1 | Ruby | jkhaha/intro-to-simple-array-manipulations-dumbo-web-082718 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 1,683 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_push(array, element)
countries_in_western_africa = ["Benin", "Carpe Verde", "Gambia", "Liberia", "Mali"]
countries_in_western_africa.push("Niger")
end
def using_unshift(array, element)
neighborhoods_in_northwest_brooklyn = ["Brooklyn Yards", "Cadman Plaza", "Clinton Hill", "Downtown Brooklyn", "DUMBO"]... | true |
7e69b0eb42b1f7ff87b79d29016c6e3de877123d | Ruby | Williampangestu/phase_0_unit_2 | /week_4/7_refactor/reverse_cipher/my_solution.rb | UTF-8 | 4,378 | 4.28125 | 4 | [] | no_license | # U2.W4: Refactor Cipher Solution
# I worked on this challenge by myself
# 1. Solution
# Write your comments on what each thing is doing.
# If you have difficulty, go into IRB and play with the methods.
# Also make sure each step is necessary. If you don't think it's necessary
# Try implementing the code without i... | true |
02b6ebbf9070fa396f7621829bf828c52814e4ca | Ruby | danilobarion1986/chess-rb | /pieces/piece.rb | UTF-8 | 346 | 2.84375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative 'piece_options'
class Piece
include PieceOptions
attr_reader :name, :state
def initialize(name)
@name = name
@state = PieceOptions::STATES[:alive]
end
def kill
@state = PieceOptions::STATES[:dead]
end
def resurrect
@state = PieceOptions:... | true |
b617ce0c71ff122588a9b6338a78017f906c91fa | Ruby | lsylvain1726/Launch_School2017 | /ruby_basics/variable_scope/exercise10.rb | UTF-8 | 251 | 3.71875 | 4 | [] | no_license | #what will the following code print
a = 7
array = [1, 2, 3]
def my_value(ary)
ary.each do |b|
a += b
end
end
my_value(array)
puts a
#this will throw an arrow message
#a is not visible within the block
#because the block is within a method | true |
952b8b5253705c1ed3c8ce597efc1f96103a70e9 | Ruby | anniezh12/sinatra-nested-forms-v-000 | /app/models/pirate.rb | UTF-8 | 239 | 3.078125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Pirate
attr_accessor :name, :weight, :height
PIRATES = []
def initialize(name,weight,height)
@name,@weight,@height = name,weight,height
PIRATES << self
end
def self.all
PIRATES
end
end
| true |
c812a20fee55efd55f10388ac6c883bc9155c59f | Ruby | DIVA-DIA/DIVAServices_Management | /app/models/enum_field.rb | UTF-8 | 754 | 2.921875 | 3 | [] | no_license | ##
# Field used to store enums.
class EnumField < Field
content_attr :values, :string
content_attr :keys, :string
validate :valid_selection
##
# Validates that the selection is valid.
def valid_selection
if !self.value.blank?
errors.add(:value, 'cannot be selected!') unless self.values.include?... | true |
0ec320655c845d0633e777ed51092d6f3a38b5fb | Ruby | itsolutionscorp/AutoStyle-Clustering | /assignments/ruby/hamming/src/885.rb | UTF-8 | 108 | 2.875 | 3 | [] | no_license | def compute(a, b)
c = a.chars.zip(b.chars).map { |nuc| nuc[0] == nuc[1] ? 0 : 1 }
c.reduce(:+)
end | true |
04555e6a259ef2d1f28c5fcff40d17977d520049 | Ruby | brianabaker/deli-counter-web-121117 | /deli_counter.rb | UTF-8 | 741 | 4.0625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
# shows everyone their current place in line
#if no one in line, say the line is empty
def line(katz_deli_line)
if katz_deli_line.length == 0
puts "The line is currently empty."
else
greeting = "The line is currently: "
katz_deli_line.each_with_index do | name, pos |
greeting += "#{pos + 1}. #{name} "
end
for... | true |
513c225cc0d60a28c026682a87e5b8178a188e9a | Ruby | philipyoo/ruby-practice | /12_rpn_calculator/rpn_calculator.rb | UTF-8 | 1,349 | 3.875 | 4 | [
"MIT"
] | permissive |
class RPNCalculator
def initialize
@calc_arr = []
end
def calc_error
raise ArgumentError.new("calculator is empty") if @calc_arr.size < 2
end
def push(num)
@calc_arr << num
end
def plus
calc_error
@calc_arr << @calc_arr.pop(2).inject(0) {|sum,x| sum + x}
end
def minus
calc... | true |
ddcff72f7190cd9cf9eb85172acc649851603a1c | Ruby | pawelma/ubob_bot | /usecases/plus_one_leaderboard.rb | UTF-8 | 921 | 2.890625 | 3 | [] | no_license | class BotShowLeaderboard
include RoomObserver
attr_reader :domain, :leaderboard, :channel_actions
def initialize(domain)
@domain = domain
@channel_actions = 'leaderboard | stats'
watch_room
end
def setup(leaderboard)
@leaderboard = leaderboard
end
def on_say(who, to_whom, what, time)
... | true |
0d57ba44b8953c44888c88aaa10b36b151234f67 | Ruby | allinelima/treinamento_fundamentos | /2_Conceitos Básicos/missao_2.rb | UTF-8 | 205 | 3.625 | 4 | [] | no_license | # Missão 2
print 'Digite seu nome: '
name = gets.chomp
print 'Digite seu Sobrenome: '
sobrenome = gets.chomp
print 'Digite sua idade: '
idade = gets.chomp
puts "Hello #{name} #{sobrenome} #{idade} anos!"
| true |
a3bbb686f6ea8174390dc634cafb00fcfa60a4e0 | Ruby | jokeofweek/comp361 | /script/launch | UTF-8 | 1,780 | 2.765625 | 3 | [] | no_license | #!/usr/bin/env ruby
JAVA_CMD = 'java -Dfile.encoding=US-ASCII -classpath ./bin:./lib/kryonet-2.18-all.jar:./lib/commons-lang3-3.2.1.jar:./lib/jl1.0.1.jar'
SERVER_APP = 'comp361.server.ServerApplication'
CLIENT_APP = 'comp361.client.ClientApplication'
CLIENTS = (ARGV.detect { |arg| arg[0] != '-' } || 2).to_i
def ... | true |
4885958f615fc7b85a7657d13c7b6ce331cf5e09 | Ruby | Balmung421/date_night | /test/binary_search_tree_test.rb | UTF-8 | 18,189 | 2.734375 | 3 | [] | no_license | require 'simplecov'
SimpleCov.start
require 'minitest/autorun'
require 'minitest/pride'
require './lib/binary_search_tree'
class BinarySearchTreeTest < Minitest::Test
attr_reader :tree
def setup
@tree = BinarySearchTree.new
end
def test_exists
assert tree
end
def test_insert_has_correct_output_after... | true |
dc904c10667612346b6b5390a0a2221c66e221bc | Ruby | BrantDFaulkner/code_challenges | /tic_tac_toe/spec/models/game_spec.rb | UTF-8 | 2,134 | 3.203125 | 3 | [] | no_license | require_relative "../../app/models/game"
describe "Game" do
subject(:game) { Game.new(active_player, idle_player)}
let(:active_player) { Player.new({human: false}) }
let(:idle_player) { Player.new({human: false}) }
describe "#set_markers" do
it "should set active_player#marker to 'X'" do
game.set_ma... | true |
8b7b83532c55dc93e6a8a8441aa4839d1497b77f | Ruby | sarakhandaker/Rails-Practice-Code-Challenge-Travelatr-seattle-web-030920 | /app/models/destination.rb | UTF-8 | 362 | 2.890625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Destination < ApplicationRecord
has_many :posts
has_many :bloggers, through: :posts
def feature_post
self.posts.max_by{|post| post.likes}
end
def five_recent
self.posts.sort_by{|post| -(post.id)}
end
def average_age
age_sum=0
self.bloggers.uniq.each{|blogger|age_sum+=blogger.age}
(age_sum/s... | true |
27c68a1243e08de81262a7969e2e3ea8a95c270d | Ruby | cybernick/lunch_ordering_task | /app/models/course.rb | UTF-8 | 484 | 2.640625 | 3 | [] | no_license | class Course < ActiveRecord::Base
validates :name, :price , presence: true
validates :price, numericality: { greater_than_or_equal_to: 0 }
scope :first_courses, -> { where(type: 'FirstCourse') }
scope :second_courses, -> { where(type: 'SecondCourse') }
scope :drinks, -> { where(type: 'Drink') }
has_and_b... | true |
9eab3cf188d21ae50a3709cb6eebc596f61589d4 | Ruby | Homarv/PIERRATMarvinRUBY | /exo_7a.rb | UTF-8 | 359 | 3.6875 | 4 | [] | no_license | puts "Bonjour, c'est quoi ton blase ?"
user_name = gets.chomp
puts user_name
# gets permet à l'utilisateur de saisir une ligne et de la renvoyer en tant que valeur à votre programme
# chomp est la méthode pour supprimer le caractère de ligne \n (touche entrée) lors du renvoi de cette valeur
#ici user_name sera égal a... | true |
96aae94ef428e968b6dca532e9c37fa3271065d1 | Ruby | bmargerison/codewars | /Ruby/7kyu/Complementary DNA (7kyu).rb | UTF-8 | 724 | 3.734375 | 4 | [] | no_license | =begin
Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and
carries the "instructions" for the development and functioning of living
organisms.
In DNA strings, symbols "A" and "T" are complements of each other, as "C" and
"G". You have function with one side of the DNA (string, except for Haskel... | true |
855ece85eb56e33846827a4a00113d8b7039702f | Ruby | iboard/spm | /app/models/application.rb | UTF-8 | 3,092 | 2.5625 | 3 | [
"LicenseRef-scancode-public-domain"
] | permissive | # -*- encoding : utf-8 -*-"
#
# @author Andi Altendorfer <andreas@altendorfer.at>
#
require "logger"
class Application
# @params [String] _env - :test, :develop, :production
# @params [Hash] options - { :logger => $stdout, :log_level => Logger::INFO }
def initialize(_env,options={})
@defaults = { :logger => ... | true |
b373b1944b60703d2d68c4071c2867e461d83d66 | Ruby | executionflow/meterpreter | /posh.rb | UTF-8 | 6,903 | 2.71875 | 3 | [] | no_license | # Meterpreter script to deliver and execute powershell scripts using
# a compression/encoding method based on the powershell PoC code
# from rel1k and winfang98 at DEF CON 18. This script furthers the
# idea by bypassing Windows' command character lmits, allowing the
# execution of very large scripts. No files are eve... | true |
4d57c4fe077482deee80c706cbddc6d55f9de3fc | Ruby | alanzoppa/proforma | /spec/formhash_spec.rb | UTF-8 | 1,498 | 3.421875 | 3 | [] | no_license | $: << File.dirname(__FILE__)
require '../lib/formhash.rb'
describe "A FormHash" do
before do
@fh = FormHash.import({:spam => 123, :eggs => 456})
end
it "should coerce string keys to symbols" do
f = FormHash.new
f['key'] = "value"
f.keys.should == [:key]
end
it "should convert a Hash to a F... | true |
24f510c9f4f46f4e69ece4b74615a5291325cb11 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/robot-name/de0e004f17974d9a9f22316aca774106.rb | UTF-8 | 387 | 3.625 | 4 | [] | no_license | # Robot-name exercism
class Robot
def initialize
self.reset
end
def name
@robot_name
end
def reset
@robot_name = (0...2).map {(65 + rand(26)).chr}.join + (0...3).map {(48 + rand(9)).chr}.join
end
end
# robot = Robot.new
# name = robot.name
# puts robot
# puts name
... | true |
cce45e729413f7ab4a9eabbf4d3d370ec8c59711 | Ruby | GL2-G4/SlitherLink | /UI/Regles.rb | UTF-8 | 2,072 | 2.734375 | 3 | [] | no_license | require "gtk3"
class Regles < Gtk::Box
def Regles.creer(gMenu, menuPere)
new(gMenu, menuPere)
end
def initialize(gMenu, menuPere)
super(:horizontal)
path = File.expand_path(File.dirname(__FILE__))
@gMenu = gMenu
@pere = menuPere
@vBox1 = Gtk::Box.new(:vertical)
@vBox2 ... | true |
9460853e395f20f1a5ef7515ee8cc3cf236dcd7c | Ruby | jeremyrempel/goalsaver | /app/models/valuation.rb | UTF-8 | 719 | 2.71875 | 3 | [] | no_license | class Valuation < ApplicationRecord
belongs_to :user
belongs_to :asslib
attr_accessor :period
# attr_writer
def period=(val)
case val
when 'Q1'
self[:date] = Date.strptime('2016-01-01', '%Y-%m-%d')
when 'Q2'
self[:date] = Date.strptime('2016-04-01', '%Y-%m-%d')
when 'Q... | true |
ae36c0b0b2981491f0b0b6fb8fb980025fb9721c | Ruby | elitenomad/shopping-cart | /lib/shopping/cart/item.rb | UTF-8 | 340 | 2.75 | 3 | [] | no_license | module Shopping
module Cart
class Item
attr_reader :sku, :name, :price, :discount
def initialize(sku:, name:, price:)
@sku = sku
@name = name
@price = price
end
def addToDiscount(discount)
@discount = discount
end
... | true |
f529c16621d56d22c194825ab42196495fc58eb1 | Ruby | prnvsan/Magic-and-Monsters | /sword.rb | UTF-8 | 1,291 | 3.1875 | 3 | [] | no_license | module Sword
require './scene.rb'
class Swordscene < Scene::Sceneclass
def enter()
puts "Press any key to continue"
print ">"
start = $stdin.gets.chomp
system ('clear')
puts "\n"
puts "You have successfully defeated the Wyvern!"
puts "\n"
sleep 1.5
put... | true |
c2b8a57af0b67648db159c83d522325334081b45 | Ruby | 97-Jeffrey/ruby-data-structure | /filter_array.rb | UTF-8 | 108 | 3.015625 | 3 | [] | no_license | numbers = Array[1,2,3,4,5]
filtered_numbers = numbers.select{|number| number.even?}
puts filtered_numbers
| true |
390f1620f710d584ec850efd986d98375645a731 | Ruby | r7kamura/syoboi_calendar | /lib/syoboi_calendar/song.rb | UTF-8 | 470 | 2.875 | 3 | [
"MIT"
] | permissive | module SyoboiCalendar
class Song
# @return [String]
attr_reader :name
# @return [Array<SyoboiCalendar::Personality>]
attr_reader :personalities
# @return [String]
attr_reader :role
# @param name [String]
# @param personalities [Array<SyoboiCalendar::Personality>]
# @param role [... | true |
21dd3494102289a0860dd390fa98149551dd32e8 | Ruby | thebravoman/software_engineering_2014 | /class017_test/files_for_exam_1/results/b/results/Veselina_Kolova_8_fc0f0c.rb | UTF-8 | 948 | 3.421875 | 3 | [] | no_license | =begin
Develop a program named FirstName_LastName_ClassNumber_fc0f0c.rb
1. you are given an argument for a folder with files;
1.1 if there are other arguments they should be discarded
2. some file names in this folder are in the form First_Last_digits.rb. But there are also other files;
3. find all the students that ... | true |
3fc6a46174a619c9e4bd91da426d92c4796c9251 | Ruby | ranska/courgette | /lib/courgette/feature.rb | UTF-8 | 943 | 2.578125 | 3 | [
"MIT"
] | permissive | module Courgette
class Feature
attr_reader :path
def initialize(path)
@path = path
end
def name
File.read(@path).to_s[/^Feature: (.+)$/, 1] || name_lines.first.split(':', 2).second.strip
end
def feature_elements_size
2
# FIXME !!!! broken by cucumber upgrade
... | true |
fce141288d132ac1b8623c2fbc7e8b83feb9aae1 | Ruby | icann-dns/puppet-webapp | /lib/puppet/parser/functions/unique_pip_packages.rb | UTF-8 | 1,214 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
# uniquepip_packages.rb
#
module Puppet::Parser::Functions
newfunction(
:unique_pip_packages, type: :rvalue, doc: <<-EOS
This function converts an array of pip package names to a hash of python::pip objects to be used with create_resources()
*Examples:*
flatten(['pip-package1',... | true |
a53465401c1491603d0776252a7be77b1954025d | Ruby | rsdesoto/ruby-practice | /ruby_collections/array_query.rb | UTF-8 | 269 | 3.40625 | 3 | [] | no_license | grocery_list = ["milk","eggs","bread","pie","potatoes"]
puts grocery_list[0]
puts grocery_list[3]
puts grocery_list.at(0)
puts grocery_list.first
puts grocery_list.last
grocery_list.insert(2,"oatmeal")
puts grocery_list.inspect
puts grocery_list.include?("pizza") | true |
06b4cfacd0c0b6fb0e9e3da01a2c0fae6d42000b | Ruby | ngeballe/ls-exercises-130 | /medium1/other files/block_review.rb | UTF-8 | 72 | 2.953125 | 3 | [] | no_license | def test
yield(1)
end
test do |num1, num2|
p "#{num1} #{num2}"
end
| true |
4843828febf59e6e2ec23ddb568e89eab0dc0817 | Ruby | dapi/module_import | /lib/module_import.rb | UTF-8 | 621 | 2.84375 | 3 | [
"MIT"
] | permissive | require "module_import/version"
# Попытка реализовать import а-ля es6
#
# importer на входе принимает название модуля. Создает абстрактный класс, инклюдит в него
# модуль и отдает инстанс. Типовое использование:
#
#
# Helpers = Importer.import TextHelper
#
# Helpers.truncate('text')
module ModuleImport
def self.impo... | true |
403de78ebc182dddab9fc7ed1e91a3a955fecff3 | Ruby | swistak35/nn_assignments | /assignment2/assgn2.rb | UTF-8 | 473 | 2.65625 | 3 | [] | no_license | require 'bigdecimal'
P_Pos_Sick = BigDecimal.new("0.99")
P_Neg_Sick = BigDecimal.new("0.01")
P_Pos_Healthy = BigDecimal.new("0.01")
P_Neg_Healthy = BigDecimal.new("0.99")
# P_Sick = BigDecimal.new("1e-3")
P_Sick = BigDecimal.new("1e-6")
P_Healthy = BigDecimal.new("1.0") - P_Sick
P_Pos = P_Pos_Sick * P_Sick + P_Pos_He... | true |
2c246fa665e498a02441974255113ded31fb1ea3 | Ruby | EdwardAndress/makers_academy_week3 | /lib/bike_container.rb | UTF-8 | 816 | 3.375 | 3 | [] | no_license | module BikeContainer #Describes the shared functionality of all objects in this domain which can contain bikes
DEFAULT_CAPACITY = 10
def initialize (capacity: DEFAULT_CAPACITY, bikes: [], location: [])
@capacity = capacity
@bikes = bikes
@location = location
end
attr_accessor :location, :capacity
def bike... | true |
3776ddd71a38c5fc9791f9b756c9f581d235126c | Ruby | Mattlk13/maglev | /src/test/testBlockGiven.rb | UTF-8 | 375 | 3.390625 | 3 | [] | no_license |
def test(a)
if block_given?
unless $HaveBlk == 1
raise 'ERR'
end
yield( [ 9 , 10, 11 , 12 ])
else
unless $HaveBlk == 0
raise 'ERR'
end
end
end
$HaveBlk = 1
test (1){ | a, *b |
unless a == 9
raise 'ERR'
end
unless b == [ 10, 11, 12]
raise 'ERR'
end
# puts a
#... | true |
d3f5e3572dcb5bd9bea1ce1d208cf30ce86c089e | Ruby | tamu222i/ruby01 | /tech-book/8/m-25.rb | UTF-8 | 413 | 2.84375 | 3 | [] | no_license | # 以下のコードを同じ意味のコードを選びなさい
def foo
puts "Hello"
end
# 1.class Object
# def foo
# puts "Hello"
# end
# end
#
# 2.class Object
# private
# def foo
# puts "Hello"
# end
# end
#
# 3.class Module
# def foo
# puts "Hello"
# end
# end
#
# 4.class Module
# private
# ... | true |
ae01adddcba2c139788596f693fffc884d277124 | Ruby | pkordel/uploadify_paperclip_demo | /vendor/plugins/delayed_job/lib/delayed/job.rb | UTF-8 | 4,899 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'timeout'
module Delayed
class DeserializationError < StandardError
end
# A job object that is persisted to the database.
# Contains the work object as a YAML field.
class Job < ActiveRecord::Base
set_table_name :delayed_jobs
named_scope :ready_to_run, lambda {|worker_name, max_run_time|
... | true |
131ab19a29f987486d2f9d658cb0475d283b5c11 | Ruby | weelliam/mpm-magic | /lib/abilities/nightmare.rb | UTF-8 | 453 | 2.890625 | 3 | [] | no_license | class NightmareAbility < Ability
def description
"The nightmare as a strenght and toughness equals to the number of Land you possess"
end
def value
return 8 if card.player.nil?
card.player.lands.size
end
def toughness(original)
return original if card.player.nil?
original + card.player... | true |
738a6c7a47e773469ad57728ffdb2c9b8cb789e2 | Ruby | somleng/adhearsion-twilio | /spec/adhearsion/twilio/gather_spec.rb | UTF-8 | 24,038 | 2.609375 | 3 | [
"MIT"
] | permissive | require "spec_helper"
RSpec.describe Adhearsion::Twilio::ControllerMethods, type: :call_controller do
describe "<Gather>" do
# From: https://www.twilio.com/docs/api/twiml/gather
# The <Gather> verb collects digits that a caller enters into
# his or her telephone keypad. When the caller is done entering ... | true |
4decb4731869adb9a608f035d58143a1f546cfee | Ruby | bachmarc/ev3dev_ruby_stretch | /examples/sensor/color.rb | UTF-8 | 930 | 3.015625 | 3 | [
"MIT",
"CC0-1.0",
"Unlicense"
] | permissive | #!/usr/bin/ruby
# LEGO EV3 Color Sensor (45506)
# http://www.ev3dev.org/docs/sensors/
# http://www.ev3dev.org/docs/sensors/lego-ev3-color-sensor/
# http://www.ev3dev.org/docs/drivers/lego-sensor-class/
require 'ev3dev'
col = Ev3dev::Sensor.new 3
p col.device_path #=> "/sys/class/lego-sensor/sensor2"
p col.driver_n... | true |
2a86442d779a1bf2055246a413f144157334161e | Ruby | eflores0227/Bloc_Record | /lib/bloc_record/assignment_3.rb | UTF-8 | 648 | 2.65625 | 3 | [] | no_license | def find_by(contact, contact_id)
shows = connection.execute <<-SQL
SELECT #{contact} FROM #{table}
WHERE contact_id = #{contact_id}
SQL
shows
end
def find_each(hash)
rows = connection.execute <<-SQL
SELECT #{column.join(",")} FROM #{table}
WHERE id = #{hash[:start]} LIMIT #{hash[:batch_size]}
... | true |
5e0ce82969d550c26e33830a313b50aafed29fd9 | Ruby | hoodielive/ruby | /old/control-structures/control-structures-ternary.rb | UTF-8 | 146 | 3.4375 | 3 | [] | no_license | #!/usr/bin/env ruby
#
#if boolean
# code 1
#else
# code 2
#end
#
#
#instead write:
#
#boolean? code1 : code2
#puts x == 1 ? "one" : "not one"
| true |
330b5e84a4c0be21e49c1a0b918c2cca0d1e4ad1 | Ruby | hermesalexis/ruby | /blackjack.rb | UTF-8 | 3,705 | 4.4375 | 4 | [] | no_license |
#¿Cómo representamos una carta? Figura y valor.
#¿Cómo representamos una baraja? 52 Cartas.
#¿Cómo representamos las cartas que tiene el jugador y el repartidor?
class Card
attr_reader :suit, :value
def initialize(suit, value)
@suit = suit
@value = value
end
def value
return 10 if ["J... | true |
912003f39e0f46185974a52acfd84b1088d428f3 | Ruby | grantr/dcell-gossip | /lib/dcell/gossip/messages.rb | UTF-8 | 1,058 | 2.53125 | 3 | [
"MIT"
] | permissive | module DCell
module Gossip
class RequestMessage
attr_reader :reply_to, :digest
def initialize(reply_to, digest)
@reply_to = reply_to
@digest = digest
end
def dispatch
#puts "received #{self.class.name}: #{digest.inspect}"
Celluloid::Actor[:gossiper].handl... | true |
ae9048baacd03f83943928ee70367cb52644dd8b | Ruby | Zlatov/lab | /rails/_tasks/layers/services/person_service.rb | UTF-8 | 728 | 2.640625 | 3 | [] | no_license | # class PersonService
# def create(params)
# lat, lng = Geocoder.coordinates(params[:address])
# username = params[:username].strip.downcase
# color = params[:color] || Person::DEFAULT_COLOR
# prepared_params = params.merge(
# lat: lat, lng: lng,
# color: color, username: username
# )... | true |
796bd74f47c6a8fa6d337dec48cd6d069cfded8a | Ruby | andersoncmartins/test_like_a_hero | /spec/models/weapon_spec.rb | UTF-8 | 1,254 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Weapon, type: :model do
it 'is invalid if the level is not between 1 and 99' do
weapon = build(:weapon, level: Random.rand(100..9999))
expect(weapon).to_not be_valid
end
it 'is invalid if the power_step is not equal 100' do
weapon1 = build(:weapon, power_step: ... | true |
e525d885430f00b7d45cbf8cb063a15e08d9c28b | Ruby | adslyw/record | /lib/record/result.rb | UTF-8 | 1,047 | 2.96875 | 3 | [
"MIT"
] | permissive | module Record
class Result
include Enumerable
attr_reader :columns, :rows
def initialize(columns, rows)
@columns = columns
@rows = rows.map{ |row| Row.new(row)}
end
alias :length :count
def length
@rows.length
end
def each
if block_given?
@rows.each { |... | true |
ff66fdbe8623e906d3e3aca98de9f57ee8073956 | Ruby | chussenot/Delivery-Router-Problem | /lib/tasks/bench.rake | UTF-8 | 1,409 | 2.515625 | 3 | [] | no_license | def dat_file(type)
name = "tmp/#{type}.dat"
File.open(name, 'w').tap do |f|
f.write("# #{type}\n")
end
end
def new_delivery_router
customers = [
Customer.new(id: 1, x: 1, y: 1),
Customer.new(id: 2, x: 5, y: 1)
]
restaurants = [
Restaurant.new(id: 3, cooking_time: 15, x: 0, y: 0),
Restau... | true |
b3aaee9f7b4c67fef1b11d8731189deb8e5a17b9 | Ruby | ioquatix/samovar | /lib/samovar/table.rb | UTF-8 | 1,539 | 2.890625 | 3 | [
"MIT",
"LicenseRef-scancode-dco-1.1"
] | permissive | # frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2016-2023, by Samuel Williams.
module Samovar
class Table
def self.nested(klass, parent = nil)
if klass.superclass.respond_to?(:table)
parent = klass.superclass.table
end
self.new(parent, name: klass.name)
end
def ... | true |
b4d4a5eaa76bd91210a1b384e37622c1305d686e | Ruby | hwangtamu/CSCE606AnswerKey | /hw1/q3.rb | UTF-8 | 963 | 3.3125 | 3 | [] | no_license | class RockPaperScissors
# Exceptions this class can raise:
class NoSuchStrategyError < StandardError ; end
def self.winner(player1, player2)
# if ((player1[1].match(/[PSR]/)&&(player2[1].match(/[PSR]/) ) ) )
if(! "RPS".include? player1[1])
raise NoSuchStrategyError, "Strategy must be one of R,P,S"
en... | true |
78a6f7f24837683d38aa3085b61a4a9b6fae603b | Ruby | GrayMyers/rails-engine | /spec/requests/api/v1/revenue/total_revenue_spec.rb | UTF-8 | 2,204 | 2.71875 | 3 | [] | no_license | require 'rails_helper'
describe "getting a merchant's total revenue", type: :request do
before :each do
@merchant = Merchant.create(name: "me")
@merchant_2 = Merchant.create(name: "not me")
item = Item.create(name: "item sold", description: "item has been sold and will count towards revenue", unit_price... | true |
4b1d8e8493dda662e34e0706fd6db09a2fddd210 | Ruby | bmolina-nyc/sinatra-nested-forms-v-000 | /app/models/pirate.rb | UTF-8 | 241 | 2.828125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pirate
attr_accessor :name, :weight, :height, :ships
PIRATES = []
def initialize(params)
@name, @weight, @height, @ships = params["name"], params["weight"], params["height"], params["ships"]
PIRATES << self
end
end | true |
e372b1f935d0dc6ccc8acd26b47fe63caa0c093e | Ruby | ymhuang0808/ruby-self-practice | /exception_rescue.rb | UTF-8 | 298 | 3.390625 | 3 | [
"Unlicense"
] | permissive | def inverse(x)
1 / x
end
begin
STDOUT.flush
var_x = gets.chomp
var_x = var_x.to_i
puts "1 / #{var_x} = #{inverse(var_x).to_s}"
rescue ArgumentError => e
puts "in rescue, Exception type: #{e.class.name}"
rescue Exception => e
puts "in else rescue, Exception type: #{e.class.name}"
end | true |
6543f72f44b703b4c1685c34079500f88c42b7f8 | Ruby | JamieReid1/week_03_day_2_crud_quiz_homework | /crud_quiz_homework.rb | UTF-8 | 2,027 | 3.71875 | 4 | [] | no_license |
# Q1. Where are we instantiating instances of the Property class?
On lines 6, 15, 24 of console.rb.
# Q2. Where are we defining the SQL that enables us to save the ruby Property object into the database?
On lines 18-29 of property.rb.
# Q3. In console.rb, which lines modify the database?
Lines 4, 13,... | true |
5ae8fad4ceb8b77396a2ed372ef332e7645d6249 | Ruby | gadgetism/bindadmin | /webapp/lib/regex/dns.rb | UTF-8 | 2,023 | 2.609375 | 3 | [
"BSD-3-Clause",
"BSD-2-Clause"
] | permissive | module Regex
class Dns
def self.check_characters(name)
return true
end
def self.check_domain_name(name)
return (name =~ /^([-a-z0-9]+\.)+[a-z]{2,}$/) != nil
end
def self.check_master(master)
if self.check_domain_name(master)
return true
elsif self.check_ipv4(master)
return true
e... | true |
0384ef3a198eec7ad43dc8779e00683b2ae2e421 | Ruby | TheMartinCrabtree/programming-univbasics-4-square-array-dumbo-web-071519 | /lib/square_array.rb | UTF-8 | 170 | 3.109375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
counter = 0
returnArray = []
while(array[counter])
returnArray[counter] = array[counter]**2
counter += 1
end
return returnArray
end | true |
cf824f138e5ccc209cac5da6118987bc952571c9 | Ruby | tkimana/todo-ruby-basics-houston-web-career-021819 | /lib/ruby_basics.rb | UTF-8 | 233 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def division(num1, num2)
puts 4 \ 2
end
def assign_variable(value)
puts = "Hello World!"
end
def argue
end
def greeting
puts "Hello World!"
end
def return_a_value
end
def last_evaluated_value
end
def pizza_party
end | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.