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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
acfca8ff8d858cdf0c4ec294677737d6d678d2ca | Ruby | Seva-Sh/RB101 | /lesson_4/9_7_method_partition.rb | UTF-8 | 297 | 3.5625 | 4 | [] | no_license | [1, 2, 3].partition do |num|
num.odd?
end
# => [[1, 3], [2]]
odd, even = [1, 2, 3].partition do |num|
num.odd?
end
odd # => [1, 3]
even # => [2]
long, short = { a: "ant", b: "bear", c: "cat" }.partition do |key, value|
value.size > 3
end
# => [[[:b, "bear"]], [[:a, "ant"], [:c, "cat"]]]
| true |
097ddad188f1fc7207693ced71301911b0cd249d | Ruby | stormbrew/channel9 | /environments/ruby/simple_tests/006.if.rb | UTF-8 | 131 | 3.453125 | 3 | [
"MIT"
] | permissive | a = 2
if (a == 1)
puts "boom"
elsif (a == 2)
puts "boom!"
else
puts "what?"
end
if (a == 0)
puts "stuff"
end
puts "what?" | true |
1dcef81cf1ac4142d93987a7546a21de3745098b | Ruby | sinkoffr/Challenge-Problems | /remove_string_spaces.rb | UTF-8 | 195 | 3.75 | 4 | [] | no_license | # from codewars.com
# Simple, remove the spaces from the string, then return the resultant string.
def no_space(x)
x = x.split(" ").join("")
puts x
end
no_space('jfBm gk lf8hg 88lbe8 ') | true |
f63a7f1142d6cb19bd896e3f4de29f9b90c678c1 | Ruby | tipsypastels/porygon | /lib/porygon/discord_anniversary/teams.rb | UTF-8 | 950 | 3.359375 | 3 | [] | no_license | module Porygon
module DiscordAnniversary
class Teams
include Enumerable
def initialize(team1, team2)
@team1 = team1
@team2 = team2
end
def each
yield @team1
yield @team2
end
def [](name)
find { |team| team.name.casecmp(name).zero? }
... | true |
b0fd521a0d03d5a4baf597ee2b06dd667556541d | Ruby | jahonora/E6CP2A1 | /2 arrays/ejercicio3.rb | UTF-8 | 618 | 4.09375 | 4 | [] | no_license | # Dado el array:
# 1. Crear un método para eliminar todos los números pares del arreglo.
# 2. Crear un método para obtener la suma de todos los elementos del arreglo Utilizando .each
# 3. Crear un método para obtener el promedio de un arreglo.
# 4. Crear un método que incrementa todos los elementos en una unidad y... | true |
d0e4acc3586a3f724c21aea8aa60a000df8972b0 | Ruby | tkzwrk/furima-31033 | /spec/models/item_spec.rb | UTF-8 | 2,848 | 2.6875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Item, type: :model do
before do
@item = FactoryBot.build(:item)
end
describe '商品登録' do
context '商品登録がうまくいくとき' do
it 'titleとtext、imageとcategory_id、condition_idとcharge_id、area_idとday_id、priceが存在すれば登録できる' do
expect(@item).to be_valid
end
end
... | true |
9e8822c9fa60ea1900ac2fa2d0c65867b97a6e29 | Ruby | jonzingale/RubyProcessing | /hyper_cubes/dates_n_dots.rb | UTF-8 | 1,228 | 2.765625 | 3 | [] | no_license | require 'matrix'
ID = Matrix.columns([[1,0,0],[0,1,0],[0,0,1]])
VECT = Vector.elements([1,2,3])
BECT = Vector.elements([4,5,6])
def setup
size(1450,870) #HOME
# size(1920,1080) #JackRabbit
background(20) ; frame_rate 10
@w,@h = [width,height].map{|i|i/2.0}
@rand_c = (0..2).map{rand(255)} ; @i = 0
text_font creat... | true |
7464e1764bfe19023ad4a36bc4a6a2627a63e0b0 | Ruby | isabella232/p99 | /ruby/28.rb | UTF-8 | 230 | 3.375 | 3 | [
"LicenseRef-scancode-public-domain"
] | permissive | def lsort(list)
list.sort { |x, y| x.length <=> y.length }
end
def lfsort(list)
list.sort { |x, y|
list.count { |elem| elem.length == x.length } <=>
list.count { |elem| elem.length == y.length }
}
end
| true |
2bfc46f18ab482babde839b6e2094ac3855baf3c | Ruby | tony-rodriguez/phase-0-tracks | /ruby/hamsters.rb | UTF-8 | 783 | 3.890625 | 4 | [] | no_license | puts "Please input your hamster's name."
name = gets.chomp
puts "Enter 1 - 10 for volume level."
volume = gets.chomp.to_i
loop do
if volume >= 1 && volume <= 10
break
else
puts "Enter 1 - 10 for volume level."
volume = gets.chomp.to_i
end
end
puts "Enter fur color."
color = gets.chomp
puts "Good for a... | true |
27f7f218b340f64c5c64af793418550da3918ccd | Ruby | johneckert/programming_languages-prework | /programming_languages.rb | UTF-8 | 811 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def reformat_languages(languages)
new_hash = {}
#add each language => {it's characteristics} to the new hash from the OG hash
#in new hash give each language a style key that points at an empty array
languages.each do |style, languages_hash|
languages_hash.each do |language, characteristic_hash|
new_... | true |
5a15be3b32bbb4d6b83862c027e70884c1cd3482 | Ruby | usagrammer/mooovi | /app/models/scraping.rb | UTF-8 | 2,385 | 2.984375 | 3 | [] | no_license | class Scraping
def self.movie_urls
#linksという配列の空枠を作る
links = []
#Mechanizeクラスのインスタンスを生成する
agent = Mechanize.new
# socket error 対策
# agent = Mechanize.new do |a|
# a.keep_alive = false
# end
#パスの部分を変数で定義
next_url = ""
while true
#映画の全体ページのURLを取得
current_pag... | true |
68ad159069bc579460a17ee1b6e0b1dc45353ea3 | Ruby | sathia27/ecommerce | /app/services/card_type_detector_service.rb | UTF-8 | 786 | 3.0625 | 3 | [] | no_license | class CardTypeDetectorService
def initialize(card_number)
@card_number = card_number
end
def card_type
if valid_amex?
"AMEX"
elsif valid_discover?
"Discover"
elsif valid_mastercard?
"MasterCard"
elsif valid_visa?
"Visa"
else
"Unknown"
end
end
private... | true |
9dcadaf14e9e08d8695703379431d73141556f0f | Ruby | AlexStupakov/GC | /plot.rb | UTF-8 | 1,220 | 2.765625 | 3 | [] | no_license | require 'gnuplot'
require 'csv'
def read_data(filename)
filename = filename
csv_contents = CSV.read(filename, :col_sep => ' ')
csv_contents.shift
times = []
sizes = []
csv_contents.each do |row|
next if row[5].nil?
times << row[5].to_s
sizes << row[3]
end
p times
p sizes
[times,sizes]
... | true |
ddbe7e471feeceb9fa086529a1729d4fc5c80c68 | Ruby | tyage/SimpleAsm | /spec/simple.rb | UTF-8 | 1,811 | 2.703125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'simple_asm'
include SimpleAsm
describe Simple do
describe 'to_s' do
before do
@simple = Simple.new do
add 1, 0
sub 0, 1
end
end
it '各命令の長さは16' do
@simple.to_s.split("\n").each do |s|
expect(s.length).to eq 16
end
end
end
... | true |
f4fe3dcf27816250bee7413c20d3c58127d3fb55 | Ruby | davidmjiang/project_danebook | /db/seeds.rb | UTF-8 | 1,981 | 2.578125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
6358a39abc41754f71099d5144047340aa38ea60 | Ruby | learn-co-students/atl-bonus-lectures | /solving-tock/ruby/computer.rb | UTF-8 | 178 | 3.109375 | 3 | [] | no_license | class Computer
attr_reader :name, :piece
def initialize(name, piece)
@name = name
@piece = piece
end
def get_move(board)
board.legal_moves.sample
end
end
| true |
e35b6471d5c02dec8e91cdd9bda5179beb422c2d | Ruby | Paubox/paubox_ruby | /spec/helpers/message_helper.rb | UTF-8 | 2,224 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module Helpers
module MessageHelper
require 'base64'
BASE64_REGEX = Regexp.new(%r{^(?:[A-Za-z0-9+/]{4}\n?)*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$})
def message_defaults
{ from: 'me@test.paubox.com',
to: 'you@test.paubox.com, someone_else@test.paubox.com',
... | true |
9105cb3a7a2e13b1b53a5a753cf15985d10c2f97 | Ruby | SurajG/codeeval | /easy/armstrong-numbers/armstrong-numbers.rb | UTF-8 | 355 | 4.125 | 4 | [] | no_license | # An Armstrong number is an n-digit number that is equal to the sum of the n'th
# powers of its digits. Determine if the input numbers are Armstrong numbers.
def armstrong? num
n = num.length
num.chars.inject(0) { |sum,d| sum + (d.to_i ** n) } == num.to_i
end
File.open(ARGV[0]).each_line do |line|
puts armstron... | true |
1370f4a83668f8580c61bfbc2dc6520aaeacbe95 | Ruby | TmNguyen12/Algorithms_Practice | /Graphs/lib/topological_sort.rb | UTF-8 | 809 | 3.4375 | 3 | [] | no_license | require_relative 'graph'
# Implementing topological sort using both Khan's and Tarian's algorithms
# 1. Queue up all vertics with no edges
# 2. Pop off vertices from queue
# a. Remove vertex & it's outedges from the graph
# b. Push vertex into sorted results array
# c. Examine each destination vertices, push ... | true |
108920fb7935e9210da72991ed08afe2ceaad955 | Ruby | juhgles/hash_map_lru_cache | /lib/p03_hash_set.rb | UTF-8 | 1,164 | 3.6875 | 4 | [] | no_license | require_relative 'p02_hashing'
class HashSet
attr_reader :count
def initialize(num_buckets = 20)
@store = Array.new(num_buckets) { Array.new }
@count = 0
end
def insert(item)
hashed_item = hash_item(item)
p "num, hashed_item: #{item}, #{hashed_item}"
if hashed_item > (num_buckets - 1) || ... | true |
022e68f1d4c680c3792322a9d1b293589971a716 | Ruby | skateonrails/bitmap_editor | /app/pixel.rb | UTF-8 | 374 | 3.578125 | 4 | [] | no_license | class Pixel
WHITE_COLOUR = "O".freeze
InvalidColour = Class.new(StandardError)
def initialize
@colour = WHITE_COLOUR
end
def colour
@colour
end
def colour=(colour_string)
raise InvalidColour, "Colour must be a capital letter, from A to Z" unless colour_string =~ /^[A-Z]{1}$/
@colour = ... | true |
d6f0cc9cc872b755e768bfc9ae12ce92ab089e8f | Ruby | sakibahmad24/Ruby | /error.rb | UTF-8 | 246 | 3.453125 | 3 | [] | no_license |
random_nums = [4, 6, 10, 12, 15]
begin #try block
random_nums["one"]
rescue TypeError #catch block
puts "Wrong index type selected"
end
begin #try block
num = 20/0
rescue ZeroDivisionError #catch block
puts "the value is undefine"
end
| true |
afac5dbfb355294e90b938c4f4d51eaba39f5f3d | Ruby | pollygee/homework_2 | /bring_change_v2.rb | UTF-8 | 1,425 | 3.375 | 3 | [] | no_license | require 'pry'
require 'minitest/autorun'
class Register
@@QUARTER_DENOM = 25
@@DIME_DENOM = 10
@@NICKEL_DENOM = 5
@@PENNY_DENOM = 1
def initialize starting_register
@register = starting_register
@coins_used = [0,0,0,0]
end
def compare (coin_denomination, available_coins, total)
if total < (available_coin... | true |
8b4ede55b2aaa4d5d51dda2878287ff749a962d1 | Ruby | slayfer-dev/Challenges-sol | /Programming/Codeabbey/191/disassembly.rb | UTF-8 | 1,080 | 3.234375 | 3 | [] | no_license | #Author disassembly
total = gets.chomp.to_i
testCases = []
for input in 1..total
testCases.push(gets.chomp)
end
solution = []
testCases.each do |testCase|
lower = lSwap = 0
testCase.each_char.with_index do |char, index|
lower = index
for position in index + 1..testCase.length - 1
if testCase[posit... | true |
b27a12402115f3ec21c68d1cd301e8d6b4694ca1 | Ruby | 3ll3n/SportsTeamHomework | /specs/sports_team_spec.rb | UTF-8 | 945 | 3.015625 | 3 | [] | no_license | require ("minitest/autorun")
require ("minitest/rg")
require_relative ("../SportsTeam")
class SportsTeamSpec < Minitest::Test
def setup
@team = SportsTeam.new("Disney Rovers", ["Jasmine", "Cinderella", "Belle"], "Ursula", 0)
end
def test_return_teamname
assert_equal("Disney Rovers", @team.teamname)
... | true |
bbc8b10b53f9a9e0001dbd9de8dc4f4b69430a55 | Ruby | VarvaraBabkova/OO-Animal-Zoo-houston-web-062419 | /run.rb | UTF-8 | 447 | 3.234375 | 3 | [] | no_license | require_relative "lib/Animal.rb"
require_relative "lib/Zoo.rb"
require 'pry'
z1 = Zoo.new("Moscow Zoo", "Moscow")
z2 = Zoo.new("Houston Zoo", "Houston")
a1 = Animal.new("Cat", 10, "Manul", z1)
a2 = Animal.new("Bear", 400, "Mashka", z1)
a3 = Animal.new("Buffalo", 500, "Joe", z2)
a4 = Animal.new("Elephant", 4000, "Moe... | true |
cb85c3607c3e540b3fe11f53a7fa8462ea486000 | Ruby | chadrem/amf_socket_ruby | /lib/amf_socket/amf_rpc_connection.rb | UTF-8 | 3,558 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class AmfSocket::AmfRpcConnection < AmfSocket::AmfConnection
PING_INTERVAL = 5 # Seconds.
PING_TIMEOUT = 10 # Seconds.
attr_reader :latency
def send_request(command, params = {}, &block)
request = AmfSocket::RpcRequest.new(command, params)
block.call(request)
@sent_requests[request.message_id] = ... | true |
a9a83c3103de04342ee6fa8ff08c5c7f6c4f5ee6 | Ruby | ribaslucian/utfpr_web5_first_evaluation | /lib/unit.rb | UTF-8 | 1,620 | 3.234375 | 3 | [] | no_license | # docs
class Unit
# definimos as unidades basicas de uma metrica
@units = []
@base_unit = ''
attr_reader :units, :base_unit
# verifica se eh uma metrica valida
def self.is?(metric)
%w(velocity weight).include?(metric)
end
# obtem a instance de um metrica a partir dos parametros da url
def self.... | true |
f6db487217164b297d9e8c69553e39bdd261d614 | Ruby | fakenine/btcengine_test | /order.rb | UTF-8 | 1,006 | 3.25 | 3 | [] | no_license | class Order
attr_reader :id, :user_id, :direction, :btc_amount, :price
attr_accessor :state
def initialize(id:, user_id:, direction:, price:)
@id = id
@user_id = user_id
@direction = direction
@btc_amount = 1
@price = price
@state = 'queued'
validate!
end
def executed!
@stat... | true |
bcb1262ac666a1c5ca7b487352066e55b1a63009 | Ruby | james-cape/cross_check | /test/league_statistics_test.rb | UTF-8 | 3,530 | 2.609375 | 3 | [] | no_license | require 'simplecov'
SimpleCov.start
require 'minitest/autorun'
require 'minitest/pride'
require './lib/stat_tracker'
class LeagueStatisticsTest < Minitest::Test
def setup
game_path = './test/data/dummy_game.csv'
team_path = './test/data/team_info.csv'
game_teams_path = './test/data/dummy_game_teams.csv'
... | true |
3a15d4b25d9b5eff6af9f97dccc9d738902ec1ab | Ruby | srajiang/app-academy-classwork | /w3/Untitled-1.rb | UTF-8 | 173 | 3.15625 | 3 | [] | no_license | def sub(arr)
p arr
return [[]] if arr.empty?
last = arr.pop
prev_call = sub(arr[0..-1])
prev_call.each.with_index {|ele, idx| prev_call[idx] << last}
end | true |
4ed2ef6f706dfa8b01f35f9e1a8e11df1f45e108 | Ruby | jcsky/ch12_compound_patterns | /duck/quackologist.rb | UTF-8 | 98 | 2.6875 | 3 | [] | no_license | class Quackologist
def update(duck)
puts "Quackologist: #{duck.class} just quack"
end
end
| true |
df6c9cbcbf5f47428890dfe8d2d5264744792241 | Ruby | StarPerfect/nrel_and_google_api | /app/models/google_route.rb | UTF-8 | 477 | 2.953125 | 3 | [] | no_license | class GoogleRoute
attr_reader :distance, :duration, :directions
def initialize(data = {})
@distance = data["routes"][0]["legs"][0]["distance"]["text"]
@duration = data["routes"][0]["legs"][0]["duration"]["text"]
@directions_array = data["routes"][0]["legs"][0]["steps"]
end
def directions
direct... | true |
95e35132c94cb0efd873ee99d73afda5597f88bf | Ruby | chrisvans/dev-sprint10 | /lolcat.rb | UTF-8 | 1,083 | 3.375 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
class LolCatViewer
def self.run(links=nil)
loldocs = Nokogiri::HTML(open("http://www.lolcats.com/gallery/new.html"))
iterable_cats = loldocs.css('.gallery-item img')
if (not links) or (links > iterable_cats.length)
links = 1
end
$i = 0
cat_array = []
while... | true |
468bb9bd9b2ca9b63e0c54a031beba3f97e048b9 | Ruby | no-tech/warcraft3_enh | /lib/peasant.rb | UTF-8 | 183 | 2.8125 | 3 | [] | no_license | require_relative "unit"
class Peasant < Unit
attr_accessor :health_points, :attack_power
def initialize(hp = 35, ap = 0)
super(hp,ap)
end
remove_method :attack!
end
| true |
8a3dd9ccc9e268a7e1f4176c06049e3fda0b10a1 | Ruby | yaseminyurekli/parrot-ruby-ruby-apply-000 | /parrot.rb | UTF-8 | 197 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Create method `parrot` that outputs a given phrase and
# returns the phrase
def parrot( name= "My name is Yaso")
puts "#{name}"
end
def parrot (squawk = "Squawk!")
puts "#{squawk}"
squawk
end
| true |
5f8db2e201fe556b5b4ffe3531d212ba2ddd38ac | Ruby | swryu0906/WDI | /w04/d04/homework/main.rb | UTF-8 | 6,043 | 3.703125 | 4 | [] | no_license | require_relative 'animal'
require_relative 'client'
require_relative 'shelter'
require_relative 'seed'
class Main
include Seed
attr_accessor :shelter
def initialize
# @shelter = Shelter.new(name: "HappiTails")
self.shelter = create_seed
end
def start
display_title
main_menu
end
def d... | true |
d889a62832eb309a345a04f0bd84114d6a5c4e8d | Ruby | semani2/BackChannelApplication | /app/models/user.rb | UTF-8 | 455 | 2.640625 | 3 | [] | no_license | class User < ActiveRecord::Base
attr_accessible :name, :password, :username, :usertype
has_many :posts
validates :username , :presence =>true
validates :password , :presence =>true
validates :name , :presence =>true
def User.authenticate (username1,password)
user1 = User.find_by_username(username1)
... | true |
2246967a4436f30c14bcea5a7878b788fa8b89a8 | Ruby | Tooconfident/phase-0 | /week-5/gps2_2.rb | UTF-8 | 3,532 | 4.40625 | 4 | [
"MIT"
] | permissive | # Method to create a list
# input: string of items separated by spaces (example: "carrots apples cereal pizza")
# steps:
# call the method food_list
# set default quantity (quantity = 0)
# creat a hash, where key is item and value is quantity
# print the list to the console [can you use one of your other metho... | true |
46f8088395bfbbc64665cea49075e9752be002a0 | Ruby | krismacfarlane/godot | /w01/d05/student/refactored_guess_the_numbers.rb | UTF-8 | 1,951 | 4.5625 | 5 | [] | no_license | # *Read* through the following code
# Write comments above *each line* explaining what it does
# pulling in a gem
require 'colorize'
# Methods
# this method adds a random number from range 1-10 and adds to array
def generate_random_number
(1..10).to_a.sample
end
# prints a message in green
def alert(message)
$s... | true |
e0af68ff76402ee66a17ed4a0c1c63486551e226 | Ruby | dredozubov/rotary | /spec/storage/redis_spec.rb | UTF-8 | 2,057 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'rotary/storage/redis'
require 'rotary/serializer/marshal'
require 'storage/shared_examples'
require 'redis'
describe Rotary::Storage::Redis do
let(:obj) { OpenStruct.new(a: 1, b: 2) }
let(:connection) { Rotary::Storage::Redis.default_connection }
let(:serializer) { Rotary::Seriali... | true |
c62a27d1bcaaa4b7c9f46f33cb68df337f13da1b | Ruby | klapuch/periodical | /src/czech_word/slovnik_cizich_slov_words.rb | UTF-8 | 889 | 2.921875 | 3 | [] | no_license | # frozen_string_literal: true
require 'nokogiri'
module CzechWord
class SlovnikCizichSlovWords
def initialize(pages)
@pages = pages
end
def all
position = 0
words = []
@pages.all.each do |page|
html = Nokogiri::HTML(page.html())
values = html.xpath('//div[@id="co... | true |
b1b0e571dc6768216df29047ce4ddfc7f8e23152 | Ruby | avr567/citySim9006 | /player.rb | UTF-8 | 437 | 3 | 3 | [] | no_license | class Player
#attributes are the player's name and the number of toys, books and classes the player has or has visited. The location is the current location of the player
attr_accessor :name
attr_accessor :num_toys
attr_accessor :num_books
attr_accessor :num_classes
attr_accessor :location
def ... | true |
4f5a8891630db1ff7546410b7e1bd13ea200efad | Ruby | tom-weatherhead/3d-labyrinth | /ruby/Labyrinth.rb | UTF-8 | 19,568 | 3.34375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
# The labyrinthine abbey library in Ruby - October 14, 2013
require 'set'
class RoomInfo
attr_accessor :levelNumber
attr_accessor :roomNumber
# Create the object
def initialize(levelNumber, roomNumber)
@levelNumber = levelNumber
@roomNumber = roomNumber
end
# To string
def... | true |
9ae574c4a900f7b9f3ce89c5ba997b42c9a2850f | Ruby | imjoeco/postr | /app/models/user_favorite_list.rb | UTF-8 | 551 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | class UserFavoriteList < ActiveRecord::Base
attr_accessible :items, :user_id
belongs_to :user
serialize :items
def add_item(item_id, title)
index = self.items.index { |li| li[:id] == item_id }
unless index
new_item = {
id:item_id,
title:title,
created_at:Time.now
}
... | true |
512fe60a59735ba868764145a52e7e77b2b8d476 | Ruby | jaruchti/PragmaticRuby | /Chapt9/scope.rb | UTF-8 | 478 | 3.84375 | 4 | [] | no_license | #Demonstrates scope and block-local variables in Ruby
#Example #1, local variable used in block
square = "yes"
total = 0
[ 1, 2, 3 ].each do |val|
square = val * val;
total += square;
end
puts "Total = #{total}"
puts "Square = #{square}"
#Example #2, block-local variable used so local variable retains prior val... | true |
15c839377e0aef3d65d8f83200ba0b408a2a2958 | Ruby | htlcnn/FAMILUG | /ruby/pe002.rb | UTF-8 | 555 | 3.484375 | 3 | [
"BSD-2-Clause"
] | permissive | #!/usr/bin/env ruby
#
class PE002
def fib(n)
s = Math.sqrt(5)
x = (1 + s) ** n
y = (1 - s) ** n
return ((x - y) / (2**n * s)).to_i
end
def solve
max = 4000000
sum = 0
n = 1
num = fib n
while num < max
if num % 2 == 0
... | true |
a3baa4a0f45cf2cf890fd586c6a3358f94feb7b6 | Ruby | loganyu/leetcode | /problems/122_best_time_to_buy_and_sell_stock_ii.rb | UTF-8 | 1,751 | 4.03125 | 4 | [] | no_license | =begin
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).
Note: You may not engage in multiple transactions at the same... | true |
f3999f7cbf085b1879e51c6aa7cbe5a4b52e2745 | Ruby | OMYDUDU/projecteuler | /58.rb | UTF-8 | 1,183 | 4.15625 | 4 | [] | no_license | # Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length 7 is formed.
# 37 36 35 34 33 32 31
# 38 17 16 15 14 13 30
# 39 18 5 4 3 12 29
# 40 19 6 1 2 11 28
# 41 20 7 8 9 10 27
# 42 21 22 23 24 25 26
# 43 44 45 46 47 48 49
# It is interesting to note that the odd s... | true |
2eaf14a1af6a622801803139050c98f0c117776a | Ruby | lep-eoll/billet-bullet | /lib/reporter.rb | UTF-8 | 6,171 | 2.75 | 3 | [] | no_license | class Reporter
def product_report(output_filename = "product_report_total_sales_to_#{Time.now.strftime('%m_%d')}.xls")
book = Spreadsheet::Workbook.new
Spree::Product.all.group_by {|product| product.name[0].upcase }.sort.each do |alpha_product|
# ap "NEW SHEET #{alpha_product[0]} ----------------------... | true |
8e09fda5fc00052205adce8bac2e40cb82084e4c | Ruby | gus77avoruiz/18xx | /assets/app/view/game/part/track_curvilinear_half_path.rb | UTF-8 | 3,489 | 2.703125 | 3 | [
"LicenseRef-scancode-free-unknown",
"MIT"
] | permissive | # frozen_string_literal: true
require 'view/game/part/track_curvilinear_path'
require 'view/game/part/base'
module View
module Game
module Part
class TrackCurvilinearHalfPath < TrackCurvilinearPath
needs :exits
needs :color, default: 'black'
needs :width, default: 8
needs :... | true |
2533c95e2e3ac730974ed3621c5c80d34288cce4 | Ruby | anattrass/cx3_8 | /week_2/day_4/structuring/specs/vehicle_spec.rb | UTF-8 | 261 | 2.65625 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../vehicle.rb')
class TestVehicle < Minitest::Test
def setup
@vehicle = Vehicle.new(4)
end
def test_vehicle_has_4_wheels
assert_equal(4, @vehicle.number_of_wheels)
end
end | true |
a6343b6dd26b5664b84ffba24fce767ff394c959 | Ruby | tindervest/solitaire | /lib/solitaire.rb | UTF-8 | 1,207 | 2.96875 | 3 | [] | no_license | $:.unshift File.expand_path("../solitaire", __FILE__)
require 'text_handler'
require 'crypto_service'
require 'deck_cutter'
require 'deck'
module Solitaire
class Solitaire
attr_writer :text_handler, :crypto, :deck, :deck_cutter
def process(message)
text = text_handler.processing_input(message)
... | true |
5d50d98360426309fb5534088fda2a45e027a554 | Ruby | nfogravity/asterbot | /skill_changer.rb | UTF-8 | 1,645 | 2.875 | 3 | [] | no_license | require 'open-uri'
require 'json'
require 'pry'
def replace_skill(json, n, new_text)
monster = json[n.to_s]
skill_text = monster["skill_text"]
skill_text = skill_text.gsub(/Cool Down.*minimum/, new_text)
monster["skill_text"] = skill_text
json[n.to_s] = monster
json
end
def write_dex(dex)
f = File.open(... | true |
3c4ee0ea989f388867698375178baa354ddb4a41 | Ruby | krutsmat/MI-RUB | /shortest_path/lib/algorithms/dijkstra.rb | UTF-8 | 1,333 | 3.296875 | 3 | [] | no_license | require_relative "algorithm"
require_relative "../graphtheory/node"
module Algorithms
class Dijkstra < Algorithms::Algorithm
def get_shortest_paths()
s = empty_solution
actual_node = 0
# from all possible starting points
graph.n.times do |start|
visited = A... | true |
1c0c65e74709bcc7ecda9c3b645e041241baf339 | Ruby | alu0100403619/prct07 | /lib/fracc_main.rb | UTF-8 | 700 | 3.578125 | 4 | [] | no_license | require 'fraccion.rb'
puts "Programa Principal"
f1 = Fraccion.new(2,4)
f2 = Fraccion.new(-3,2)
red = f1.reduccion
fl = f1.to_f
fabs = f2.abs
rec = f1.reciprocal
fm = -f2
sum = f1 + f2
rest = f1 - f2
mult = f1 * f2
div = f1 / f2
puts "f1: #{f1}"
puts "f2: #{f2}"
puts "reduccion de #{f1}: #{red}"
puts "float de #{f1}:... | true |
951dc0d15427c9ed909e8df7cc1feff3631f7f95 | Ruby | jollopre/bambooing | /lib/bambooing/support/time.rb | UTF-8 | 1,100 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'date'
module Bambooing
module Support
class Time
class << self
SECONDS_PER_MINUTE = 60.freeze
MINUTES_PER_HOUR = 60.freeze
SECONDS_PER_HOUR = MINUTES_PER_HOUR*SECONDS_PER_MINUTE.freeze
MAX_BREAK_MINUTES = MINUTES_PER_HOUR
def rand_work(date: nil, hours:, st... | true |
c7441c967fc02adf3d2ca9f8b04110e76d707e52 | Ruby | mgrachev/pivotal_tracker_telegram_bot | /lib/pivotal_tracker/bot.rb | UTF-8 | 3,769 | 2.734375 | 3 | [] | no_license | require_relative '../pivotal_tracker'
module PivotalTracker
class Bot < Base
BOT_NAME = 'Pivotal Tracker Bot'.freeze
HELP = <<HELP
Initially, the need to integrate the bot with Pivotal Tracker.
See: https://github.com/mgrachev/pivotal_tracker_telegram_bot
Available commands:
/start - Start a #{BOT_NAME}
/tr... | true |
2c95fe1f3dd30d219dd0ef00b364851279bc120c | Ruby | sandbochs/negamax | /spec/end_state_spec.rb | UTF-8 | 1,124 | 2.734375 | 3 | [] | no_license | require 'spec_helper'
describe EndState do
context "default states" do
it "has the default state WIN" do
EndState.WIN.should eq EndState.new(1, "WIN")
end
it "has the default state TIE" do
EndState.TIE.should eq EndState.new(0, "TIE")
end
it "has the default state LOSE" do
... | true |
d63411cb35a465444b0867145a8096372846328e | Ruby | aleksandraszwaczka/code_sensei_course | /zjazd_2/9_attr_reader_and_writter.rb | UTF-8 | 353 | 3.25 | 3 | [] | no_license | class Wallet
attr_writer :balance
attr_reader :balance
end
wallet = Wallet.new
wallet.balance = 120
puts wallet.balance
#można zamiast razem readera i writera użyć attr_accessor
# attr_accessor :balance, :owner
#attr_reader pozwala na czytanie danego symbolu
#attr_writer pozwala na dopisanie danego symbolu (:ba... | true |
3808b01dfb4039560cb3102ece5c442220360ca3 | Ruby | a-G-a-o/RB101 | /small_problems/easy_2/1.rb | UTF-8 | 455 | 4.46875 | 4 | [] | no_license | =begin
Build a program that randomly generates and prints Teddy's age.
To get the age, you should generate a random number between 20 and 200.
Input: String name
Output: String with age integer string concatenation
Rules: age must be a random number between 20 and 200
=end
puts "Enter a name and I will tell... | true |
ea400379d34d343b615dcb10759d5ddb1af6a415 | Ruby | vshl/exercism.io | /luhn/luhn.rb | UTF-8 | 663 | 3.875 | 4 | [] | no_license | =begin
Write your code for the 'Luhn' exercise in this file. Make the tests in
`luhn_test.rb` pass.
To get started with TDD, see the `README.md` file in your
`ruby/luhn` directory.
=end
class Luhn
def self.valid?(number)
return false if number =~ /[[:alpha:]]/ || number =~ /[[:punct:]]/
number = number.gsu... | true |
ca78d0b45118b1a635d45e8aa4055dc514a0b7bc | Ruby | txus/fuby | /test/compiler_test.rb | UTF-8 | 2,952 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'test_helper'
module Fuby
describe Compiler do
def compile(str)
Compiler.eval(str)
end
describe 'a string' do
it 'is a Fuby::String' do
compile('"foo"').must_be_kind_of Fuby::String
end
describe 'when dynamic' do
it 'is also a Fuby::String' do
co... | true |
9ba93d5fcda23d1046feef875b3031b29ab4e121 | Ruby | tk0358/meta_programming_ruby2 | /chapter6/11hooks.rb | UTF-8 | 140 | 2.984375 | 3 | [] | no_license | class String
def self.inherited(subclass)
puts "#{self}は#{subclass}に継承された"
end
end
class MyString < String; end | true |
79f5b8e5e79492e9af4865e721965f7071fcd2e3 | Ruby | michaelkoper/country_list | /spec/country_spec.rb | UTF-8 | 3,185 | 3.296875 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Country do
let(:country) { Country.new('NL') }
it 'allows to create a country object from a country code' do
country = Country.new('NL')
expect(country.data).not_to be_nil
end
it 'allows to create a country object from a lower... | true |
997984aa8aceba24e23cb358a412c66ba3463319 | Ruby | bubje/aoc-2020 | /14/ruby-14.rb | UTF-8 | 2,898 | 3.609375 | 4 | [] | no_license | #!/usr/bin/ruby
#
# solution for day 14
# some basic checking: did we get an argument?
if ARGV.length != 1
puts "Usage: script <filename>"
exit 1
end
filename = ARGV[0]
# read data
file = File.open(filename)
file_data = file.readlines.map(&:chomp)
file.close
# part 14a
# some start up values
zero_mask = 2 << 37 ... | true |
b56c994bb1e260109aa1d2775314211ec978a4ba | Ruby | Hassanmir92/exercism | /ruby/nucleotide-count/nucleotide_count.rb | UTF-8 | 576 | 3.78125 | 4 | [] | no_license | class Nucleotide
def self.from_dna(string)
nucleotides = string.chars
raise ArgumentError.new("Invalid DNA #{string}") unless nucleotides.all?(&validate)
new(nucleotides)
end
def self.validate
proc { |nucleotide| %w(A C G T).include?(nucleotide) }
end
attr_reader :nucleotides
def initiali... | true |
10e87dbfbbfa7cdce0f2a46f1e38d5e0e1021e7d | Ruby | slntopp/Labs | /Численные методы/EulerMethodExplicit/funcs.rb | UTF-8 | 4,941 | 2.890625 | 3 | [] | no_license | require 'pry'
require "../Метод Гаусса/art.rb"
require '../../include/gauss.rb'
#################################################
# => #
# => Система уравнений #
# => #
###############################... | true |
737329f567cf8876746da9fcf3704d4349c922aa | Ruby | webovator/ruby-challenges | /oop_song2.rb | UTF-8 | 1,033 | 3.828125 | 4 | [] | no_license | class Album
def set_album=(album_title)
@album = album_title
end
def get_album
return @album
end
def set_band=(band)
@band = band
end
def get_band
return @band
end
end
class Song < Album
def set_name=(name)
@name = name
end
def get_name
return @nam... | true |
1a7654b63decf53212494bc735210d20d5bb80c8 | Ruby | rcchan/quality-measure-engine | /lib/qme/map/map_reduce_executor.rb | UTF-8 | 7,705 | 2.546875 | 3 | [] | no_license | module QME
module MapReduce
# Computes the value of quality measures based on the current set of patient
# records in the database
class Executor
include DatabaseAccess
# Create a new Executor for a specific measure, effective date and patient population.
# @param [String] measure_id... | true |
622f2657d40226a1226ea418e39368368de7c4e5 | Ruby | Rainbow-Ninja/ruby | /Day6/MathBlock.rb | UTF-8 | 1,625 | 4.40625 | 4 | [] | no_license | # def total(num1, num2)
# sum = num1 + num2
# return sum
# end
# puts "The sum of your two numbers is #{total(4, 4)}"
# #-------------------------------------------------------
# def total(num1, num2)
# sum = num1 + num2
# yield(sum)
# end
# total(4,4) do |addition_total|
# puts "... | true |
bc8ab18ff3d198b6ef44e80ef134ec4c197fa0c0 | Ruby | raghavendra-prithvi/assignment | /app/controllers/home_controller.rb | UTF-8 | 542 | 2.515625 | 3 | [] | no_license | class HomeController < ApplicationController
require 'rest-client'
FACEBOOK_URL = 'https://takehome.io/facebook'
TWITTER_URL = 'https://takehome.io/twitter'
def index
twitter_comments = call_url TWITTER_URL
facebook_comments = call_url FACEBOOK_URL
render json: {twitter: twitter_comments, facebo... | true |
7c127698e18693d97e20dd7bafc0b1b091adc065 | Ruby | creativechain/crea-ruby | /lib/crea/stream.rb | UTF-8 | 13,731 | 2.890625 | 3 | [
"MIT"
] | permissive | module Crea
# Crea::Stream allows a live view of the CREA blockchain.
#
# Example streaming blocks:
#
# stream = Crea::Stream.new
#
# stream.blocks do |block, block_num|
# puts "#{block_num} :: #{block.witness}"
# end
#
# Example streaming transactions:
#
# strea... | true |
2914a2f0c6fbab76af8b064562f53ce79fddbfa7 | Ruby | pboling/striuct | /lib/striuct/instancemethods/assign.rb | UTF-8 | 774 | 2.796875 | 3 | [
"MIT"
] | permissive | class Striuct; module InstanceMethods
# @group Assign / Unassign
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
def assigned?(key)
@db.has_key? autonym_for_key(key)
end
alias_method :assign?, :assigned?
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / i... | true |
d8aa039a2fe3e76ffa9f0f10631118a65ed0a4ad | Ruby | daniel-ivanco/data_normaliser | /lib/source_combinator.rb | UTF-8 | 1,741 | 3.140625 | 3 | [] | no_license | class SourceCombinator
require 'csv'
require 'json'
require './parse_journals'
require './parse_articles'
require './parse_authors'
def initialize(journals_filename, articles_filename, authors_filename)
@journals_filename = journals_filename
@articles_filename = articles_filename
@aut... | true |
0b7c6f728886986058609dce1c22361a8a280c9f | Ruby | zidizei/authlane-example | /modular/modular-app.rb | UTF-8 | 1,485 | 2.546875 | 3 | [] | no_license | require 'sinatra/base'
require 'sinatra/contrib'
require 'sinatra/authlane'
# Using AuthLane in a modular app is very similar, except you - of course - have
# to register the AuthLane extension manually using `register Sinatra::AuthLane`.
# Additionally, the Cookie helpers provided by `sinatra/contrib` are required by... | true |
fc49eedd001ad282ce510bee47d4bbd35685f035 | Ruby | Jose-N/Launch-Academy-Week-2 | /kickball-site/spec/models/player_spec.rb | UTF-8 | 1,174 | 2.90625 | 3 | [] | no_license | require "spec_helper"
RSpec.describe Player do
let(:player) {Player.new('jose', 'catcher', 'phillies')}
describe "#new" do
it 'should take a name, position, and team_name as arguments' do
expect(player).to be_a(Player)
end
end
describe '#name' do
it 'should have a reader' do
expect(pl... | true |
19fd105d4851a74176a95c48bb56d1f60c8beee5 | Ruby | benhawker/sorting-algorithms-ruby | /lib/happy_number.rb | UTF-8 | 809 | 4.1875 | 4 | [] | no_license | # Write an algorithm to determine if a number is "happy".
# A happy number is a number defined by the following process: Starting with any positive integer,
# replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay),
# or it loops endlessly in a ... | true |
9e9fd7b49259c9cb34be336fce3a9846eadc7834 | Ruby | RedTeamSeed/Studios | /challs/codeabbey/013/SYLAR.rb | UTF-8 | 518 | 3.46875 | 3 | [] | no_license | #!/usr/bin/ruby
def read_file(filename)
respuesta=" "
total = 0
File.foreach(filename).with_index do |line|
line=line.split(" ")
array_length= line.length
if array_length > 1
line.each { |num|
temp = num.chars
temp.each_with_index { |val, index|
total = total + (val.to_i * (ind... | true |
8d1ae3079c0e106fdc6ad2b10cb802b07dfc3864 | Ruby | vbuterin2/learn_ruby_basic_1 | /hash_iter.rb | UTF-8 | 255 | 3.140625 | 3 | [] | no_license | people = { jordan: 32, tiffany: 27, kristine: 10, heather: 29}
people.each_value do |key|
puts key
end
people = { jordan: 32, tiffany: 27, kristine: 10, heather: 29}
people[:leann] = 42
puts people
puts people2 = people.invert
people.merge(people2) | true |
f6e8bec527823d1b22bff01d59fa643737ad5cc1 | Ruby | sul-dlss/sul_pub | /lib/doi_search.rb | UTF-8 | 1,446 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require 'identifiers'
class DoiSearch
# The first authoritative result(s) are returned.
# If an authoritative local match is found, no remote services are hit.
# WoS hits need to be post-processed because the API does partial string
# matching for DOI queries, unfortunately.
# ... | true |
467c7380299beb17d203861c386f2f255196d33e | Ruby | srih4ri/advent_of_code_2019 | /ruby/day_1/problem_1.rb | UTF-8 | 510 | 3.625 | 4 | [] | no_license | def assert(expected, actual)
if expected == actual
puts "Test OK: #{expected}"
else
puts "Test Failed : Exp: #{expected} Actual : #{actual}"
end
end
def fuel_required(mass)
(mass.to_i/3) - 2
end
assert(2,fuel_required(12))
assert(2,fuel_required(14))
assert(654, fuel_required(1969))
assert(33583, fue... | true |
d3c9a025fa11c9d9566faa69389edd8397fec508 | Ruby | masafumi0612/y-saori | /cgi-bin/create_table.cgi | UTF-8 | 31,049 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/ruby
require 'cgi'
require "cgi/escape"
require 'json'
require 'digest'
require "fileutils"
require 'securerandom'
require_relative '../lib/source_url_controller'
require_relative '../lib/document_info_controller'
require_relative '../lib/document_info'
require_relative '../lib/statistics_info'
require_rela... | true |
f208ea6ec714d2aee95b785bb31116e662e270a5 | Ruby | tn-0214/Club_BoL | /spec/models/item_spec.rb | UTF-8 | 3,471 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Item, type: :model do
describe "#create" do
before do
category = FactoryBot.create(:category)
@item = FactoryBot.build(:item, category_ids: category.id)
end
context '出品成功時' do
it '全て規定通り入力されていれば出品できる' do
expect(@item).to be_valid
end
it 'daily... | true |
5b5793228bdc0bfcf6c8694597dbfa6321f912cc | Ruby | Tdamas/ruby_dec_2017 | /Tamisha_Damas/Ruby/OOP/wizard_ninja_samurai/wizard.rb | UTF-8 | 510 | 3.296875 | 3 | [] | no_license | require_relative 'human'
class Wizard < Human # Wizard inherits from Human
def initialize
super
@health = 50
@intelligence = 25
self
end
def heal
@health += 10
self
end
def fireball(obj)
# Wizard should have a method called fireball, which when invoked, decrease the health of whi... | true |
a7b138f091c5cd59b2be2a3e51fb011be9077d7e | Ruby | miguelmorais7/Curso-Ruby-Puro | /Aula 03/for.rb | UTF-8 | 225 | 3.265625 | 3 | [] | no_license | #Aula 03 - Estruturas de controle
fruits = ['Maçã', 'Uva', 'Morango']
for fruit in fruits
puts fruit
end
fruits = ['Maçã', 'Uva', 'Morango']
fruit = "Laranja"
for fruit in fruits
puts fruit
end
puts fruit | true |
7264dfcd08e447b091198b124f71cdd093ab586c | Ruby | tdhzz/Algorithm | /week01/tdhzz/70_climbing_stairs.rb | UTF-8 | 859 | 3.953125 | 4 | [] | no_license | =begin
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Example 1:
``` ruby
Input: 2
Output: 2
Explanation: T... | true |
af1d74a50f2e07ac067050c078683ef2d9dc95f5 | Ruby | neffnet/blocmetrics | /db/seeds.rb | UTF-8 | 640 | 2.671875 | 3 | [] | no_license | # create a test user if not already
u = User.where(username:'test').first_or_create do |u|
u.username = 'test'
u.password = 'hello'
u.password_confirmation = 'hello'
u.email = 'test@example.com'
u.skip_confirmation!
u.save
end
# give test user some applications
4.times do
new_domain = Faker::Internet.do... | true |
035019e20109d6eba275595bb8f32a453566f2f1 | Ruby | bsheldon/burghers | /lib/burghers/response.rb | UTF-8 | 787 | 2.671875 | 3 | [
"MIT"
] | permissive | module Burghers
class Response
attr_reader :topics, :tags, :entities, :raw
def initialize(json)
@raw = json
@topics = []
@tags = []
@entities = []
@relations = []
if @raw['doc']['meta']['language'] == "InputTextTooShort"
raise DocumentTooSmallError, "Document too... | true |
9dd76e58e19118aae4768b012202d1bddb5f33de | Ruby | flyeagle/call_juiz | /yahooapis.rb | UTF-8 | 5,607 | 2.515625 | 3 | [] | no_license | require 'open-uri'
require 'json' if RUBY_VERSION < '1.9.0'
require 'rexml/document'
class Yahooapis
def initialize
path = '/home/flyeagle/call_juiz/'
yaml = YAML::load_file(path+'accesskey.yaml')
@appid = yaml['yahooapis']['appid']
@premium = yaml['yahooapis']['premium']
end
... | true |
ea38bb242173ebf2b1cb1c4ae35e0276257baaf2 | Ruby | stas0n7/ruby-lessons | /lesson6/carriage.rb | UTF-8 | 243 | 2.8125 | 3 | [] | no_license | class Carriage
#include Manufacturer
attr_reader :type
attr_reader :train
def initialize
@train = ""
end
def take(train)
if train.type == @type
@train = train
end
end
def take_off
@train = ""
end
end
| true |
f5b844593d7542ba1a4f5edcb7e98a7dfd12bf5e | Ruby | amatriain/feedbunch | /FeedBunch-app/app/models/entry.rb | UTF-8 | 12,782 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
require 'nokogiri'
require 'encoding_manager'
require 'special_feed_manager'
require 'url_normalizer'
require 'sanitizer'
require 'url_validator'
##
# Feed entry model. Each instance of this class represents an entry in an RSS or Atom feed.
#
# Instances of this class are saved in the da... | true |
12db7ae1030219471e1c297c8289d30733fbeef4 | Ruby | josfervi/ruby_playground | /00-Before_first_coding_interview/00-practice_problems--prompts_and_solutions/solutions-MINE/15-is-prime.rb | UTF-8 | 1,758 | 4.5 | 4 | [] | no_license | # Write a method that takes in an integer (greater than one) and
# returns true if it is prime; otherwise return false.
#
# You may want to use the `%` modulo operation. `5 % 2` returns the
# remainder when dividing 5 by 2; therefore, `5 % 2 == 1`. In the case
# of `6 % 2`, since 2 evenly divides 6 with no remainder, `... | true |
98336e5fe34fcfbb76d0292f95097cb84a4687f5 | Ruby | sebaquevedo/desafiolatam | /guia_array_hash/ejercicio1.rb | UTF-8 | 309 | 3.421875 | 3 | [
"MIT"
] | permissive |
a = [1,2,3,9,1,4,5,2,3,6,6]
# #1 mostrar primer elemento
# puts a [0]
# #2 mostrar ultimo elemento
# puts a [-1]
# #3
# puts a
# #4
# a.each_with_index do |value,index|
# puts "#{value} #{index}"
# end
# #5
# a.each_with_index do |value,index|
# puts value if index.even?
# end
# 6
#puts a.include?(10) | true |
5e221cc797b0f9dad66801d1138bbf0d3e121fcb | Ruby | markpent/background_queue | /lib/background_queue/client_lib/job_handle.rb | UTF-8 | 1,461 | 2.625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'digest/md5'
module BackgroundQueue::ClientLib
#returned from add_task to describe what the job/server was added.
#this is because you can call add_task without a job_id, and not know what server was used.
#this is passed to get_status
class JobHandle
attr_reader :owner_id
attr_reader :job_... | true |
7376a3dba37b628830984d41a49c3413fb3e4a6d | Ruby | totallynotleo/ruby-challenges | /tests/26_max_min_test.rb | UTF-8 | 374 | 3.15625 | 3 | [] | no_license | require 'test/unit'
require_relative '../Completed/26_max_min'
class MaxMinTest < Test::Unit::TestCase
def test_basic_premise
assert_equal("21 1", max_min("1 2 6 9 21"))
assert_equal("7 0", max_min("0 1 2 3 4 5 6 7"))
end
def test_with_negatives
assert_equal("21 -9", max_min("1 2 6 -9 21"))
asser... | true |
bf31be1f4bae3ed9aed1ea85455c77f75c53ab77 | Ruby | trueheart78/book-notes-generator | /lib/book.rb | UTF-8 | 3,597 | 2.84375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'yaml'
require 'pathname'
require 'chapter'
require 'section'
require 'image'
class Book
def initialize(yaml_file, config)
@yaml_file = yaml_file
@config = config
end
def directory
config.notes_path.join title_as_directory
end
def relative_directory
co... | true |
0dfa4eedff76b3fc5df6a73daa638e86582b81d1 | Ruby | Dawenster/wokaiqiao_two | /app/models/refund.rb | UTF-8 | 1,977 | 2.59375 | 3 | [] | no_license | class Refund < ActiveRecord::Base
belongs_to :payment
belongs_to :user
validates :amount_in_cents,
:user_id,
:payment_id,
:stripe_pyr_id,
:stripe_py_id,
:currency,
presence: true
validate :cannot_refund_more_than_charged
def self.make(u... | true |
366e16772c4cee29897a124cb9bbb7ce9e355870 | Ruby | qatutor/winter_rails | /lesson28/try_when_protected/coffee_machine.rb | UTF-8 | 198 | 3.390625 | 3 | [] | no_license | class CoffeeMachine
def make_coffee
get_water(200)
get_beans(50)
end
def get_water(mls)
puts "Get water #{mls}"
end
def get_beans(mls)
puts "Get beans #{mls}"
end
end | true |
7fc82d00350a7843dd267a351b4d1058f6bf36cb | Ruby | DinoPew/TwitterReporter | /twitter_reporter.rb | UTF-8 | 4,632 | 2.65625 | 3 | [
"WTFPL"
] | permissive | #!/usr/bin/env ruby
require "selenium-webdriver"
require 'highline/import'
require 'open-uri'
require 'openssl'
require 'choice'
require 'fileutils'
require 'logger'
# The reporter class
class TwitterReporter
# Get the username from cmdline switch or prompt the user
def get_username(choice_user)
if choice_us... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.