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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
b49ce210e95a11378e22f68a77184cf2a636a024 | Ruby | quarzz/bsu-labs | /sasm/1/mgenerator.rb | UTF-8 | 243 | 3.109375 | 3 | [] | no_license | require_relative 'constants'
class MGenerator
def initialize(x, y, k = K)
@x, @y, @k = x, y, k
@v = Array.new(@k) { @x.next }
end
def next
s = (@y.next * @k).to_i
result = @v[s]
@v[s] = @x.next
result
end
end
| true |
b46a07884c9043ae3680fbda1d965b58d43663ed | Ruby | SuperMegaGiperProger/continuous-stochastic-queuing-system | /lib/characteristics/average_count_in_system.rb | UTF-8 | 421 | 2.921875 | 3 | [] | no_license | require_relative './base_characteristic'
module Characteristics
class AverageCountInSystem < BaseCharacteristic
def initialize
@sum = 0
@all_time = 0
end
def update(queue:, channel:, spend_time:)
count = queue.size
count += 1 if channel.busy?
@sum += count * spend_tim... | true |
bf9105f9b626642dad566897a5f0e1dab1e19dbb | Ruby | javoor1/Cont | /Contenido_Piloto/testing.rb | UTF-8 | 942 | 4.0625 | 4 | [] | no_license | # # Respuesta:
# def mayor(num1, num2)
# if num1 == num2
# "son iguales"
# elsif num1.to_s.chars.last == num2.to_s.chars.last
# num1
# elsif num1 % 5 == 0 && num2 % 5 == 0
# num2
# else
# nil
# end
# end
# p mayor(1, 5) == nil
# p mayor(110, 210) == 110
# p mayor(5, 50) == 50
# def mayor(num1, num2)
# ... | true |
0a3774941ccdc7cde1a584741562a240b789121e | Ruby | DevNeoLee/AppAcademy2019 | /ruby/ghost_project/game.rb | UTF-8 | 1,020 | 3.546875 | 4 | [] | no_license | require_relative "player"
require 'set'
class Game
attr_reader :fragment, :players
def initialize(player1, player2)
@fragment = ""
@players = [player1, player2]
end
def dictionary(data = nil)
@dictionary = data ||= File.readlines("dictionary.txt").join("\n").split
@... | true |
6ae9cc128739b955bf7099cc9030c224296adb27 | Ruby | JoseGomez247/codeacamp | /newbie/semana1/Miercoles/procesor.rb | UTF-8 | 239 | 3.3125 | 3 | [] | no_license | class Computer
attr_reader :proc
def initialize(proc)
@proc = proc
end
def processor
@proc
end
end
mac= Computer.new("Intel")
#test
p mac.processor
#=>"Intel"
mac.processor = "AMD"
#=>...undefined method `processor='...
| true |
a10af4d22ab8c6286b3d2d3bb975c47a5fbec532 | Ruby | MikeAlphaBravo/Anagrams_Checker | /spec/bdd_independent_spec.rb | UTF-8 | 1,478 | 3.515625 | 4 | [
"MIT"
] | permissive | require('rspec')
require('pry')
require('bdd_independent')
# 1
describe('AnagramChecker#bdd_independent') do
it("checks two words length") do
a = AnagramChecker.new("bury","dill")
expect(a.same_length?).to(eq(true))
end
# 1 & 2
it("checks strings for same letters") do
a = AnagramChecker.new("Bu ry",... | true |
66f0b1e667078f05a19911b6f1865d50cb1a84f1 | Ruby | mkmojo/cs254 | /A4/xref.rb | UTF-8 | 10,155 | 2.734375 | 3 | [] | no_license | require 'set'
require 'fileutils'
def mkdir (dir_name)
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
end
def is_interesting_filetype (path)
/.*\.([ch]|dump)/.match(path)
end
def list_content(path)
if File.file?(path)
nil
else
Dir.glob(path)
end
end
def list_files (path)
res = []
list... | true |
04b3b10f1be978e4d2d46c2743066d2894120a98 | Ruby | Nesk27/MarginalValera | /src/load.rb | UTF-8 | 410 | 2.59375 | 3 | [] | no_license | class Load
def save(valera)
@hash = {'health' => valera.health, 'food' => valera.food,
'alcomana' => valera.alcomana, 'happy' => valera.happy,
'tired' => valera.tired, 'money' => valera.money
}
file = File.open('saved_game.json', 'w')
file.write(JSON.dump(save_hash))
file.close
en... | true |
5c4f89fe68f4a1e8242b3e7b233eb3187a1dc7e3 | Ruby | fuzyll/wrastor | /replace.rb | UTF-8 | 3,199 | 2.875 | 3 | [] | no_license | #!/usr/bin/env ruby
##
# replace.rb | Wrastor Replace Utility
#
# Copyright (c) 2017 Alexander Taylor <ajtaylor@fuzyll.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restrict... | true |
58a5b07cfaf634dd8d1aee59c80a2a42c53b82dc | Ruby | SteveHonor/backend-rover-challenge | /rover.rb | UTF-8 | 1,240 | 3.8125 | 4 | [] | no_license | class Rover
def initialize (coordinates, orientation, plateau)
@coordinate = coordinates
@orientation = orientation
@plateau = plateau
end
def turn_left
@orientation = case @orientation
when 'N' then 'W'
when 'E' then 'N'
when 'S' then 'E'
when 'W' then 'S'
end
end
def tu... | true |
ddee4df032669e4b8d53c3b32f2240b3b8dc756f | Ruby | gpks/adder_web | /lib/params_parser.rb | UTF-8 | 285 | 3.109375 | 3 | [] | no_license | class ParamsParser
def self.parse(params)
raise ParamsError if params.nil?
final = split_string(params)
change_into_integers(final)
end
def self.split_string(string)
string.split(',')
end
def self.change_into_integers(array)
array.map(&:to_i)
end
end
| true |
3d7a0a8521fdff44759d65089cf440773e3e0c78 | Ruby | bjjb/yapaas | /lib/docker/machine.rb | UTF-8 | 1,312 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'pathname'
require 'json'
require 'rbconfig'
module Docker
class Machine
attr_reader :path
attr_reader :config_file
attr_accessor :name
def initialize(path)
@path = Pathname.new(path)
@name = @path.basename.to_s
end
def run(command)
ENV['DOCKER_TLS_VERIFY'] = "1"
... | true |
06698b0cd0fd53ba2999665c92553e688c44c3bc | Ruby | leormston/nameofapp | /spec/models/product_spec.rb | UTF-8 | 793 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
describe Product do
context "Calculate average rating" do
let(:product) { Product.create!(name: "Test GPU") }
let(:user) { User.create!(email: "Test123@test.com", password: "password")}
before do
product.comments.create!(rating: 1, user: user, body: "Awful GPU")
product... | true |
f8297f89b857f6c6bce74362861e73c7cc5bf3c9 | Ruby | norskbrek/ruby-foundations | /03_practice_problems/medium1/06.rb | UTF-8 | 550 | 3.875 | 4 | [] | no_license | def tricky_method(a_string_param, an_array_param)
a_string_param += "rutabaga"
an_array_param += "rutabaga"
return a_string_param, an_array_param
end
my_string = "pumpkins"
my_array = ["pumpkins"]
tricky_method(my_string, my_array)
puts "My string looks like this now: #{my_string}"
puts "My array looks like th... | true |
05581941ec0e2a0292329f4da860775a7e7c30f4 | Ruby | markgandolfo/toy-robot | /spec/libs/board_spec.rb | UTF-8 | 1,321 | 2.9375 | 3 | [] | no_license | require 'spec_helper'
RSpec.describe Board do
subject(:board) { Board.new(height: height, width: width) }
let(:width) { 5 }
let(:height) { 5 }
describe '.valid_placement?' do
context 'when given a co-ordinate that is on the board' do
it 'will return true' do
expect(board.valid_placement?(x:1... | true |
0e82ae31a87ab612609749c51eea67f6adb220d2 | Ruby | naechrist/CLI-Project | /lib/louisville_events/scraper.rb | UTF-8 | 1,492 | 3.03125 | 3 | [
"MIT"
] | permissive | class Scraper
def self.scrape_events
page = Nokogiri::HTML(open("https://www.gotolouisville.com/events-calendar/"))
event_listings = page.css("#dir-root > article")
p = 1
last_page = 76
while p <= last_page #goes through each page
... | true |
b480496ce8c7c8d67eb40f9d6f8714051e3696b8 | Ruby | harpreeetghotra40/school-domain-nyc-web-060319 | /lib/school.rb | UTF-8 | 1,019 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # code here!
require 'pry'
class School
attr_accessor :name, :roster
def initialize(name)
@name = name
@roster = {}
end
def add_student(student_name, grade)
if @roster.key?(grade)
@roster[grade] << student_name
else
@roster[grade] = []
... | true |
09b3049d3ae837b5aad037f2d56824924e1ca159 | Ruby | Atlas-Quest/code_alongs | /week04/intro/ruby/2-tue/hashes/inumerables.rb | UTF-8 | 598 | 3.671875 | 4 | [] | no_license | require 'pry'
languages = ['ruby','php','python']
lucky_numbers = [1,7,21]
# in js we call it higher order functions
# inumerables in short is something you can count
# ruby block
languages.each do |lang|
puts lang
end
total = 0
lucky_numbers.each do |num|
total = total + num
puts total
end
binding.pry
so... | true |
1df29a4f401a7965391633947b4c3d85edb394a7 | Ruby | patrodriguez108/can-place-flowers | /flowers.rb | UTF-8 | 215 | 3.234375 | 3 | [] | no_license | # @param {Integer[]} flowerbed
# @param {Integer} n
# @return {Boolean}
def can_place_flowers(flowerbed, n)
end
can_place_flowers([1,0,0,0,1], 1)
# output: true
can_place_flowers([1,0,0,0,1], 2)
# output: false | true |
88ad5304ca3e835f4eaa85a188d01a0d1084bf3e | Ruby | styerfoam/RubyFall2013 | /week3/homework/calculator.rb | UTF-8 | 292 | 3.671875 | 4 | [
"Apache-2.0"
] | permissive | class Calculator
def sum array
if array == []
0
else
array.inject{|n, x| n += x}
end
end
def multiply (*number)
number.flatten.inject{|n,x| n *= x}
end
def pow a, n
a ** n
end
def fac n
if n == 0
1
else
n * fac(n-1)
end
end
end | true |
5ad098f315fcf438046321c2f9586dcb5e531411 | Ruby | werdlerk/blackjack-web | /main.rb | UTF-8 | 4,249 | 2.71875 | 3 | [] | no_license | require 'rubygems'
require 'sinatra'
require 'pry'
require 'json'
require './helpers'
set :sessions, true
set :session_secret, 'Codefish.org\'s secret'
CARD_VALUE_TO_WORD = { 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten" }
BLACKJACK_AMOUNT = 21
DE... | true |
9e37247c8612981ea73610ce6213d7bc4a4bac90 | Ruby | rosscarrothers/rbnd-toycity-part3 | /lib/product.rb | UTF-8 | 1,252 | 3.671875 | 4 | [
"MIT"
] | permissive | class Product
attr_reader :title
attr_reader :price
attr_reader :stock
@@products = []
def self.all
@@products
end
def self.in_stock
# Loop over all products in the class list and check which are in stock
in_stock_products = []
@@products.each do |product|
if product.in_stock?
in_s... | true |
dff3d71dc7e814bd0198c3e03bd739ff609daa88 | Ruby | Willibaur/learn_to_program | /ch11-reading-and-writing/build_your_own_playlist.rb | UTF-8 | 540 | 3.453125 | 3 | [] | no_license | def playlist
Dir.chdir '/home/william/Dropbox/WK-03/learn_to_program/ch11-reading-and-writing'
songs = shuffle(Dir['**/*.mp3'])
p songs.length
puts "Please enter the name for your playlist"
playlist_name = "#{gets.chomp}.m3u"
File.open playlist_name, 'w' do |f|
songs.each { |song| f.write song+"\n" }... | true |
66d622a2ac689ef89bc1029c641d9cebd47e30a8 | Ruby | Shelvak/nebula-game | /server/lib/app/models/parts/constructor.rb | UTF-8 | 16,380 | 2.578125 | 3 | [
"LicenseRef-scancode-other-permissive"
] | permissive | module Parts::Constructor
# Proxy class for #constructable property of constructors.
class ConstructableProxy < ActiveSupport::BasicObject
TYPE_BUILDING = :building
TYPE_UNIT = :unit
TYPES = [TYPE_BUILDING, TYPE_UNIT]
def self.converter(constructable)
case constructable
when ::Building... | true |
f7139526442d951be9620a0d5b8ab1034c24be84 | Ruby | yujinakayama/rspec-hue_formatter | /lib/rspec/hue_formatter.rb | UTF-8 | 3,098 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'hue'
module RSpec
class HueFormatter
Core::Formatters.register(
self,
:start,
:example_started, :example_passed, :example_pending, :example_failed,
:dump_summary, :close
)
GREEN = 29_000
YELLOW = 12_750
RED = 0
IMMEDIATE_TRANSITION = 0
SLOW_TRANSITIO... | true |
d485af5ad0328c5baba7344ba8702dc360b5aef0 | Ruby | johndillon773/learn_to_program | /ch_13/shuffle.rb | UTF-8 | 345 | 3.75 | 4 | [] | no_license | class Array
def shuffle
shuffled = []
if self.length <= 0
return shuffled
end
while self.size > 0
i = rand(self.size)
shuffled << self[i]
self.delete_at(i)
end
shuffled
end
end
my_arr = ["Chica", "Ale", "John", "Paloma", "Barb", "mike", "jaime", "conn... | true |
b039c2aed4c0f09a2de6e04c30a505f946bd684c | Ruby | mindu/rubyprograms | /week 4/p028xrandom.rb | UTF-8 | 123 | 2.8125 | 3 | [] | no_license | f = File.new('teste.rb')
#f.seek(12,IO::SEEK_SET)
#f.seek(0,IO::SEEK_CUR)
f.seek(0,IO::SEEK_END)
print f.readline
f.close
| true |
af8cb99ea2259ca79e7deee2cf68006c3e303083 | Ruby | LetiTran/oo-ride-share | /specs/trip_dispatch_spec.rb | UTF-8 | 10,071 | 2.828125 | 3 | [] | no_license | require_relative 'spec_helper'
describe "TripDispatcher class" do
describe "Initializer" do
it "is an instance of TripDispatcher" do
dispatcher = RideShare::TripDispatcher.new
dispatcher.must_be_kind_of RideShare::TripDispatcher
end
it "establishes the base data structures when instantiated"... | true |
e39b55883da60baeb0f432801d5e04b808f8a54e | Ruby | liuderek97/Challenges-Week-1 | /create_hash.rb | UTF-8 | 250 | 3.4375 | 3 | [] | no_license | def create_hash(hash_key, hash_value)
hash = {}
hash[hash_key] = hash_value
puts hash
end
puts "create a hash key"
user_input = gets.chomp
puts "create a hash value"
user_input_value = gets.chomp
create_hash(user_input, user_input_value) | true |
23142e08ecfc75df10c58201bd6c57c3248574bd | Ruby | NanyR/sinatra-nested-forms-web-0217 | /app/models/ship.rb | UTF-8 | 274 | 3.046875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Ship
attr_reader :name, :type, :booty
@@all=[]
def initialize(parameters)
@name= parameters[:name]
@type=parameters[:type]
@booty=parameters[:booty]
@@all<<self
end
def self.all
@@all
end
def self.clear
@@all.clear
end
end
| true |
978b3b4a93c51f7904a0a0640334bdc26b324071 | Ruby | tsuruhaya/freemarket_sample_64b | /spec/models/address_spec.rb | UTF-8 | 3,780 | 2.75 | 3 | [] | no_license | require 'rails_helper'
describe Address do
describe '#create' do
it "is valid with a sending_first_name, sending_last_name, sending_first_name_kana, sending_last_name_kana, postal_code, prefecture_id, city, town" do
address = build(:address)
expect(address).to be_valid
end
# 氏名が空では登録できない
... | true |
f499c1aa287953694d2da5f16c29cb6136c64946 | Ruby | ChrisBarthol/project_euler | /problem28.rb | UTF-8 | 719 | 3.625 | 4 | [] | no_license | # Starting with the number 1 and moving to the right in a clockwise
# direction a 5 by 5 spiral is formed as follows:
# 21 22 23 24 25
# 20 7 8 9 10
# 19 6 1 2 11
# 18 5 4 3 ... | true |
bf274270b31094ed0b06404dca7bbcdad818357e | Ruby | jasoares/rubaship | /lib/rubaship/exception.rb | UTF-8 | 1,275 | 3.171875 | 3 | [
"MIT"
] | permissive | module Rubaship
class InvalidRowArgument < ArgumentError
def initialize(row)
super("Invalid row or range type passed #{row}:#{row.class}")
end
end
class InvalidColArgument < ArgumentError
def initialize(col)
super("Invalid column or range type passed #{col}:#{col.class}")
end
end
... | true |
8193969d7c2d9c919aca2729c8fa17d7efffab28 | Ruby | swaff/api-stub | /lib/response_file.rb | UTF-8 | 1,180 | 2.828125 | 3 | [] | no_license | class ResponseFile
attr_reader :request_path, :request_params, :ignored_params
def initialize (request_path, request_params = {}, ignored_params = [])
@request_path = clean_path request_path
@request_params = request_params
@ignored_params = ignored_params
end
def name
"#{request_path}#{params... | true |
01ffedfd50fce83f59dd4f7db30c62718f592aa4 | Ruby | rails/rails | /activemodel/test/cases/attributes_test.rb | UTF-8 | 4,995 | 2.546875 | 3 | [
"MIT",
"Ruby"
] | permissive | # frozen_string_literal: true
require "cases/helper"
module ActiveModel
class AttributesTest < ActiveModel::TestCase
class ModelForAttributesTest
include ActiveModel::Model
include ActiveModel::Attributes
attribute :integer_field, :integer
attribute :string_field, :string
attribut... | true |
e7ee30566374f67ced646a80fabb29844fd97d26 | Ruby | erikolsen/usatt_notifier | /app/models/concerns/rating_finder.rb | UTF-8 | 306 | 2.53125 | 3 | [] | no_license | class RatingFinder
RATING_IDENTIFIER = '.huge-number'
def initialize(profile_page_url)
@url = profile_page_url
end
def rating
profile_page.at(RATING_IDENTIFIER).text.strip
end
def profile_page
mechanize.get @url
end
def mechanize
@mechanize ||= Mechanize.new
end
end
| true |
e66db483a01e8f92bbef2bb2707a7c482df8f9c9 | Ruby | chrisclc/RB101-Programming-Foundations | /lesson_2/Rock Paper Scissors.rb | UTF-8 | 998 | 3.734375 | 4 | [] | no_license | VALID_CHOICES = %w(rock paper scissors)
def win?(first, second)
(first == 'rock' && second == 'scissors') ||
(first == 'paper' && second == 'rock') ||
(first == 'scissors' && second == 'paper')
end
def result(user_input, computer_choice)
if win?(user_input, computer_choice)
prompt('You won!')
elsif ... | true |
be5eb4cd287d2fb0a720f0459e7c58c19bf2812d | Ruby | marina-h/LaunchSchool | /course_101/lesson_3/easy1/easy1_10.rb | UTF-8 | 251 | 3.375 | 3 | [] | no_license | # Exercises: Easy 1
# Question 10
flintstones = ["Fred", "Barney", "Wilma", "Betty", "Pebbles", "BamBam"]
flintstones_with_index = {}
flintstones.each_with_index do |name, index|
flintstones_with_index[name] = index
end
p flintstones_with_index
| true |
bf86695d7c69f07fc496f75a2e3d36869a63725c | Ruby | deepigarg/rubyx | /lib/sol/statement.rb | UTF-8 | 3,447 | 3.078125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #
# SOL -- Simple Object Language
#
# SOL is the abstraction of ruby: ruby minus the fluff
# fluff is generally what makes ruby nice to use, like 3 ways to achieve the same thing
# if/unless/ternary , reverse ifs (ie statement if condition), reverse whiles,
# implicit blocks, splats and multiple assign... | true |
065608a3f669d84663d64a96bfcf5886f4f751c0 | Ruby | swsalsify/ruby-tutorials | /20190614-classes-and-inheritance/classes-and-inheritance.rb | UTF-8 | 341 | 3.4375 | 3 | [] | no_license | require 'pry'
class Mammal
def breathe
puts "inhale and exhale"
end
end
class Cat < Mammal
def speak
puts "Meow"
end
end
class Bird
def preen
puts "I am cleaning my feathers."
end
def fly
puts "I am flying."
end
end
class Penguin < Bird
def fly
puts "Sorry. I'd rather swim."
... | true |
e847b80c7554da2cf25270e2774fa2da0e416393 | Ruby | LiteRiver/metaprogramming | /part2/greet_with_prepend.rb | UTF-8 | 212 | 3.265625 | 3 | [] | no_license | class MyClass
def greet
'hello'
end
end
module EnthusiasticGreetings
def greet
"Hey, #{super}"
end
end
class MyClass
prepend EnthusiasticGreetings
end
p MyClass.new.greet
p MyClass.ancestors
| true |
6820100d684215cb34d8ab56d2bf62bfefe36859 | Ruby | monkeygq/ruby_demo | /singleton_method_and_class.rb | UTF-8 | 876 | 3.5 | 4 | [] | no_license | str = "my love lcx"
def str.myupcase
self.gsub(/lcx/,"Lcx")
end
p str.myupcase #=> "my love Lcx"
p str.methods(false) #=> [:myupcase]
#===========================two methods to get singleton class===============================>
singleton_class = str.singleton_class
p singleton_class #=> #<Class:#<String:0x0000... | true |
02965f686d31eb0ea2b41903d8a1fb2f98514982 | Ruby | jhnegbrt/aA_Classwork | /w4d2/class_inheritance.rb | UTF-8 | 1,054 | 3.703125 | 4 | [] | no_license | require "byebug"
class Employee
attr_reader :salary, :name, :title, :boss
def initialize(name, title, salary, boss)
@name = name
@title = title
@salary = salary
@boss = boss
end
def bonus(multiplier)
bonus = @salary * multiplier
end
def add_subs
self.boss.subs << self
if... | true |
5ddacaed59cc4573e9c63e49b99747b2a4f83795 | Ruby | mikereinhart/hw | /week1/522/option2.rb | UTF-8 | 2,461 | 4.0625 | 4 | [] | no_license |
#HOMEWORK
#The program takes the line and stop that a user is getting on at and the line and stop that user is getting off at and prints the total number of stops for the trip.
#There are 3 subway lines:
#the N line has the following stops: Times Square, 34th, 28th, 23rd, Union Square, and 8th
#The L line has the f... | true |
10173d441e5e9ff8bf0a3e09cf9f8d7b1299e66b | Ruby | safetymonkey/asq | /spec/models/interval_schedule_spec.rb | UTF-8 | 997 | 2.625 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
RSpec.describe IntervalSchedule do
let(:schedule) { IntervalSchedule.new() }
it "returns false next date when empty" do
expect(schedule.get_scheduled_date).to be_falsy
end
it "returns date for populated schedule" do
schedule.param = 0
expect(schedule.get_scheduled_date).to ... | true |
0016a5fb5916fc3643993a8ee87a13e470469902 | Ruby | nyaago/cms | /lib/domain_validator.rb | UTF-8 | 521 | 2.625 | 3 | [] | no_license | # = DomainValidator
# Domain名のvalidator
# ラテン文字・数字・“-”(先頭はラテン文字または数字)をdotで区切ったもののみ有効
class DomainValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank?
regexp = Regexp.new("^(?:[a-zA-Z]{1}[-a-zA-Z0-9]+\.)+[a-zA-Z]{1}[-a-zA-Z0-9]+$")
unless regexp.match... | true |
4b83d3044d8a5c43d97f28065ed6193f59597fe7 | Ruby | kangkyu/codeschool | /ruby bits 2/block-to-lambda.rb | UTF-8 | 479 | 3.53125 | 4 | [
"MIT"
] | permissive | # Proc
class Tweet
def post
if authenticate?(@user, @password)
# submit tweet
yield
else
raise 'Auth Error'
end
end
end
tweet = Tweet.new('Ruby Bits')
tweet.post { puts 'Sent!'}
# Lambda
class Tweet
def post(success, error)
if authenticate?(@user, @password)
# submit the tweet
success.call
... | true |
deafbc18cdedefe585896119b0b7f54a739bbf8b | Ruby | joesus/WineCardsWithDevise | /spec/models/wine_spec.rb | UTF-8 | 1,918 | 2.71875 | 3 | [] | no_license | # == Schema Information
#
# Table name: wines
#
# id :integer not null, primary key
# varietal :string(255)
# country :string(255)
# vintage :integer
# description :string(255)
# price :integer
# created_at :datetime
# updated_at :datetime
# name :string(255)
# plac... | true |
d0d565c811f0070e0f9dd8d79294998ae0d207e5 | Ruby | indra-an/investasiku | /app/models/glosarry.rb | UTF-8 | 451 | 2.609375 | 3 | [] | no_license | class Glosarry < ApplicationRecord
validates_presence_of :title, :description
before_save :extract_word_index
scope :word_indexes, -> {
select(:word_index).order(:word_index => :asc).distinct.collect(&:word_index)
}
scope :search, ->(query) {
where('glosarries.title ILIKE ?', "%#{query}%")
}
#... | true |
8c01a6519f03443dd492c107f594aa9f24f4122b | Ruby | alscotty/aA_classwork | /W5D1/LRU Cache/lib/p02_hashing.rb | UTF-8 | 839 | 3.578125 | 4 | [] | no_license | class Integer
# Integer#hash already implemented for you
end
class Array
def hash
new_num = ""
(0...self.length).each do |i|
new_num += self[i].to_s(2)
end
new_num.to_i
end
end
class String
def hash
new_num = ""
alphabet = ("a".."z").to_a
(0...self.length).each do |i|
... | true |
72da3f84e991cd81349687a5df849736298e66c7 | Ruby | stuartstein777/CodeWars | /8KYU/Calculate BMI/solution.rb | UTF-8 | 233 | 3.046875 | 3 | [] | no_license | def bmi(weight, height)
bmi = (weight / (height * height))
case bmi
when 0..18.5
"Underweight"
when 18.5..25
"Normal"
when 25..30
"Overweight"
else
"Obese"
end
end | true |
ad039fa9d8df52f7c6c101f7a9ffca883f551108 | Ruby | smosab/Prep_Course_Assignments | /Intro_to_Programming/Loops_&_Iterators/conditional_loop.rb | UTF-8 | 364 | 3.53125 | 4 | [] | no_license | #conditional_loop.rb
# i = 0
# loop do
# i += 2
# puts i #"#{i}"
# if i == 10
# break #this will cause execution to exit the loop
# end
# end
i = 0
loop do
i += 2
if i == 4
next
end
puts i #"#{i}"
if i == 10
break #this will cause ex... | true |
6e13e1bd81887455fcd7d19a465245bca91e9660 | Ruby | arnaldoaparicio/black_thursday | /lib/sales_engine.rb | UTF-8 | 1,106 | 2.515625 | 3 | [] | no_license | require_relative './spec_helper'
class SalesEngine
attr_reader :items,
:merchants,
:invoices,
:invoice_items,
:transactions,
:customers,
:analyst
def self.from_csv(data)
SalesEngine.new(data)
end
def initialize(data)
... | true |
46cba5e85a3ff81a7c7c0a48eef0b34a1bd1168b | Ruby | ga-wdi-boston/wdi_1_ruby_cheatsheets | /hashes_collin_holly_cenk.rb | UTF-8 | 1,678 | 3.96875 | 4 | [] | no_license | #This is the cheatsheet for hashed by Cenk Holly and Collin
new_hash = { #This line defines a hash
hash_item1: "hash value a", #hash_item1 = key; "hash value a" = value
hash_item2: "hash value b",
hash_item3: "hash value c",
hash_item4: { #this is a nested hash; a key whose value is a hash
... | true |
4b005045548d65757309d19388cead4f55b17b15 | Ruby | sdbs-cz/psy-high | /lib/bands_data.rb | UTF-8 | 1,624 | 2.90625 | 3 | [] | no_license | require 'remote_table'
require 'yaml'
require 'fileutils'
require_relative './embeds'
class Hash
def hmap(&block)
Hash[self.map {|k, v| block.call(k,v) }]
end
# Map only values, maintain keys
def hmap_val(&block)
self.hmap { |k, v| [k, block.call(v)] }
end
end
SOURCE_URL = 'https://docs.google.com... | true |
31f46217811900550dae06e6b25afd4b7173b63c | Ruby | hopesgit/battleship | /test/cell_test.rb | UTF-8 | 2,017 | 3.1875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/cell'
class CellTest < Minitest::Test
def test_it_exists
cell = Cell.new("B4")
assert_instance_of Cell, cell
end
def test_it_has_a_coordinate
cell = Cell.new("B4")
assert_equal "B4", cell.coordinate
end
def test_it_is_cre... | true |
197a8455bdca4895ba14c715042321334032a370 | Ruby | dbaruahtcd/Algorithms-and-Data-structure | /exercises/5.coding_challenge/13.roman_to_int.rb | UTF-8 | 4,101 | 4.28125 | 4 | [] | no_license | =begin
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, two is written as II in Roman numeral, just two one's added together. Twelve... | true |
1b95679acc16dbb8dc893dbb69917b74573383eb | Ruby | tomholford/pots | /spec/pots_game_spec.rb | UTF-8 | 1,546 | 2.984375 | 3 | [] | no_license | require 'rspec'
require_relative '../pots_game'
describe PotsGame do
let(:instance) { described_class.new(pots: pots) }
let(:pots) { [] }
describe '#maximize_gold' do
subject { instance.maximize_gold }
context 'no pots given' do
it 'raises error' do
expect { subject }.to raise_error(Argum... | true |
6005c02489c2f44106b45403ee0fe44a0ae5c842 | Ruby | askl56/income-tax | /spec/income_tax/countries/tunisia_spec.rb | UTF-8 | 4,801 | 2.78125 | 3 | [
"MIT"
] | permissive | describe IncomeTax::Countries::Tunisia do
subject(:result) { described_class.new(income: income, income_type: type, tax_year: tax_year) }
let(:type) { :gross }
describe 'from gross income of 0' do
let(:tax_year) { 2015 }
let(:income) { 0 ... | true |
b107e7c3c298ed265c17bdcd2b303ad991222e5a | Ruby | gizmore/ricer2 | /app/models/ricer/plug/params/base.rb | UTF-8 | 2,937 | 2.53125 | 3 | [] | no_license | module Ricer::Plug::Params
class Base
include Ricer::Base::Base
include Ricer::Base::Translates
def self.type_label(type); I18n.t!("ricer.plug.param.#{type}.label") rescue type.to_s.camelize; end
attr_reader :input, :value, :options
def initialize(options=nil, value=nil)
@inp... | true |
f37055a1ec8d5438662a7e8d5fe76c1a9785c758 | Ruby | briecodes/potluck | /app/models/event.rb | UTF-8 | 1,451 | 2.859375 | 3 | [
"MIT"
] | permissive | class Event < ApplicationRecord
has_many :user_events
has_many :users, through: :user_events
has_many :event_recipes
has_many :recipes, through: :event_recipes
validates(:title, {presence: true, uniqueness: true, length: {maximum: 20}})
validates(:location, {presence: true, length: {maximum: 100}})
valid... | true |
494500aeb9a9e64606d0adac5d20aacc96b3c552 | Ruby | toasterbob/review | /challenges/ruby/hackerrank/implementation/mig_birds.rb | UTF-8 | 965 | 3.6875 | 4 | [] | no_license | #!/bin/ruby
n = gets.strip.to_i
types = gets.strip
types = types.split(' ').map(&:to_i)
# your code goes here
def most_common(arr) #sort array first
arr.sort!
most_common = 0
most_common_count = 0
type_count = 0
prev = 0
arr.each do |type|
if prev == type
type_count += 1
... | true |
3289c601583d5c70c05f8773519deb6bfeeef262 | Ruby | keepcosmos/twitter-korean-text-ruby | /test/processor_test.rb | UTF-8 | 1,555 | 3.09375 | 3 | [] | no_license | require 'test_helper'
class ProcessorTest < Minitest::Test
def test_normalization
input = "그랰ㅋㅋㅋㅋㅋㅋ"
expected = "그래ㅋㅋ"
proccessor = TwitterKorean::Processor.new
assert_equal(expected, proccessor.normalize(input))
assert_equal(nil, proccessor.normalize(nil))
end
def test_tokenization
... | true |
512ec93c2f79fe09b676c2d5b05ab670caba452c | Ruby | shsachdev/ls101 | /small_problems/easy_problems/conditional_fun.rb | UTF-8 | 94 | 3.203125 | 3 | [] | no_license | def fixer(num)
if num > 8
num = 9
elsif num == 9
p "hello"
end
end
p fixer(10)
| true |
e553bc6b391f41189546d7db4bde9578dd1a0a86 | Ruby | ml1984/family_tree_rails | /familytree/spec/person_spec.rb | UTF-8 | 2,366 | 2.578125 | 3 | [] | no_license | require 'active_record'
require 'rspec'
require_relative '../app/models/person'
database_configuration = YAML::load(File.open('config/database.yml'))
configuration = database_configuration['test']
ActiveRecord::Base.establish_connection(configuration)
describe Person do
it "should validate the presence of a first ... | true |
881b75d4c88e4f95c437bf369918e654ddb77122 | Ruby | swatkns785/lets-jam-some-time | /spec/features/jamsessions/user_creates_jamsession_spec.rb | UTF-8 | 2,124 | 2.5625 | 3 | [] | no_license | require "rails_helper"
feature "user creates jamsession", %q(
As an authenticated user
I want to create a jamsession
So that I can organize music sessions with strangers
Acceptance Criteria
[ ] I must be able to create a jamsession from the meetups index page
[ ] I must be able to add a title, time, loca... | true |
226e6121ba577e2c0b55d7faf5c8450451e19400 | Ruby | rkray/ruby_script_blueprint | /ruby_script_blueprint.rb | UTF-8 | 1,579 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/ruby
# Author: René Kray <rene@kray.info>
# Date: 2020-04-14
require 'optparse'
require 'pp'
class RubyScriptBlueprint
attr_accessor :conf, :option
def initialize
@conf={}
# set defaults
@conf["configfile"]=ENV["HOME"]+"/.config/"+File.basename($0)+"/preferences"
end... | true |
50a77f657c9885913b61004b881af5ccdb212766 | Ruby | joker1007/simple_taggable | /spec/simple_taggable/tag_list_spec.rb | UTF-8 | 2,984 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe SimpleTaggable::TagList do
it "is Enumerable" do
expect(subject.class.ancestors).to include(Enumerable)
expect(subject).to be_respond_to(:each)
end
let(:tag_list) { SimpleTaggable::TagList.new }
describe "Constructor" do
it "should receive initial tags" do
tag... | true |
3425d91750c0d086482eb97bf4452078437390fb | Ruby | relynch91/classwork | /Week1/W1D2/rspec_exercise_1/lib/part_1.rb | UTF-8 | 555 | 4.09375 | 4 | [] | no_license | def average(num1, num2)
return (num1 + num2)/2.0
end
def average_array(arr)
return arr.sum.to_f/arr.length
end
def repeat(string, num)
new_string = ""
num.times {new_string << string}
new_string
end
def yell(string)
string.upcase! + "!"
end
def alternating_case(str)
new_str = []
word... | true |
349ec0d9979aa9de750e72fc5d1420f0bb74f543 | Ruby | nog/atcoder | /contests/arc104/a/main.rb | UTF-8 | 80 | 3.171875 | 3 | [] | no_license | A, B = gets.split.map(&:to_i)
x = (A + B) / 2
y = (A - B) / 2
puts "#{x} #{y}" | true |
afc4facbf1e3a54b686b60f1fbf0c5a99f2fad8d | Ruby | cice/wsdl-mapper | /lib/wsdl_mapper/naming/default_namer.rb | UTF-8 | 6,224 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'wsdl_mapper/dom/name'
require 'wsdl_mapper/naming/type_name'
require 'wsdl_mapper/naming/property_name'
require 'wsdl_mapper/naming/enumeration_value_name'
require 'wsdl_mapper/naming/namer_base'
module WsdlMapper
module Naming
# This is the default Namer implementation. It provides the de-facto stand... | true |
9338074246bd94a303f993fb0a0f68edeb738879 | Ruby | jamesascarter/boris_bikes2 | /spec/docking_station_spec.rb | UTF-8 | 1,136 | 3.15625 | 3 | [] | no_license | require 'docking_station'
require 'bike'
describe DockingStation do
let(:bike) { Bike.new }
let(:station) { DockingStation.new }
it "should accept a bike" do
bike
station
expect(station.bike_count).to eq(0)
station.dock(bike)
expect(station.bike_count).to eq 1
end
it "should release a ... | true |
759331572272280a5d94cc8da0052a1091131664 | Ruby | janeywanee/http_yeah_you_know_me | /lib/game.rb | UTF-8 | 205 | 3 | 3 | [] | no_license | class Game
attr_reader :number, :answer
# make it from reader tp attr_accessor later?
def initialize
@number = rand(0..100)
@answer = false
end
def start
"Start Guessing"
end
end
| true |
105a48c963087440b5fd3e29291b2b3cd39f973c | Ruby | mapuchila/ten_thousand_hours_app | /dev/import.rb | UTF-8 | 1,571 | 3.265625 | 3 | [] | no_license | require 'date'
require 'json'
require 'rubygems'
require 'data_mapper'
require '../models/project.rb'
require '../models/entry.rb'
require '../models/category.rb'
# config
project_id = 10
# prep work
puts 'Connecting to database...'
DataMapper.setup(:default, 'mysql://root:amalla@localhost/ten_thousand_hours_app')
p... | true |
21a1081ea1ccfe1cff992c5728689ec6f15ce2eb | Ruby | CindyChenx/rack-dynamic-routes-lab-nyc-web-060319 | /app/application.rb | UTF-8 | 615 | 3.015625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Application
@@item = [Item.new("Melon", 6), Item.new("Watermelon", 8)]
def call(env)
resp = Rack::Response.new
req = Rack::Request.new(env)
if req.path.match(/items/)
product_name = req.path.split("/items/").last
if item = @@items.find {|p| p.name == pr... | true |
e58c267aae6c5432822187bbe4188aa25901343d | Ruby | eebbesen/minutes_maid | /vendor/cache/ruby/2.5.0/gems/mocha-1.11.2/lib/mocha/method_matcher.rb | UTF-8 | 349 | 2.75 | 3 | [
"MIT",
"Ruby"
] | permissive | module Mocha
class MethodMatcher
attr_reader :expected_method_name
def initialize(expected_method_name)
@expected_method_name = expected_method_name
end
def match?(actual_method_name)
@expected_method_name == actual_method_name.to_sym
end
def mocha_inspect
@expected_method... | true |
df5e8b06075952fcce39609beecbbd14637c0bc3 | Ruby | cornjacket/enumerable | /spec/enumerable_spec.rb | UTF-8 | 3,314 | 3.828125 | 4 | [] | no_license | require "spec_helper"
describe "my_each" do
a = [1, 2, 3]
it "returns itself" do
expect(a.my_each{ |i| i }).to eq a
end
it "returns itself" do
expect([].my_each{ |i| i }).to eq []
end
it "sequentially processes each element in an array if given a block" do
result = []
... | true |
0f4826521e4757e09f2f2428157832a5ca15ef50 | Ruby | szapata427/learn-co-sandbox | /if-else-boolean.rb | UTF-8 | 138 | 2.8125 | 3 | [] | no_license |
def what_to_wear_today(weather)
if weather == "raining"
"Hooded raincoat"
elsif weather == "sunny"
"sunscreen"
end
end
| true |
6fc821b1f0ea9c5d9584fb8a07ca850563fd1dd9 | Ruby | athenaavalos/Homework-3 | /db/seeds.rb | UTF-8 | 1,779 | 2.71875 | 3 | [] | no_license | Product.delete_all
# . . .
Product.create(title: 'Floral Turquoise Opal Ring',
description:
%{<p>
This is a special and unique piece that will be sure to grab attention! The Floral Turquoise Opal Ring is hand crafted from genuine sterling silver and beautifully decorated with Turquoise and Opal inla... | true |
ce23418eddcefef3951f37a8d5159988effd67ec | Ruby | lorenzosinisi/robot-ruby | /lib/robot/play.rb | UTF-8 | 1,263 | 2.796875 | 3 | [] | no_license | module Roboruby
class Play
attr_reader :robot, :name, :parser
# saving command issued by human in order
# to be able to create a kind of "reverse" method in the future
attr_accessor :command, :command_x, :command_y, :command_f
def initialize(options={})
@board = options[:board] || Roboru... | true |
7e1bbd8b5d4dc646b925ef2f63223fbb2911c567 | Ruby | schwarro/ruby_fundamentals1 | /exercise4_3.rb | UTF-8 | 268 | 4.1875 | 4 | [] | no_license | #Compares the string of my name vs the user's name
my_name = "Rob"
puts "Please enter your name: "
user_name = gets.chomp
if my_name.casecmp(user_name) == 0
puts "Hey #{user_name}, we have the same name!"
else
puts "Hello #{user_name}, my name is #{my_name}."
end
| true |
41f686225d165d5d05f24c54004eacd30b2e3179 | Ruby | ViviVGL/log_reader | /reader.rb | UTF-8 | 463 | 2.671875 | 3 | [] | no_license | require_relative './lib/file_parser'
require_relative './lib/counter'
require_relative './lib/printer'
filename = ARGV.first
URL_REGEX = /request_to=\"(\S*)\"/
STATUS_REGEX = /response_status=\"(\d*)\"/
urls = FileParser.parse(URL_REGEX, filename)
statuses = FileParser.parse(STATUS_REGEX, filename)
url_count = Coun... | true |
e2753b426656e8181ced330d878b3f3d82fbbb50 | Ruby | DemoLesson/Tioki | /app/helpers/events_helper.rb | UTF-8 | 3,193 | 2.625 | 3 | [] | no_license | module EventsHelper
# Format the date for the event method
def date2format(event, row = "start_time", format = "%m/%d/%Y")
event[row].localtime.to_datetime.strftime(format) unless event[row] == nil
end
def event_hours(event, start_time = "start_time", end_time = "end_time", same_day = "%l:%M%P", diff_day = "%m/%... | true |
86bc9de77c3fffb7a41372cb266428b88fd4c869 | Ruby | insignia4u/i4u | /app/helpers/calendar_helper.rb | UTF-8 | 1,551 | 2.703125 | 3 | [] | no_license | module CalendarHelper
def parse_regex(text)
regex = /\{\{calendar(.*?)\}\}/
reset_regex = /\{\{resetcounter(.*?)\}\}/
new_text = text.gsub(regex) do |s|
fechas = "#{s}".match(/\{\{calendar(.*?)\}\}/)[1].split(" ")
begin
dates = fechas.map{|f| Date.parse(f)}
rescue ArgumentError
... | true |
ae2063a28be90f06a283cfc8935210dc5023ff5e | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/d9d744aef3be4e81b0853318427af085.rb | UTF-8 | 592 | 3.5625 | 4 | [] | no_license | class Bob
def hey(message)
Request.new(message).respond
end
class Request
def respond
if empty?
'Fine. Be that way!'
elsif all_caps?
'Woah, chill out!'
elsif question?
'Sure.'
else
'Whatever.'
end
end
private
attr_accessor :messa... | true |
441e86ed4888852a3495d5f897a7a1facc5f586e | Ruby | kkristof93/AoC-2017 | /Day-19/day19-part2.rb | UTF-8 | 424 | 3.546875 | 4 | [] | no_license | map = []
File.open('input.txt') do |file|
file.each_line do |line|
map.push(line)
end
end
x = 0
y = map[0].index('|')
dirX = 1
dirY = 0
steps = 0
while map[x][y] != ' '
c = map[x][y]
steps += 1
if c == '+'
if dirX != 0
dirX = 0
dirY = map[x][y + 1] != ' ' ? 1 : -1
else
dir... | true |
02ce9b7e1b071658d5ed98bd8be87ee7614ddd8d | Ruby | benja2208/BookmarkManager_Wednesday | /app/models/user.rb | UTF-8 | 588 | 2.578125 | 3 | [] | no_license | require 'bcrypt'
class User
include DataMapper::Resource
attr_reader :password
attr_accessor :password_confirmation
property :id, Serial
property :email, String, required: true
property :password_digest, Text
def password=(password)
@password = password
self.password_digest = BCrypt::Password.create(pass... | true |
20d2e54ea99287e0face9ff9b1d07e3fe403ce8a | Ruby | maddox/tvdb_party | /lib/tvdb_party/series.rb | UTF-8 | 2,487 | 2.6875 | 3 | [
"MIT"
] | permissive | module TvdbParty
class Series
attr_reader :client
attr_accessor :id, :name, :overview, :seasons, :first_aired, :genres, :network, :rating, :rating_count, :runtime,
:actors, :banners, :air_time, :imdb_id, :content_rating, :status
def initialize(client, options={})
@client = client
... | true |
97cc0125338ee1a1d8aea6345fa17baccdbb24a7 | Ruby | gmaglio/High-Score-Management-System | /src/DBHandler.rb | UTF-8 | 932 | 2.984375 | 3 | [] | no_license | #!/usr/bin/env /usr/bin/ruby
# Author: Gregory Maglio
# DBHandler.rb: Object to handle DB transactions via sqlite.
require 'rubygems'
require 'sqlite3'
class DBHandler
def initialize(mode = "RO")
if( mode.match("RW") )
@db = SQLite3::Database.new("../data/glm.db")
@db.execute("drop table ... | true |
4320eadb21d26ca1e8d50d3149c94abebf947ebc | Ruby | andres-arana/degree-7516-tp | /lib/plzero/scanner/scanner_state.rb | UTF-8 | 587 | 3.0625 | 3 | [
"MIT"
] | permissive | module PLZero
module Scanner
class ScannerState
def initialize
@buffer = ""
end
def on_transition(&transition)
@on_transition = transition
end
def on_token(&token)
@on_token = token
end
protected
def transition_to(new_state, initial_value ... | true |
e1a2a264dbf6ea5131062367c0cb9e11bc189eca | Ruby | jamesmilanhiggins/volunteer_tracker | /lib/volunteer.rb | UTF-8 | 1,636 | 2.84375 | 3 | [
"MIT"
] | permissive | class Volunteer
attr_reader(:volunteer_name, :project_id, :id)
define_method(:initialize) do |attributes|
@volunteer_name = attributes.fetch(:volunteer_name)
@project_id = attributes.fetch(:project_id)
@id = attributes[:id]
end
define_singleton_method(:all) do
returned_volunteers = DB.exec("S... | true |
8593d7fa92ddb005fb008b8ca195941d54e9e22a | Ruby | kelleyjenkins/pantry | /lib/pantry.rb | UTF-8 | 978 | 3.578125 | 4 | [] | no_license | require './lib/recipe'
require 'pry'
class Pantry
attr_reader :stock, :shopping_list, :cookbook
def initialize
@stock = Hash.new(0)
@shopping_list = {}
@cookbook = {}
end
def stock_check(item)
@stock[item]
end
def restock(item, quantity)
@stock[item] += quantity
end
def add_to_s... | true |
69d11a41abb3d313f8587181c54b0e5f948f6433 | Ruby | fabiosantossilva/grindr | /parse.rb | UTF-8 | 2,560 | 2.796875 | 3 | [] | no_license | require 'time'
class Entry
attr_reader :title, :authors, :links, :published, :content,
:xtitle, :xauthors, :xlinks, :xpublished, :xcontent # xhtml-containing attrs
def initialize(stanza)
#plain
@title = stanza.title
@published = stanza.published.to_s
@authors = generate_authors stanza
... | true |
5339a71dae4d57aae2988d743659b40db58eda55 | Ruby | natnatparis/first_scraper_web | /tests_ruby/lib/03_basics.rb | UTF-8 | 879 | 3.828125 | 4 | [] | no_license | def who_is_bigger(a,b,c)
if a != nil && b != nil && c != nil
return "a is bigger" if a > b && a > c
return "b is bigger" if b > a && b > c
return "c is bigger" if c > a && c > b
else return "nil detected"
end
end
#Methode permettant de combiner 3 fonctions portant sur des strings
#af... | true |
8a758aac305f1193b0d149061fca843f5214a52c | Ruby | dbach/puzzles | /ProjectEuler/special-sum.rb | UTF-8 | 858 | 3.5625 | 4 | [] | no_license | #!/sw/bin/ruby -w
#
# special sum set problems
# n=7 : 20, 31, 38, 39, 40, 42, 45
def verify_no_sum(sums, val)
unless sums[val].nil?
puts "ERROR: sum #{val} already exists"
return false
end
sums[val] = true
return true
end
def generate_subset(set, state)
result = Array.new
(0..set.size-1).each {... | true |
91005d93eb0f225d3af18cabfeb41e7d4f437f47 | Ruby | takagotch/rb | /list_pra/pretty-printer.rb | UTF-8 | 1,297 | 3.390625 | 3 | [] | no_license | #p
friends = [{ first_name: "Emily", last_name: "Laskin" },
{ first_name: "Nick", last_name: "Mauro" },
{ first_name: "Mark", last_name: "Maxwell" },]
me = { first_name: "Gregory", last_name: "Brown", friends: friends }
p me
#pp
require "pp"
friends = [{ first_name: "Emily", last_name: "L... | true |
134974441feccbffd15090145a42915186f7e1ee | Ruby | jacoblurye/wokewindows | /app/lib/parser/parser.rb | UTF-8 | 309 | 2.515625 | 3 | [
"MIT"
] | permissive | # base class for parsers
class Parser::Parser
def initialize(filename)
@filename = filename
end
def attribution
Attribution.new(filename: pathname.basename.to_s.sub(/\.gz$/, ""), category: category, url: url)
end
def pathname
Pathname.new(@filename)
end
def url
nil
end
end
| true |
68246a56a769275c9fc32e769b42ed91f5f8a9ab | Ruby | pmanko/slice | /app/models/validation/validators/default.rb | UTF-8 | 2,221 | 2.828125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Validation
module Validators
class Default
include DateAndTimeParser
attr_reader :variable
def initialize(variable)
@variable = variable
end
def value_in_range?(value)
{
status: status(value),
message: messa... | true |
3c5d0f4a3aa2ed34dea816d17c8fdfbceb56fd0e | Ruby | hussyvel/ruby | /VideoAulaOreally/extract_multiple_characters_with_range_object.rb | UTF-8 | 207 | 3.203125 | 3 | [] | no_license | # frozen_string_literal: true
story = 'Once upon a time in a land far, far away...'
p story[27..39]
p story.slice(27..39)
p story[32..1000]
p story.slice(32..1000)
p story[25..-9]
p story.slice(25..-9)
| true |
316e99226e3cc2d3e5bde60497c5bd2fa5677c51 | Ruby | correamth/learning-ruby | /basico/operadores.rb | UTF-8 | 508 | 3.78125 | 4 | [] | no_license | #numero1 = 0
#numero2 = 0
#total = 0
#puts 'informe o numero 1:'
#numero1 = gets.chomp.to_i
#puts 'informe o numero 2:'
#numero2 = gets.chomp.to_i
#total = numero1 + numero2
#total = numero1 - numero2
#total = numero1 * numero2
#total = numero1 / numero2
#puts total
# Operadores de comparacao
v1 = 11
v2 = 11
#... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.