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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
78113bee45fe8d22ce58465a705ab62d4dbe7c17 | Ruby | meedan/check-api | /config/initializers/field_formatters.rb | UTF-8 | 1,598 | 2.53125 | 3 | [
"MIT"
] | permissive | # Define field formatters for our various dynamic field types.
DynamicAnnotation::Field.class_eval do
def field_formatter_type_language
code = self.value.to_s.downcase
CheckCldr.language_code_to_name(code)
end
def field_formatter_name_response_multiple_choice
response_value(self.value)
end
def... | true |
b15efcef49f949238eee3e1dac851c5813d5f4c8 | Ruby | vickerdj/ruby | /02_calculator/calculator.rb | UTF-8 | 359 | 3.5 | 4 | [] | no_license | def add(a,b)
a + b
end
def subtract(a,b)
a - b
end
def sum(array)
i = 0
total = 0
while i < array.length
total += array[i]
i += 1
end
total
end
def multiply(a,b)
a * b
end
def power(a,b)
i = 1
while i <= b
a *= a
i += 1
end
end
def factorial(a)
i = a - 1
whil... | true |
603ed0e2e9b53809e34ad53073b7059beb8e308f | Ruby | hull/hull-ruby | /lib/hull.rb | UTF-8 | 1,455 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'hull/client'
require 'hull/config'
module Hull
extend Config
class << self
# Alias for Hull::Client.new
#
# @return [Hull::Client]
def new(options={})
Hull::Client.new(options)
end
def as(user)
as_user(user)
end
def as_user(user)
if user.is_a?(String)
... | true |
44ccf835311cd7b50f05738cf77ae3a7ff144ff6 | Ruby | brantpastore/May_Tic_Tac_Toe | /lib/tic_tac_toe_board.rb | UTF-8 | 2,758 | 3.578125 | 4 | [] | no_license | require 'board'
class TicTacToeBoard < Board
class InvalidPiece < Exception ; end
attr_reader :x_mark, :o_mark
VALID_PIECES = ['X', 'O'].freeze
def initialize(length = 3)
@length = length
super(length * length)
@x_mark = "X"
@o_mark = "O"
end
def game_over?
full? || !row_winner.nil?... | true |
5b2e41ae19ff962a6afde2333df5324a042e9726 | Ruby | aluisribeiro/envoice-ruby-example | /test/models/item_test.rb | UTF-8 | 701 | 2.578125 | 3 | [] | no_license | require 'test_helper'
class ItemTest < ActiveSupport::TestCase
test "should calculate the total" do
item = Item.new(product: Product.new, amount: 10, product_price: 20)
assert_equal 200, item.total
end
test "should validate the item" do
item = Item.new(product: Product.new, envoice: Envoice.new, am... | true |
1ba70a39888d9306cc134496bc9e3b2d7fd3c174 | Ruby | tchartchke/purkamyern | /lib/purkamyern/pokemon.rb | UTF-8 | 510 | 2.734375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class Purkamyern::Pokemon
attr_accessor :name, :types, :id
@@all = Set.new
def initialize(attributes)
@name = attributes['name']
@id = attributes['id']
@types = []
attributes['types'].each do |t|
type = t['type']['name']
@types << type
end
@@all... | true |
1b61d5e5c4bdca2f43e909559c97806eac273120 | Ruby | brady-robinson/ls-rb101 | /small_problems/easy9_6.rb | UTF-8 | 1,306 | 4.5 | 4 | [] | no_license | # problem: take a string and make an array with each word and its
# length represented as separate strings
# data: string, array
# facts: non-alphanumeric characters do not count (not true)
# examples:
# word_lengths("cow sheep chicken") == ["cow 3", "sheep 5", "chicken 7"]
# word_lengths("baseball hot dogs and ap... | true |
e35ff1eafd61c459c43dc3d8d933a36e1ad95f59 | Ruby | MigueCc99/DS | /P1/S1/RUBY/lib/bicicleta_montana.rb | UTF-8 | 696 | 2.890625 | 3 | [] | no_license | # To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
require_relative("bicicleta.rb")
module Practica1
class BicicletaMontana < Bicicleta
@@contador_bicicleta = 0
def clone()
... | true |
1611ce4fd7492e775796e155f08a3a3137822f59 | Ruby | valesil/QE_training_BDT_ruby | /Silvia/Practices/Session 7/Singleto_practice.rb | UTF-8 | 604 | 3.28125 | 3 | [] | no_license | class Guest
attr_accessor :user
attr_reader :hash
attr_reader :visitors
def initialize
@user = "Guest"
@message = "Welcome to the city"
@visitors = 0
@hash = {}
@hash [@user] = @message
end
def add_to_hash
@user = gets.chomp
@message = gets.chomp
@visitors ... | true |
f699cb7c1dcaddac1c80dfd3ac482b93bdb9eb74 | Ruby | sherylhodgson/skillcrush-ruby-challenges | /love_notes.rb | UTF-8 | 228 | 3.40625 | 3 | [] | no_license | puts 'Are roses red? Are violets blue? Is sugar sweet?'
answer = gets.chomp.downcase
while (answer.downcase == 'y')
puts 'I love you'
puts 'Are roses red? Are violets blue? Is sugar sweet?'
answer = gets.chomp.downcase
end | true |
5347212cd5669b2d552c61a75cb83e5444d1fdaa | Ruby | ThePurplePanda/fantasy_on_rails | /app/models/team.rb | UTF-8 | 3,519 | 2.828125 | 3 | [] | no_license | require 'open-uri'
class Team < ActiveRecord::Base
belongs_to :league, inverse_of: :team
has_and_belongs_to_many :trade, inverse_of: :team
has_many :player, inverse_of: :team, dependent: :destroy
def make_players(scraped_players, scraped_values)
scraped_players.select{|p| p[:team] == self.number... | true |
3d08710fedf832229209eddf35942bc030784ee8 | Ruby | foxnewsnetwork/drunken-octo-tyrion | /app/helpers/orders_helper.rb | UTF-8 | 356 | 2.703125 | 3 | [] | no_license | module OrdersHelper
def mtilify material
price = material.unit_price
price = price.abs <= 0.000001 ? 'unknown' : price.abs unless price.is_a? String
{
:image => "http://placehold.it/150x100" ,
:header => material.name ,
:content => material.mass.to_s + " @ $#{price} per #{material.units}" ,
:link => ... | true |
cdaff0b1130661dcde46b40acd75640f79984610 | Ruby | ilanusse/bio-info | /ex1.rb | UTF-8 | 587 | 3.109375 | 3 | [
"MIT"
] | permissive | require 'bio'
if ARGV.length < 1
puts 'Please add an input file.'
exit 1
elsif ARGV.length > 2
puts 'Please do not add any extra parameters'
exit 1
end
INPUT_FILE = ARGV[0]
OUTPUT_FILE = ARGV[1] || 'ex1result.fas'
puts "Reading from #{INPUT_FILE}..."
begin
entries = Bio::GenBank.open(INPUT_FILE)
rescue => ... | true |
32042aea03e265c11a2a9eecea7997452ef983f7 | Ruby | byelipk/exercism-ruby | /say/say.rb | UTF-8 | 852 | 3.734375 | 4 | [] | no_license | class Say
attr_reader :number, :chars, :db
def initialize(n)
@number = n
@chars = hashmap.build
@db = Database.new
end
def in_english
db.lookup[number]
end
def hashmap
@hashmap ||= Hashmap.new(number)
end
end
class Hashmap
attr_reader :n
def initialize(n)
@n = n
end
... | true |
1076d876a2194942f075e14684630575401a5bb3 | Ruby | ladamesny/blog_rails4 | /app/models/user.rb | UTF-8 | 2,153 | 3.140625 | 3 | [] | no_license | require 'digest'
class User < ActiveRecord::Base
#This creates an accessor (variable) that will allow you to set the password before it's encrypted
#Remember, there is no "password" column on your database.
attr_accessor :password
validates_uniqueness_of :email
validates_length_of :email, within: 5..50
va... | true |
b4b8a94ba6d212a6259482071b5d7e8efca46cb9 | Ruby | CarlosAndres22/IronHack-1 | /Pre-Work/age_round.rb | UTF-8 | 73 | 3.625 | 4 | [] | no_license | age = 28
puts age.round(-1) # returns 30
puts age.round(1) # returns 28.0 | true |
39f260b024a612f657ace54e8ce3b8f63cb71989 | Ruby | pixelastic/pdf | /lib/command_helper.rb | UTF-8 | 473 | 2.84375 | 3 | [] | no_license | require 'awesome_print'
require 'open3'
# Simplified access to shell commands
module CommandHelper
# Returns true if the specified command exits with 0, false otherwise
def command_success?(command)
return false if command.empty?
_, _, status = Open3.capture3(command)
status.success?
end
# Returns... | true |
af5aceabbe5416d758764134b63c0c39db3f6bde | Ruby | n-ihm/rubiks_cube | /lib/view.rb | UTF-8 | 1,955 | 3.375 | 3 | [] | no_license |
class View
def initialize(cube)
@name = cube
@seiten = @name.get_cube
end
private
#ktr 17. 07
def disp_singl(sidenum, highl = nil)
z1 = 1
#zahlenblock breite 5, spacing 4
print " "
while z1 <= 9
if highl == z1 - 1
print "\033[7m#{@seiten[sidenum... | true |
355eb51fa6ae728280e89032aa33aa6d9b6cb523 | Ruby | tbowzz/advent_of_code_2020 | /day_05.rb | UTF-8 | 972 | 3.328125 | 3 | [] | no_license | text = File.open('day_05_input.txt').read
seats = []
text.each_line do |raw|
seats.push(raw.strip)
end
max_id = 0
seat_ids = []
seats.each do |seat|
rows = (0..127).to_a
cols = (0..7).to_a
seat.split('').each do |position|
split_point = (rows.length / 2)
if position == 'F'
rows = rows[0..split_po... | true |
71cb0fa2877edb5092d9789661c51d011eac4a95 | Ruby | kimnorth/codeclan_snakes_ladders | /snakes_ladders/dice.rb | UTF-8 | 133 | 2.828125 | 3 | [] | no_license | class Dice
attr_reader :dice_face
def initialize
@dice_face = 1
end
def roll_dice
return rand(1..6)
end
end | true |
c35aa680b723b7356a897fc98fdac2d8f2d8fa10 | Ruby | namdevlife/looping-for-online-web-prework | /for.rb | UTF-8 | 101 | 3.015625 | 3 | [] | no_license |
def using_for
checklist = 1..10
#your code here
for checklist in (1..10)
puts "Wingardium Leviosa"
end
end
| true |
c9b2d47c0e544fc4a596c21b5f5efbfbddeebc35 | Ruby | thestrauss3/CodeWars | /ruby/AnotherCamelCaseMethod.rb | UTF-8 | 1,075 | 4.25 | 4 | [] | no_license | # Description:
#
# Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized.
#
# Examples:
#
# # returns "theStealthWarrior"
# to_camel_case("the-stealth-warrior")
#
# # returns "T... | true |
e511cd1cba718a3ea48413c1b2bbec7c2f77d4c8 | Ruby | sunoko/ruby-grimoire | /mokey_patch.rb | UTF-8 | 255 | 3.1875 | 3 | [] | no_license | #==============================
#
# モンキーパッチ
# (既存クラスの振る舞いを変更)
#
#==============================
p "abc".reverse #=> "cba"
class String
def reverse
"monkey patch"
end
end
p "abc".reverse #=> "monkey patch"
| true |
3122083bfddcf47e189fd475f5f599492692a573 | Ruby | srebalaji/100DaysOfAlgorithm | /day46/match_sum_of_arrays.rb | UTF-8 | 548 | 3.859375 | 4 | [] | no_license | # Given two array of integers, swap two numbers so that the sum of two arrays must be same.
ar1 = [4,1,2,1,1,2]
ar2 = [3,6,3,3]
ha1 = {}
ha2 = {}
def add_to_hash_sum_it(arr, ha)
sum = 0
arr.each do |ar|
sum += ar
if ha.key? ar
ha[ar] += 1
else
ha[ar] = 1
end
end
return sum
end
su... | true |
7ea390469e1b26d26ef722962860adee1e0480be | Ruby | jorgemolinan/lab | /regex4_identificadores.rb | UTF-8 | 643 | 3.5 | 4 | [] | no_license | # 1. \d es equivalente a /[0-9]/
# 2. \D es equivalente a /[^0-9]/
# 3. \w es equivalente a /[a-zA-Z0-9_]/ (cualquier letra o número)
# 4. \W es equivalente a /[^a-zA-Z0-9_]/ (cualquier letra o número al comienzo)
# 5. \s espacio (espacio, indentación, salto de línea, ...)
# 6. \b límite de palabra (inicio o fin de una... | true |
cf4b8b3caa2135cef25ab72d9961b1e78b2db259 | Ruby | celestelayne/CHI_BEWD1 | /Week3/Lesson1/Homework/assignments/kent_green/kg_apartment_objects/lib/building.rb | UTF-8 | 599 | 3.53125 | 4 | [] | no_license | #Building Class
class Building
#first you have to have the attr_accessor
attr_accessor :building_name, :building_address, :apartments #these are the class-level variables
#next we have to initialize, so that all of our variables will be required
def initialize(building_name, building_address, apartments=[]) #para... | true |
81682958b111ca8abd8559ba4e4dfd38a9613e88 | Ruby | tiabas/oauth2-provider | /lib/oauth2-provider/request.rb | UTF-8 | 2,680 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'addressable/uri'
module OAuth2Provider
class Request
RESPONSE_TYPES = [:code, :token]
GRANT_TYPES = [:authorization_code, :password, :client_credentials, :refresh_token]
attr_reader :response_type, :grant_type, :client_id, :client_secret, :state, :scope,
:errors, :username, :... | true |
6681bfe7a051cf6d4a260abb1747742e70d3ec9c | Ruby | roseliux/ruby-coding-exercises | /sum_array_spec.rb | UTF-8 | 296 | 3.21875 | 3 | [
"MIT"
] | permissive | def sum(array)
array.inject(0){ |sum, e| sum += e }
end
describe 'sum' do
it 'returns the sum of the elements of given array' do
expect(sum([])).to eq(0)
expect(sum([-1, 1])).to eq(0)
expect(sum([1, 2, 3])).to eq(6)
expect(sum([1, 2, 34, 5, 6, 7, 8, 9])).to eq(72)
end
end
| true |
1a20a03b8c79682117a54528772646acce50cd8b | Ruby | mcmire/super_diff | /lib/super_diff/object_inspection/inspection_tree.rb | UTF-8 | 6,458 | 2.609375 | 3 | [
"MIT"
] | permissive | module SuperDiff
module ObjectInspection
class InspectionTree
include Enumerable
def initialize(disallowed_node_names: [], &block)
@disallowed_node_names = disallowed_node_names
@nodes = []
instance_eval(&block) if block
end
Nodes.registry.each do |node_class|
... | true |
a49fa0dc9e704f8ceb245820784e41fa8e52f1a7 | Ruby | Sakura-Hirokawa/Ruby_2 | /lesson2.rb | UTF-8 | 81 | 2.921875 | 3 | [] | no_license | puts "私の名前は"+"sakura"+"です。"
puts "年齢は"+23.to_s+"です。"
| true |
9be8ab1479182581436867481af79846dc1cc7b0 | Ruby | rcalves82/CucumberBasic | /Exemplo1/imc/src/imc.rb | UTF-8 | 279 | 2.640625 | 3 | [] | no_license | class Imc
def calcula(peso, altura)
imc = (peso.to_i / (altura.to_f * 2)).round(2)
if imc > 22
return 'IMC deu ruim. #PartiuAcademia #NoPainNoGain'
else
return 'IMC Ok. #PartiuBK'
end
end
end | true |
f6b7833da23da41335659057c149660aa7a71ff4 | Ruby | toddt67878/udemy-learn-to-code-with-ruby | /METHODS/Parameters_and_arguments.rb | UTF-8 | 807 | 4.03125 | 4 | [] | no_license | #Argument is an input to a method
def person(name)
puts "#{name} is amazing"
puts "#{name} is charming"
puts "#{name} is talented"
end
#When calling the method we need to add the name as well to make it work,
#see below:
person ("Aga")
person ("Dave")
person ("Marta")
person "Pizza" # will work as well although ... | true |
6e03dc0da7fb72f1933accc02201cb222447f722 | Ruby | MelanieS/ptraj_Builder | /step_time.rb | UTF-8 | 3,798 | 3.21875 | 3 | [] | no_license | #ruby 2.2.1p85 (2015-02-26 revision 49769)
#energies files must contain time on left column, energy on right, separated by space
#change paths on line 73
#This opens the energies file, and splits it into an array at newlines
energies = Dir.glob('*energies.txt')
energies = energies.pop
text = File.open(energies).read
t... | true |
5ddfb99d336fd2c12c7491b2b0bc6ce32cf2494a | Ruby | michelemendel/misc | /projects/pgt/src/ranking.rb | UTF-8 | 1,546 | 3.375 | 3 | [] | no_license | #
# Ranking
#
# Author:: Michele Mendel
# Date:: Oslo 2009-05-11
#
# Ranking:
# 1. Number of points in all matches
# 2. Number of points in the internal matches between teams with a equal number of points
# 3. Best goal difference in all matches
# 4. Most goals scored in all matches
#
require 'pp'
requir... | true |
0f4cf4af456b8dba34fca2354cb0603255ca793f | Ruby | hegyi/isbn_tool | /lib/isbn_tool/group.rb | UTF-8 | 299 | 2.71875 | 3 | [
"MIT"
] | permissive | module IsbnTool
class Group
attr_reader :prefix, :group_id
attr_accessor :rules
def initialize(group_text)
@prefix, @group_id = group_text.split("-")
@rules = []
end
def add_rule(rule)
@rules += Array(rule)
end
alias :add_rules :add_rule
end
end
| true |
207a0fd51dc2cdfb2b4390882903386f165b054d | Ruby | gangelo/com.realcruiter | /app/services/crypted_uri_token_creator.rb | UTF-8 | 1,641 | 2.953125 | 3 | [] | no_license | require 'openssl'
require 'base64'
require 'uri'
class CryptedUriTokenCreator
def initialize(text, action=:encrypt, params={context: nil, key: nil})
@text = ensure_text(text)
@action = ensure_action(action)
@context = ensure_context(params[:context])
@key = ensure_key(params[:key])
end
def exec... | true |
fd7d7f3efa170081d7cce854e75a9d07006e1ecb | Ruby | niaeashes/ume | /spec/models/pokemon_spec.rb | UTF-8 | 3,426 | 2.640625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Pokemon, type: :model do
describe "is valid" do
context "with name" do
subject { build :pokemon, name: name }
let(:name) { "mew" }
it { is_expected.to be_valid }
end
context "without name" do
subject { build :pokemon, name: nil }
it {... | true |
27f625d81ecab0e825b1a2265df6b5d889351e43 | Ruby | brodock/DW-ETL | /lib/old/re_test.rb | UTF-8 | 2,156 | 3.046875 | 3 | [] | no_license | require "rubygems"
require "xml"
require "benchmark"
puts "Importador de XML para base relaciona MySQL"
class ParserXML
attr_reader :files, :tags, :xml
MAX_AMOUNT_OF_FILES = 1000
def initialize
@path = "/Users/brodock/Projetos/XML"
@files = Dir.glob("#{@path}/*.xml")
end
def parse_libxml
resul... | true |
60dbb27b6dfd60d81d2e99f9b9c330113b2de508 | Ruby | sumnerjj/antcat | /app/models/rank.rb | UTF-8 | 3,132 | 3.28125 | 3 | [] | no_license | # coding: UTF-8
class Rank
def initialize hash
@hash = hash
end
def string
@hash[:string]
end
def display_string
string.titlecase
end
def uncommon?
@hash[:uncommon]
end
# Returns only Genus for species and Family for genus.
# Can't take subfamily or subgenus into consideration.
... | true |
b52a2548ad5c8d14b841a26f7d7abc5fe2a80e0f | Ruby | takagotch/ruby1 | /LIST/01BigFloat/P012to_b.rb | SHIFT_JIS | 491 | 3.75 | 4 | [] | no_license | #!/usr/local/bin/ruby
# to_b.rb
# Usage: to_b n value
# value must be 0.xxxx
#
require "BigFloat"
n = ARGV.shift.to_i
v = BigFloat.new(ARGV.shift)
b = BigFloat.new("1.0")
if v >= b
raise "2Ԗڂ̈͂PȉɂĂˁI"
end
t = BigFloat.new("0.0")
s = "0."
n.times {
b = b/2.0
if t+b > v
s = s + "0"
elsif t+b < v
s ... | true |
b045f82fa2090fa046edfbbae6f28abf5210d8cd | Ruby | pdavidow/MetronomeApp | /test/unit/tick_test.rb | UTF-8 | 3,216 | 2.625 | 3 | [] | no_license | require 'test_helper'
class TestTick < ActiveSupport::TestCase
def test_state
Mongoid.purge!
u1 = User.create(email:'u1@user.com', password:'qewr5675jkljgrty')
p1 = u1.pieces.create(name: 'a', composer: 'c1')
p1.measures.push(Measure.new)
p1.measures.last.beats.push(Beat.new(rh:3, lh:4))
u1 ... | true |
196d0963b95848b6a81e62327d64afaa6ebe1d6c | Ruby | dingzishidtc/dzPython | /ruby.rb | UTF-8 | 979 | 2.9375 | 3 | [] | no_license | #!/usr/bin/ruby -w
# -*- coding : utf-8 -*-
# require 'rubygems'
# require 'selenium-webdriver'
# # driver = webdriver.Chrome("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe")
# driver = Selenium::WebDriver.for :Chrome
# driver.navigate.to "http://baidu.com"
# sleep 3
# element = driver.fi... | true |
e4fbce93c7b0f79b6fb0963466616eddb3d1949c | Ruby | ellenlt/WA | /Project2/group.rb | UTF-8 | 926 | 4.28125 | 4 | [] | no_license | require 'set'
module Enumerable
=begin
This method is an iterator that yields two items at a time:
a one-character string and an array of all input values
starting with that character.
=end
def each_group_by_first_char
used_ch = Set.new
self.each_entry do |entry|
next if entry.empty?
ch = entry[0]
if ... | true |
a9d20ca15287552ade585e98df2d64a4faab57dc | Ruby | seand08/ruby_practice | /five_numbers.rb | UTF-8 | 468 | 4.15625 | 4 | [] | no_license | puts "Give me 5 numbers."
first = gets.chomp.to_i
second = gets.chomp.to_i
third = gets.chomp.to_i
fourth = gets.chomp.to_i
fifth = gets.chomp.to_i
my_array = [first, second, third, fourth, fifth]
sum = 0
product = 1
my_array.each do |x|
sum += x
end
my_array.each do |i|
product *= i
end
puts "The Sum is " +... | true |
7eb646db5e908346bd6861f02eb310e31a151246 | Ruby | abishekaditya/exercism | /ruby/raindrops/raindrops.rb | UTF-8 | 311 | 3.125 | 3 | [] | no_license | module BookKeeping
VERSION = 3
end
# number to string based on factors
class Raindrops
def self.convert(number)
str = ''
str += 'Pling' if (number % 3).zero?
str += 'Plang' if (number % 5).zero?
str += 'Plong' if (number % 7).zero?
str == '' ? number.to_s : str
end
end
| true |
d76fb36434c31079d4efc75696c427f46b15e4cc | Ruby | josiahsp/wallerhill | /app/models/address.rb | UTF-8 | 425 | 2.6875 | 3 | [] | no_license | class Address < ActiveRecord::Base
belongs_to :user
validates_presence_of :name, :address1, :city, :state, :zip, :phone
def array
address = [self.name]
if self.company.present?
address << self.company
end
address << self.address1
if self.address2.present?
address << self.address2
end
... | true |
cc1aa9a1babc3ad7b830db4c1ffb8867359f0736 | Ruby | berga/hacker_news_stats | /lib/hacker_news_stats/gui/cli/application.rb | UTF-8 | 942 | 2.53125 | 3 | [
"WTFPL"
] | permissive | require "awesome_print"
module HackerNewsStats
module Gui
module Cli
class Application
def initialize(posts)
@posts = posts
end
def display
puts "Hacker News Stats - Latest posts and user's statistics\n--------------"
@posts.each do |post|
... | true |
3c7f2511b7af649283bf2aeed5b3c463a3996537 | Ruby | tiagoit/code-challenges | /hackerrank/27-insertion-sort-2/solve.rb | UTF-8 | 694 | 4.09375 | 4 | [] | no_license | # https://www.hackerrank.com/contests/microverse-coding-challenges/challenges/insertionsort2
# 27 - Insertion Sort 2 - 20191020
def insertion_sort n, arr
# puts arr.join(' ')
# puts
(n - 1).times do |i|
j = i
while arr[j + 1] < arr[j] && j >= 0
arr[j], arr[j + 1] = arr[j + 1], arr[j]
j -= 1
... | true |
517be8fe261ce3ad3b200bbe5e4dc77cdc1bf8ac | Ruby | carojane/bank_account | /account.rb | UTF-8 | 671 | 3.125 | 3 | [] | no_license | class Account
attr_reader :name, :starting_balance
def initialize(name, starting_balance)
@name = name
@starting_balance = starting_balance.to_f
end
def current_balance
@current_balance = @starting_balance
CSV.foreach('bank_data.csv', headers: true) do |row|
if row['Account'] == @name
... | true |
03b97c3b81443f0bfe78f25cc574182337ae55cc | Ruby | leo-orellana/gustavo-o | /iteracion-02/ejercicios/snaker.rb | UTF-8 | 103 | 3.046875 | 3 | [] | no_license | class Snaker
def snakear(input)
if input == "holamundo"
"HoLaMuNdO"
else
""
end
end
end
| true |
d1a7f412a2158fcc7ba9d99792070d3cffc9d83b | Ruby | hiki/hiki | /lib/hiki/pluginutil.rb | UTF-8 | 3,964 | 2.890625 | 3 | [] | no_license | #
# apply_plugin(str):
# Eval the string as a plugin.
#
# methodwords(str):
# Separte a string to a method and arguments for plugins.
#
# Copyright (C) 2004 Masao Mutoh <mutoh@highway.ne.jp>
#
# Based on shellwords.rb(in ruby standard library).
require "cgi" unless Object.const_defined?(:Rack)
require "erb"
module ... | true |
00af18bf63ad162002507b15044d9a8b4e3137cf | Ruby | filinivan/thinknetica | /5/station.rb | UTF-8 | 617 | 3.328125 | 3 | [] | no_license | class Station
attr_reader :name, :trains
@@stations = []
include InstanceCounter
def initialize(name)
@name = name
@trains = []
@@stations << self
register_instance
end
def self.all
@@stations.each.with_index(1) {|station, x| puts "#{x} - #{station.name}"}
end
def add_train(train)... | true |
1cf21b767df655c225d9495aa84541161f203cf0 | Ruby | drunkwater/leetcode | /medium/ruby/c0178_357_count-numbers-with-unique-digits/00_leetcode_0178.rb | UTF-8 | 647 | 3.65625 | 4 | [] | no_license | # DRUNKWATER TEMPLATE(add description and prototypes)
# Question Title and Description on leetcode.com
# Function Declaration and Function Prototypes on leetcode.com
#357. Count Numbers with Unique Digits
#Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.
#Example:
#Given n = 2... | true |
4f55ec28800d06e9fe8982d965825a4dffa43dc5 | Ruby | nullkal/mastodon_healthchecker | /lib/mastodon_healthchecker/hash_hosts.rb | UTF-8 | 2,985 | 2.703125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
##
# Copyright (C) 2017 nullkal.
#
# This program is a derived work from Resolv::Hosts of Ruby 2.4
# (https://github.com/ruby/ruby/).
#
# ----
#
# Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modi... | true |
b0a714a3011270b76e8d3948d6e53c7a0d010654 | Ruby | kch/aliastool | /src/aliastool.rb | UTF-8 | 1,851 | 2.6875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env macruby
# encoding: utf-8
framework 'Foundation'
require 'hex_string'
require 'raisins'
require 'alias'
module Commands
extend self
USAGE = <<-EOS.gsub(/^ {4}/, '')
Usage:
{name} make TARGET [PATH] # Creates an alias to TARGET in PATH. PATH defaults to the current directory.
... | true |
d4e713d461d44fcf7ea8984eeb51ab65b238c69d | Ruby | southerncross/document-converter | /something2excel/postgres2txt.rb | UTF-8 | 582 | 2.71875 | 3 | [] | no_license | #!/bin/ruby
# -*- coding: utf-8 -*-
require "pg"
require "Date"
conn = PG.connect dbname: "pku"
Dir.mkdir "./output" unless Dir.exist? "./output"
Date.new(2000, 01, 01).upto(Date.new(2000, 12, 31)) do |date|
sql = "SELECT year, story FROM history WHERE month=#{date.mon} AND day=#{date.day} ORDER BY year"
name =... | true |
2382b82ad1d833162cb032a3c38957c6f3344c6e | Ruby | wenbo/rubyg | /sample/CHAPTER08/180/matrix.rb | EUC-JP | 1,859 | 3.625 | 4 | [] | no_license | require 'matrix'
# 2x2ι
m1 = Matrix[[1, 2], [3, 4]]
m2 = Matrix[[5.0, 6.6], [7.2, 8.9]]
# 4гѹ
Matrix.diagonal(1,2,3,4) # => Matrix[[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]
# βû
m1+m2 # => Matrix[[6.0, 8.6], [10.2, 12.9]]
# ξ軻
m1*m2 # => Matrix[[19.4, 24.4], [43... | true |
a202b14e921f28e6c65abca4de6ed4ad858d77ed | Ruby | adore/daylight | /rails/extensions/read_only_attributes.rb | UTF-8 | 909 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | module ReadOnlyAttributes
extend ActiveSupport::Concern
included do
# place the read_only attributes along side the other class_attributes for a Serializer
class_attribute :_read_only
self._read_only = []
end
module ClassMethods
##
# Records the attribues as read only then stores them as a... | true |
e4ac5f1d19d3826d8dea78a4e180902f19c73961 | Ruby | kamilkamilc/Projekt-Euler | /501.rb | UTF-8 | 178 | 3.046875 | 3 | [] | no_license | def ile_dzielnikow (n)
(1..n).select {|k| n % k == 0 }.size
end
require "prime"
y = 500500
liczba = 1
tab = Prime.first(y)
tab.each_with_index {|v, i| puts "#{i}: #{v}"}
| true |
ce5d5083467c418d4ca218b980f52187ca2c59db | Ruby | beaucouplus/hospitalshifts | /level5/hospital/test/models/shift_test.rb | UTF-8 | 979 | 2.53125 | 3 | [] | no_license | require 'test_helper'
class ShiftTest < ActiveSupport::TestCase
setup do
@worker = Worker.create(first_name: "Vladimir", status: "medic")
@shift = Shift.new(worker_id: @worker.id,start_date: "2018-01-18")
end
test "empty shift should be invalid" do
shift = Shift.new
refute shift.valid?
end
... | true |
d972152bdfd450fc8b2b5144a148330f75083c14 | Ruby | MaxMEllon/ika-fry | /lib/ika/analyzer.rb | UTF-8 | 779 | 2.53125 | 3 | [] | no_license | module IkaFry
class Analizer
class << self
# @param Record::ActiveRecord_Associations_CollectionProxy<Record> records
def analyse_by_rule records
grouped = records.group_by { |r| r.rule_name }
inital = { battle: 0, win: 0, kill: 0, death: 0, assist: 0 }
grouped.map do |k, v|
... | true |
2a87289767913281f851ba552f91e5e31a1e45fe | Ruby | young10270/basic_Ruby_Python | /OOP_variable/1.rb | UTF-8 | 195 | 3.21875 | 3 | [] | no_license | class C
def initialize v
@value = v
end
def show
p @value
end
end
c1 = C.new 10
c1.show
#메소드 밖에서 직접 인스턴스 변수에 접근 불가
#p c1.value
#c1.value=20
| true |
df80ab1d2a45a47e7039a5d3799380f7827f2477 | Ruby | hanfak/ruby-database | /database.rb | UTF-8 | 3,970 | 3.609375 | 4 | [] | no_license | class String
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
end
@people =[["Entry","Surname","Forename", "Nationality", "Age", "Hobby"]]
@i=1
def fill_in_blanks entry
entry.map! {|item_entry| item_entry=="" ? "N/A" : item_entry}
end
def a... | true |
1058275bcce660b30b712950f6db05161ac906f9 | Ruby | UltimateCoder00/Codility-Challenges | /lib/Lesson 4 Counting Elements/MissingInteger/missing_integer.rb | UTF-8 | 155 | 2.828125 | 3 | [
"MIT"
] | permissive | def missing_integer(a)
a.select! { |x| x > 0 }
return 1 if a.empty?
a.sort!.uniq!
for i in 1..(a.length+1)
return i if a[i-1] != i
end
end
| true |
aa21a352a8ea86bff283114791d2e24505c48ab8 | Ruby | abdulkalam7/kalam | /ex16.rb | UTF-8 | 597 | 3.421875 | 3 | [] | no_license | file = ARGV.first
puts "the selected file is #{file}"
puts "to cancle enter ctrl^c"
puts "opening the file"
$stdin.gets
target = open(file, 'w')
puts "about to truncate"
target.truncate(0)
puts "enter the new elements \n"
puts "enter line 1: "
line1 = $stdin.gets.chomp
puts "enter line 2:"
line2 =... | true |
278f622f1a89f7b534c5b83817adc3fdc2cad954 | Ruby | johnwahba/LegalBacon | /script/add_opinion_starts_to_paragraph.rb | UTF-8 | 234 | 2.6875 | 3 | [] | no_license | p "running"
count = Opinion.count
Opinion.all.each_with_index do |opinion, idx|
paragraph = opinion.paragraphs.first
paragraph.start_of_opinion = true
paragraph.save!
if idx % 1000 == 0
p idx.to_s + "/" + count.to_s
end
end
| true |
89dda0fdedb7fe00755cb8c2976750fa0e2ca8c3 | Ruby | rike422/moguro | /lib/moguro/method_reference.rb | UTF-8 | 1,140 | 2.875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Moguro
# MethodReference represents original method reference that was
# decorated by contracts.ruby. Used for instance methods.
# This class borrowed many source code from https://github.com/egonSchiele/contracts.ruby
# License:: https://github.com/egonSchiele/contracts.ru... | true |
70479336f4bfb496c752a58a8fa64d8593de2be3 | Ruby | enspirit/bmg | /lib/bmg/operator/allbut.rb | UTF-8 | 2,794 | 2.859375 | 3 | [
"MIT"
] | permissive | module Bmg
module Operator
#
# Allbut operator.
#
# Projects operand's tuples on all but given attributes, that is,
# removes attributes in the list. The operator takes care of removing
# duplicates.
#
# Example:
#
# [{ a: 1, b: 2 }] allbut [:b] => [{ a: 1 }]
#
# All ... | true |
f5f8e3ec38f22cee5e2f94d3eaecee37238d5f0c | Ruby | michaelsexton/rhubarb | /app/helpers/occurrences_helper.rb | UTF-8 | 316 | 2.9375 | 3 | [] | no_license | module OccurrencesHelper
def to_dms(ord)
deg= (ord - ord%1).to_i
min= (ord%1 *60 - (ord%1 *60 %1)).to_i
sec= ((ord%1 *60 - min)*60).to_i
return deg.to_s+("%02d"%min)+("%02d"%sec)
end
def popular(long, lat)
e = "E"+to_dms(long.abs)
s = "S"+to_dms(lat.abs)
return s+s+e+e
end
end
| true |
ec0996153a9cb0a91ef0d7a0f9ce39c86b9b2d03 | Ruby | viniavancii/TreinamentoRuby | /lib/curso/Aula33.rb | UTF-8 | 819 | 4.40625 | 4 | [] | no_license | #Range
puts intervalo = 1..5
#verificar se algum número esta dentro do intervalo
puts "\n3 está dentro do intervalo 1-5? " + intervalo.include?(3).to_s
puts "\n6 está dentro do intervalo 1-5? " + intervalo.include?(6).to_s
#metodo each = apresenta cada indice por vez
puts "\nUm de cada vez"
inter... | true |
fa8b1a1e579ce1ba5e9acec7d7b22a950bd7ff66 | Ruby | huaiyulin/leetCodeRuby | /Compare Version Number.rb | UTF-8 | 368 | 3.296875 | 3 | [] | no_license | # @param {String} version1
# @param {String} version2
# @return {Integer}
def compare_version(version1, version2)
arr1 = version1.split(".")
arr2 = version2.split(".")
for i in 0..arr1.length
if arr1[i].to_i > arr2[i].to_i
return 1
elsif arr2[i].to_i >arr1[i].to_i
ret... | true |
83d0c0cd1da6987b561b109553e8d59a731bc775 | Ruby | naemono/checkout_system | /lib/checkout.rb | UTF-8 | 3,095 | 2.9375 | 3 | [] | no_license | # frozen_string_literal: false
require 'command_line_reporter'
require 'sequel'
require_relative './base'
require_relative './special'
# Class to hold a list of items to be calculated at a future date
# for a total price.
class Checkout < Base
attr_reader :database, :checkout_id, :specials
include CommandLineRe... | true |
f1fd3e878bd129a367a1988f7f1c8872fb03d605 | Ruby | Haar/coderetreats | /sheffield-May7_2011/iteration2/spec/conways_spec.rb | UTF-8 | 716 | 2.734375 | 3 | [] | no_license | require 'conways'
describe Cell do
context "#live?" do
it "returns true when initialized as live" do
cell = Cell.new(:state => :live)
cell.live?.should be_true
end
it "returns false when initialized as dead" do
cell = Cell.new(:state => :dead)
cell.live?.should be_false
end
... | true |
cc338495bdb80c96aa13c660612aeda856fc0190 | Ruby | candyapplecorn/ruby-definition-clearer | /def-clearer.rb | UTF-8 | 1,462 | 3.046875 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | #!/usr/bin/env ruby
require 'byebug'
if ARGV.empty?
abort "\tUsage: def-clear source.rb [destination]"
elsif ARGV.any?{|a| a =~ /\-h|help/i}
abort "def-clear:
\tremoves all lines of code
\tbetween 'def' and 'end',
\twriting the result to STDOUT.
\t
\tOutput will be redirected to
\tdestination if provided." ... | true |
ee24e70821fff62715f0928b7e279baf46192d65 | Ruby | kpam92/app_academy_coursework | /w3d2/question_follow.rb | UTF-8 | 2,156 | 2.890625 | 3 | [] | no_license | require_relative 'questions_database'
require_relative 'question'
require_relative 'user'
class QuestionFollow
attr_accessor :user_id, :question_id
def self.all
data = QuestionsDatabase.instance.execute("SELECT * FROM question_follows")
data.map { |datum| QuestionFollow.new(datum) }
end
def initiali... | true |
bb8ecb22d012f5cb8a3ba751047f729c07a119d0 | Ruby | Michel-hub/ruby_arreglos | /venta_meses.rb | UTF-8 | 313 | 3.0625 | 3 | [] | no_license | ventas = {
Octubre: 65000,
Noviembre: 68000,
Diciembre: 72000
}
ventas.each do |k,v|
ventas[k] *= 1.1
end
puts ventas
ventas1 = {
Octubre: 65000,
Noviembre: 68000,
Diciembre: 72000
}
nuevo_ventas = {}
ventas1.each do |k,v|
nuevo_ventas[k] = v * 0.8
end
puts nuevo_ventas
| true |
7aa7ad3f3b9dca5e3f03b2d783862cee2283d7dc | Ruby | RubyCrypto/ed25519 | /lib/ed25519/verify_key.rb | UTF-8 | 1,431 | 2.859375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
module Ed25519
# Public key for verifying digital signatures
class VerifyKey
# Create a Ed25519::VerifyKey from its serialized Twisted Edwards representation
#
# @param key [String] 32-byte string representing a serialized public key
def initialize(key)
Ed25519.v... | true |
5eea17c701ae7b0ca58c4991a204c01e295f8353 | Ruby | citin/training | /codewars/unique_in_order.rb | UTF-8 | 214 | 3.375 | 3 | [] | no_license | # https://www.codewars.com/kata/54e6533c92449cc251001667
def unique_in_order(iterable)
result = []
for pos in (0..iterable.size - 1)
c = iterable[pos]
result << c if c != result[-1]
end
result
end
| true |
1ce0dfffa958fecc921a39e45200c2e742b40f7f | Ruby | luketurnerdev/codewars-challenges | /remove_smallest.rb | UTF-8 | 868 | 4.46875 | 4 | [] | no_license | # Given an array of integers, remove the smallest value.
# Do not mutate the original array/list.
# If there are multiple elements with the same value,
# remove the one with a lower index. If you get an empty array/list,
# return an empty array/list.
# Don't change the order of the elements that are left.
def re... | true |
aea3d7743bd547afd9c532f9b05a676bfa74dd56 | Ruby | surgentt/bespoke-challenge | /bin/run.rb | UTF-8 | 595 | 3.734375 | 4 | [] | no_license | require_relative '../config/environment'
player1_wins = 0
player2_wins = 0
text=File.open('./lib/poker.txt').read
text.each_line do |line|
cards = line.split(' ')
hand1 = Hand.new(cards[0..4])
hand2 = Hand.new(cards[5..9])
turn = Turn.new(hand1, hand2)
winner = turn.winner
if winner == 'hand1'
player1... | true |
228c98e325442cc8a93ac33f2fe393811c3a4e81 | Ruby | Bcharlotin/ruby-intro-to-arrays-lab-online-web-prework | /lib/intro_to_arrays.rb | UTF-8 | 1,131 | 3.71875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def instantiate_new_array
instantiate_new_array = []
@my_new_array = instantiate_new_array
end
def array_with_two_elements
array_with_two_elements = [1, 2]
@my_two_array = array_with_two_elements
end
def first_element(my_first_element)
@taylor_swift = ["Welcome to New York", "Blank Space", "Style", "Out of ... | true |
41f4e12e0e0d92c24c56a38092a92cfec0e07a55 | Ruby | Oxford-G/tic_tac_toe | /lib/board.rb | UTF-8 | 345 | 2.953125 | 3 | [
"MIT"
] | permissive | class Board
def print_game(layout)
puts ' 1 2 3'
puts '-------------'
puts "| #{layout[0]} | #{layout[1]} | #{layout[2]} |"
puts '-------------'
puts "| #{layout[3]} | #{layout[4]} | #{layout[5]} |"
puts '-------------'
puts "| #{layout[6]} | #{layout[7]} | #{layout[8]} |"
puts '... | true |
66368f352018038f7a1ca4ffbc32537e82ea1e8d | Ruby | NolanHughes/ttt-with-ai-project-v-000 | /lib/players/computer.rb | UTF-8 | 2,182 | 3.53125 | 4 | [] | no_license | require 'pry'
module Players
class Computer < Player
def move(board = nil)
@board = board
if board.valid_move?("5")
"5"
elsif board.turn_count == 1
"1"
elsif close_to_winning?
close_to_winning?
elsif board.turn_count == 3
["3", "7", "9"].sample
... | true |
eb3219575ba8373bbd8cd5df747da2f944bd831e | Ruby | hiratai/strftime_jp_week | /lib/strftime_jp_week.rb | UTF-8 | 382 | 2.6875 | 3 | [
"MIT"
] | permissive | require "strftime_jp_week/version"
require "date"
require "strftime_jp_week/date"
require "strftime_jp_week/date_time"
require "strftime_jp_week/time"
module StrftimeJPWeek
JP_WEEK = ["日", "月", "火", "水", "木", "金", "土"].freeze
def strftime(format = nil)
if format.nil?
super()
else
super(format.g... | true |
bfefa0e73097dc9dc850cff7796dd3b14f98bca9 | Ruby | neilmcdonagh1985/wk2-d2-lab | /specs/bus_spec.rb | UTF-8 | 973 | 3.046875 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative("../bus")
class BusTest < MiniTest::Test
def setup
@bus = Bus.new(33, 'ocean terminal', [])
end
def test_route
assert_equal(33, @bus.route())
end
def test_destination
assert_equal("ocean terminal", @bus.destination)
end
... | true |
f6dab9ce7a64d64d66ac96ae49c395f0c8551aa9 | Ruby | AustWick/employees-webclient | /app/models/employee.rb | UTF-8 | 415 | 3.15625 | 3 | [] | no_license | class Employee
attr_accessor :id, :first_name, :last_name, :email, :birthday
def initialize(options_hash)
@id = options_hash["id"]
@first_name = options_hash["first_name"]
@last_name = options_hash["last_name"]
@email = options_hash["email"]
@birthday = options_hash["birthday"] ? Date.parse(opti... | true |
7385f95d024a7b7539e8735bfe583cde5f085265 | Ruby | junster90/homestay | /app/helpers/reservations_helper.rb | UTF-8 | 231 | 2.578125 | 3 | [] | no_license | module ReservationsHelper
def booked_dates(listing_id)
dates =[]
bookings = Reservation.where(listing_id: listing_id)
bookings.each do |b|
dates += (b.check_in..b.check_out-1).map(&:to_s)
end
return dates
end
end
| true |
d56923ef66134b2d11d371b51b4d16f769a19bc5 | Ruby | jeff-h4/test-ruby | /day5_exercises/sinatra/course/apps.rb | UTF-8 | 5,949 | 2.5625 | 3 | [] | no_license |
require "sinatra"
require "sinatra/reloader" if development?
require "faker" # for BS
# This allows using the sessions feature in Sinatra
enable :sessions
# From Sinatra FAQ: HTTP Authentication
helpers do
def protected!
return if authorized?
headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
... | true |
5a27fde877068a7d6e732fafa8bd7d39b6f073b5 | Ruby | DanielVartanov/tty-prompt | /spec/unit/slider_spec.rb | UTF-8 | 5,102 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
RSpec.describe TTY::Prompt, "#slider" do
subject(:prompt) { TTY::TestPrompt.new }
let(:symbols) { TTY::Prompt::Symbols.symbols }
let(:left_right) { "#{symbols[:arrow_left]}/#{symbols[:arrow_right]}"}
it "specifies ranges & step" do
prompt.input << "\r"
prompt.input.rewin... | true |
5b1f292cc7430df31131df7ca1b287b90f88d268 | Ruby | mcartmell/greygoomud | /lib/greygoo/testagent.rb | UTF-8 | 927 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'rack/test'
require 'mud'
require 'json'
class GreyGoo
class TestAgent
attr_reader :browser
attr_accessor :user_id
def app
Mud
end
def initialize
@browser = Rack::Test::Session.new(Rack::MockSession.new(Mud))
@browser.header('Accept', 'application/json')
register_user
end
def name... | true |
eff67fbd9a7ff99d232418b566e84caeff24c839 | Ruby | danreedy/dice_bag | /lib/dice_bag/dice.rb | UTF-8 | 746 | 3.453125 | 3 | [
"MIT"
] | permissive | module DiceBag
class Dice
DEFAULT_SIDES = 6
attr_reader :sides
def initialize(sides=DEFAULT_SIDES)
sides = sides.to_i
raise DiceBag::InvalidSidesError, 'Dice must have a positive integer number of sides' if sides <= 0
raise DiceBag::TooLargeError, 'Dice has too many sides' if sides > 10... | true |
86967e0c24272360fe1529cf5ba29f2a43eca472 | Ruby | Baxxis/final_project | /app/models/order.rb | UTF-8 | 456 | 2.625 | 3 | [] | no_license | # order class
class Order < ApplicationRecord
belongs_to :customer
before_create :set_order_status
belongs_to :order_status
has_many :order_items
before_save :update_subtotal
def subtotal
order_items
.collect { |item| item.valid? ? (item.quantity.to_i * item.unit_price.to_f) : 0 }
.sum
en... | true |
c0356e61aec9e95d2bb195e7b7c5ba001642f865 | Ruby | hinrik/ircsupport | /lib/ircsupport/masks.rb | UTF-8 | 2,379 | 3 | 3 | [
"MIT"
] | permissive | require 'ircsupport/case'
module IRCSupport
module Masks
# @private
@@mask_wildcard = '[\x01-\xFF]{0,}'
# @private
@@mask_optional = '[\x01-\xFF]{1,1}'
module_function
# Match strings to an IRC mask.
# @param [String] mask The mask to match against.
# @param [String] string The stri... | true |
3d5e46e7b98bd5d7dda80c403c4e8ac9b07e2c1e | Ruby | datenreisender/codersdojo_client | /app/console_view.rb | UTF-8 | 3,679 | 3 | 3 | [] | no_license | require 'shell_wrapper'
class ConsoleView
def initialize scaffolder
@scaffolder = scaffolder
end
def show_help
puts <<-helptext
CodersDojo-Client, http://www.codersdojo.org, Copyright by it-agile GmbH (http://www.it-agile.de)
CodersDojo-Client automatically runs your code kata, logs the progress and uploads... | true |
89433d9190f2ffc020ca1ec1e2633d3adf7bb48e | Ruby | exercism/ruby | /exercises/practice/robot-name/.meta/example.rb | UTF-8 | 221 | 2.875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Robot
def self.forget
@@name_enumerator = [*'AA000'..'ZZ999'].shuffle.each
end
self.forget
attr_reader :name
def initialize
reset
end
def reset
@name = @@name_enumerator.next
end
end
| true |
a3901db5fb69feab6daa5e9c287cfc3b12daa91b | Ruby | bryanl/luhnybin | /luhnyrb/spec/luhnyrb/chunker_spec.rb | UTF-8 | 484 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
describe Luhnyrb::Chunker do
it "chunks up text" do
text = "this is a longer string of text for testing"
chunker = Luhnyrb::Chunker.new(text)
chunker.chunk(14).must_equal("this is a long")
chunker.chunk(14).must_equal("his is a longe")
end
it "returns nil when we have no m... | true |
8271d17aad339a3f11d39592c243998154c663f5 | Ruby | digitalronin/github-actions | /reject-escalated-privileges-yaml/reject-escalated-privileges-yaml.rb | UTF-8 | 1,962 | 2.640625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require "json"
require "octokit"
require "yaml"
require File.join(File.dirname(__FILE__), "github")
# can expand this list spliting with spaces. e.g %w(cluster-admin root webops)
STRING_LIST = %w[cluster-admin]
# Output the yaml file and the code if any of the strings in the STRING_LIST is
# pre... | true |
9c18a91a5f78d6d80075fa8812562d71ba0dfda8 | Ruby | shannonjen/sportsrocket-wdi | /day7/validation-app/app/models/user.rb | UTF-8 | 459 | 2.5625 | 3 | [] | no_license | class User < ApplicationRecord
# validates :email, length: { minimum: 4, maximum: 8 }
validates :email, uniqueness: true
before_save :some_method
before_validation :append_random_id
after_validation :geocode_address
def some_method
puts "HI!!!! We are all stardust"
end
def append_random_id
se... | true |
577e11a036bf0c64512e964668857f9f21146245 | Ruby | adccb/tic-tac-toe | /ruby/index.rb | UTF-8 | 1,718 | 4.0625 | 4 | [] | no_license | require "colorize"
require_relative "./class/Board.rb"
require_relative "./class/Game.rb"
require_relative "./class/Renderer.rb"
def parse_move raw
raise ArgumentError if raw.size > 2 or raw.size < 2
raw_x, raw_y = raw.split ""
raise ArgumentError if not raw_x =~ /[[:alpha:]]/ or not raw_y.to_i.between?(0, 3)
... | true |
765f9a31c88ce7a5a9448c675c3e3c8c9a9906ad | Ruby | S-Maitland/Rock_Paper_Scissors_GAME | /controller.rb | UTF-8 | 287 | 2.671875 | 3 | [] | no_license | require('sinatra')
require('sinatra/contrib/all')
require('pry-byebug')
require_relative('models/rps.rb')
get "/" do
erb(:home)
end
# TODO: add a controller
get "/rps/:hand1/:hand2" do
game = RPS.new(params[:hand1], params[:hand2])
@winner = game.play_game()
erb(:result)
end
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.