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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9c4ba6065738f87d1ef554c221a02540db58f653 | Ruby | lawrend/project-euler-even-fibonacci-q-000 | /lib/even_fibonacci.rb | UTF-8 | 219 | 3.171875 | 3 | [] | no_license |
def even_fibonacci_sum(limit)
allFib = [1,1]
while allFib[-1]<limit && (allFib[-1]+allFib[-2]) <limit
allFib.push(allFib[-1]+allFib[-2])
end
evenFib = allFib.delete_if &:odd?
return evenFib.inject(:+)
end | true |
b15136e89b9274dad9009e1c69614bdf0f801aab | Ruby | fuchsto/aurita | /lib/aurita/base/bits/hash.rb | UTF-8 | 225 | 2.84375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
class Hash
def to_get_params
string = ''
self.each_pair { |k,v|
string << k.to_s << '=' << v.to_s << '&'
}
string[0..-2]
end
def dup
d = {}
each_pair { |k,e| d[k] = e }
d
end
end
| true |
c01bc2f7199b2a4caac7a0dc3f905c5c3df4c264 | Ruby | hyphenized/exercism | /ruby/difference-of-squares/difference_of_squares.rb | UTF-8 | 335 | 3.453125 | 3 | [] | no_license | class Squares
def initialize num
@num=num
end
def square_of_sum
(1..@num).sum ** 2
end
def sum_of_squares
(1..@num).map{|x|x**2}.sum
end
def difference
square_of_sum - sum_of_squares
end
end
# Find the difference between the square of the sum and the sum of the squares of the first N na... | true |
6824fb3fd2007dc3146d92fcf33c70e8d3fcc26b | Ruby | trixiegoff/word-processor | /anagram.rb | UTF-8 | 2,104 | 3.359375 | 3 | [] | no_license | class String
def histogram
out = {}
out.default = 0
self.gsub(/[^a-z]/i, '').upcase.each_char {|c| out[c] += 1}
out
end
def is_anagram (s)
needle = self.histogram
haystack = s.histogram
needle.keys.each {|c| haystack[c] -= needle[c] }
result = not(haystack.values.any?{|v| v < 0 })
remainder = ""
... | true |
8c39a1485220176433acc5a6c206908ccfd78f93 | Ruby | boomer/tealeaf | /course1/lesson1/blackjack.rb | UTF-8 | 4,977 | 3.40625 | 3 | [] | no_license | # blackjack.rb
# Michael Boomershine
# Edited 11/16/14
require 'pry'
def create_deck
deck = [{"2H" => 2}, {"2C" => 2}, {"2S" => 2}, {"2D" => 2},
{"3H" => 3}, {"3C" => 3}, {"3S" => 3}, {"3D" => 3},
{"4H" => 4}, {"4C" => 4}, {"4S" => 4}, {"4D" => 4},
{"5H" => 5}, {"5C" => 5}, {"5S" => 5}, {"5D" => 5},... | true |
6a480d66e18a4b2db2e76a6c355b9c2aa7c5ec73 | Ruby | inclooder/math_expr | /lib/math_expression/parser.rb | UTF-8 | 1,442 | 3.203125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative './postfix_evaluator'
require_relative './tokenizer'
class MathExpression::Parser
def initialize(expression)
@expression = expression
end
def to_tokens
MathExpression::Tokenizer.new(expression).call
end
def to_postfix
output_queue = []
operato... | true |
97a82015bc0fd5ad0c93883a3bc240fece5f2164 | Ruby | W-Mills/ruby-exercises | /Code Challenges/Easy/beer_song.rb | UTF-8 | 2,312 | 4.71875 | 5 | [] | no_license | # Beer Song
# Write a program that can generate the lyrics of the 99 Bottles of Beer song. See the test suite for the entire song.
# Write a program to generate the lyrics of the 99 bottles of beer song.
# Verse 99:
# => "99 bottles of beer on the wall, 99 bottles of beer."
# => "Take one down and pass it around, 98 ... | true |
30ece26986e812ebf6852f93300644d7a31282f0 | Ruby | nadeka/ratebeer | /spec/features/beers_spec.rb | UTF-8 | 2,217 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
describe "Beer" do
it "should have zero beers at first" do
visit beers_path
expect(page).to have_content 'Beers'
expect(page).to have_content '0 beers'
end
describe "when beers exists" do
before :each do
@beers = ["Karhu", "Tuplahumala", "... | true |
df971618d1dfd3a020754e198ac557bfb12498ae | Ruby | lukaswet/My-Ruby-first-steps | /myapp_05_16/whatnumber.rb | UTF-8 | 461 | 3.546875 | 4 | [] | no_license | whatnumber = rand(0..100)
time_att = 10
1.upto(time_att) do |attempt|
print "Я загадав число. Вгадай яке? Спроба: #{attempt}. Осталось #{time_att - attempt} попыток. "
answer = gets.to_i
if answer == whatnumber
puts "Вгадав"
exit
elsif answer > whatnumber
puts "Нет. Ваше число больше."
elsif answer < ... | true |
b715844be58af6f2ce4f9175d3acc97e5329e02d | Ruby | Edardgtz/practice_ruby | /inheritance_example.rb | UTF-8 | 753 | 3.640625 | 4 | [] | no_license | class Vehicle
def initialize
@speed = 0
@direction = 'north'
end
def current_direction
@direction
end
def brake
@speed = 0
end
def accelerate
@speed += 10
end
def current_speed
@speed
end
def turn(new_direction)
@direction = new_direction
end
end
class Car < Veh... | true |
5afec8a622803d50e289ee24a14edbfafea05581 | Ruby | paploo/warriorbots-core | /backend/lib/child_process.rb | UTF-8 | 3,821 | 3.03125 | 3 | [] | no_license | #
# A library for managing child processes.
# Only compatible with UNIX based systems.
#
class ChildProcess
@@child_processes = []
# Create a child process either by running a shell command or by supplying a
# block to run.
#
# When running a shell command that is going to exit on its own, it is often
... | true |
f6d8d21a838879bf3471de266258a13ff7479b1c | Ruby | BenR1312/rails-template | /app/models/fleet.rb | UTF-8 | 1,283 | 2.65625 | 3 | [] | no_license | class Fleet < ActiveRecord::Base
acts_as_paranoid
has_many :fleet_trucks, inverse_of: :fleet
has_many :trucks, through: :fleet_trucks
accepts_nested_attributes_for :fleet_trucks, allow_destroy: true
validates_associated :fleet_trucks
validates :fleet_name, presence: true
# We need to manually ensu... | true |
42eb123b17a0287b3b475b6ceb9f3625ecea5646 | Ruby | vertis/nomad | /features/step_definitions/when_i_wait_steps.rb | UTF-8 | 73 | 2.53125 | 3 | [
"MIT"
] | permissive | When /^I wait for (\d+) seconds?$/ do |seconds|
sleep(seconds.to_i)
end | true |
5cbaa42b39fe325535665432c742e8fd16122389 | Ruby | Radik73/convert_util | /lib/parsers/atom_parser.rb | UTF-8 | 978 | 2.90625 | 3 | [] | no_license | require_relative 'parser'
require 'nokogiri'
require 'active_support/core_ext/hash/conversions'
class AtomParser < Parser
def self.can_parse?(xml)
begin
xml.xpath('//xmlns:entry').text
true
rescue Nokogiri::XML::XPath::SyntaxError
false
end
end
def transform_hash(hash)
content... | true |
d051042fe6773796f4637d4d4b108dfb6f35e7bf | Ruby | christianlarwood/ruby_small_problems | /live_coding_exercises/product_search.rb | UTF-8 | 1,432 | 4.1875 | 4 | [] | no_license | =begin
Write a method that will return the products given the criteria in query and query2
input: hash
output: an array of hashes
algorithm:
- initialize a result variable and assign to an empty array
- iterate over PRODUCTS
- iterate over each hash
- if the price is between min & max and name includes ... | true |
eb8050579b7020e591c46936e77ac480292c7960 | Ruby | byendan/poker_on_rails | /spec/models/table_spec.rb | UTF-8 | 2,272 | 3 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Table, type: :model do
describe "initialize the table" do
it "sets up a table with a user" do
table = Table.new(user: "Brendan")
expect(table.user).to eq("Brendan")
end
it "sets up ai players" do
table = Table.new(ai_count: 5)
expect(table.... | true |
0867b4a0a7548de40c774ef8b18c0dc36d14dcf2 | Ruby | relev/skud | /test/models/visit_test.rb | UTF-8 | 730 | 2.796875 | 3 | [] | no_license | require 'test_helper'
class VisitTest < ActiveSupport::TestCase
def create_visit(duration)
visit = Visit.new
visit.created_at = Time.at(Time.now.to_i - duration*60)
visit
end
test "плата за 10 минут = 15р" do
visit = create_visit(10)
assert visit.to_state[:price] == 15
end
test "плата з... | true |
48bfe2a9c351ebe0d2b9b989b40c294ea7d993c7 | Ruby | gwenh11/LS_core | /100/exercises/exercise_2.rb | UTF-8 | 153 | 4 | 4 | [] | no_license | arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Method 1
arr.each do |num|
if num > 5
puts num
end
end
# Method 2
arr.each {|num| puts num if num > 5}
| true |
aef706f61076e616b7566c08ba266eb1cb8efc1f | Ruby | ozybrennan/chess | /w2d3/pawn.rb | UTF-8 | 743 | 3.5 | 4 | [] | no_license | require_relative 'piece.rb'
class Pawn < Piece
attr_accessor :pos
attr_reader :board, :color, :symbol, :value
def initialize(board, pos, color)
super(board, pos, color)
@symbol = ( color == :black ? "\u2659" : "\u265F" )
@value = 1
end
def moves
dx = ( color == :black ? 1 : -1 )
x, y =... | true |
bde9ab8ecaf5f7d37187bf10bd99e77bd1fd61c4 | Ruby | tuned-up/algorithms-playground | /chapter2/erastofen_table/erastofen_table_oop.rb | UTF-8 | 1,281 | 3.53125 | 4 | [] | no_license | require 'forwardable'
class ErastofenTable
class IntegerWithInfo
extend Forwardable
attr_reader :number
attr_accessor :is_composite
def_delegators :@number, :<=>, :+, :-, :*
def initialize(number)
@number = number
@is_composite = false
end
alias is_composite? is_compo... | true |
14f7af120abf0cf04cf2177aacf62474c7506b5c | Ruby | KasperKen/anagram-detector-online-web-ft-110419 | /lib/anagram.rb | UTF-8 | 195 | 3.5625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Anagram
attr_accessor :word
def initialize(input)
@word = input
end
def match(string)
string.select {|is_anagram| is_anagram.chars.sort == @word.chars.sort}
end
end
| true |
844135aa8987545e14e11a6b79fcd666b84d5d80 | Ruby | kyojo/LDA | /lda.rb | UTF-8 | 2,859 | 2.734375 | 3 | [] | no_license | corpus = Array.new(){[]} #corpus[doc_index][token_index] = word
wd = []
allwd = []
k = 10
iterate = 100
alpha = beta = 1.0
#Load File
File.open("kakaku_filtered.txt") do |f|
while l = f.gets
wd = l.split(" ")
for w in wd do
w.slice!(/_.*/)
end
wd.delete_if{|item| (item.length == 1 && !item=~/[\... | true |
0a74d3aa40a95f0031d697ef27c0ba077fd207df | Ruby | MayankKashyap/Ruby | /9.rb | UTF-8 | 395 | 3.390625 | 3 | [] | no_license | #def test(a = "hey" , b = "amn")
#puts "#{a}"
# puts "#{b}"
#end
#test "Mayank", "Kashyap"
#test
def test
i = 100
j = 200
k = 300
return i, j, k
end
var = test
puts var
def sample (*test)
puts "The number of parameters is #{test.length}"
for i in 0...test.length
puts "The parameters are #{t... | true |
898135e07b03eb2c90ac0894f8ad89b970a69723 | Ruby | campbill01/stuff | /cipher.rb | UTF-8 | 5,683 | 3.609375 | 4 | [] | no_license | class Deck_of_cards
def initialize
#define cards
@cards=[]
suits=['clubs','diamonds','hearts','spades']
suits.each do |suit|
@cards.push("#{suit}.ace")
(2..10).each do |num|
@cards.push("#{suit}.#{num}")
end
@cards.push("#{suit}.jack")
@cards.p... | true |
38a990ebb0c72470ef988b129d7debe8053b4467 | Ruby | youpy/scissor | /lib/scissor/tape.rb | UTF-8 | 4,769 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'open-uri'
require 'tempfile'
module Scissor
class Tape
class Error < StandardError; end
class EmptyFragment < Error; end
attr_reader :fragments
def initialize(filename = nil)
@fragments = []
if filename
filename = Pathname(filename).expand_path
@fragments << Fr... | true |
9e99034cd5bb4de8e05afce1880144afca8698b3 | Ruby | fbrute/lovy | /data/pm10/madininair_import.rb | UTF-8 | 727 | 3.046875 | 3 | [] | no_license | #!/usr/bin/env ruby
datetimes = []
pm10 = []
File.open("export_mesure_fixe.csv").each_with_index do |line,idx|
values = line.split ";"
#values = values.slice(1,values.length)
# remove first element
values.shift
puts values.length
datetimes = values if (idx == 1)
pm10 = values if (idx == 2... | true |
1f8c8d8f9ffc142d1a0413233847539d8f327526 | Ruby | tingleshao/rablo2d | /rablo2d.rb | UTF-8 | 21,676 | 2.78125 | 3 | [] | no_license | # rablo2d.rb
# This is the main program of the 2D objects in context protypeing system.
# It contains a class Field that abstracts the canvas of the main window that displays the s-reps.
# It contains a class InterpolationControl that abstracts a subwindow for user
# to select which s-rep's spokes to interpolate.
#... | true |
e102491e73c5fcf3f3dde6b2687ff094b95f53b6 | Ruby | Epigene/2021_codingame_spring | /codingame.rb | UTF-8 | 5,361 | 3.015625 | 3 | [
"MIT"
] | permissive | class Decider
attr_reader :world, :timeline
LAST_DAY = 5 # for wood1, will change
def initialize(world:)
@world = world
@timeline = []
end
# Takes in all data known at daybreak.
# Updates internal state and returns all moves we can reasonably make today.
#
# GROW cellIdx | SEED sourceIdx targ... | true |
2e527910a4e34a3272ad2f717e92f7a2596f56a8 | Ruby | kirangan/class_kolla | /hari_2/exercise.rb | UTF-8 | 122 | 3.46875 | 3 | [] | no_license | def create_sentence(words)
str = " "
for word in words
str += word
end
end
puts create_sentence(["hello, world"]) | true |
5cbdc5e69b857bfa50e9607253ea1c8006046bcb | Ruby | tayjames/rales_engine | /lib/tasks/import.rake | UTF-8 | 682 | 2.640625 | 3 | [] | no_license | require 'csv'
namespace :import do
desc "imports all data from csv"
task seeds: :environment do
data = { "Merchant" => ["db/csv/merchants.csv", Merchant],
"Customer" => ["db/csv/customers.csv", Customer],
"Items" => ["db/csv/items.csv", Item],
"Invoice" => ["db/csv/invoices.csv",... | true |
3524d567df61dd9b35d5c54d033772a20e973d07 | Ruby | christianlarwood/ruby_small_problems | /1.fundamentals_exercises/easy_5/after_midnight_1.rb | UTF-8 | 1,509 | 4.3125 | 4 | [] | no_license | =begin
Write a method that takes a time using this minute-based format and returns the time of day in 24 hour format (hh:mm). Your method should work with any integer input.
You may not use ruby's Date and Time classes.
23:30
What's the expected input(s):
- an integer
What's the expected output(s):
- hh:mm represe... | true |
0e65979c5df4ecf008c9e54251836397fbb3422e | Ruby | ivaanrl/FinalRubyProject | /pawn.rb | UTF-8 | 1,999 | 3.96875 | 4 | [] | no_license | require_relative 'piece'
class Pawn < Piece
attr_accessor :piece
def initialize(color)
color == 'white' ? @piece = "\u2659 " : @piece = "\u265F "
@position = []
end
def self.move(initial_square, target_square, taken, turn)
if turn == 'white'
if taken[0]
if turn != taken[1]
... | true |
07d1fd7cd0576153aa55c88cecaeadff1e250d99 | Ruby | Buraisx/Ruby-OOP-exercises | /player/player.rb | UTF-8 | 710 | 3.546875 | 4 | [] | no_license | class Player
def initialize
@gold_coins = 0
@health_points = 10
@lives = 5
end
def display_stats
return "Gold: #{@gold_coins}/ Health: #{@health_points}/ Lives: #{@lives}"
end
def level_up
@lives = @lives +1
end
def collect_treasure
@gold_coins = @gold_coins +1
if @gold_coins % 10 == 0
level_u... | true |
1d39c1deb0daa95167637c1ad09c2a1d7848f616 | Ruby | Andyreyesgo/reposting | /aumento_precios.rb | UTF-8 | 761 | 3.609375 | 4 | [] | no_license | def augment ()
puts "Escribe el nombre del documento con su extensión (.txt)"
STDOUT.flush
d=gets.chomp
data1 = open(d).read.chomp.split(',')
array=[]
puts "el documento contiene el siguiente arreglo"
print data1
data1.each do |x|
array.push x.to_i
... | true |
3e22eb5ddf96aa1a682e134bba49c519b7802e5e | Ruby | Felipeandres11/desafioruby1 | /DESAFIO1/escape.rb | UTF-8 | 70 | 2.5625 | 3 | [] | no_license |
g=ARGV
r=ARGV
ve = Math.sqrt(2*ARGV[0].to_f*ARGV[1].to_f);
puts ve
| true |
00c9664fad2a8f106531503d8d875756cc95025f | Ruby | Sidarth20/ted_lasso_2103 | /lib/team.rb | UTF-8 | 893 | 3.40625 | 3 | [] | no_license | require 'pry'
class Team
attr_reader :name, :coach, :players
def initialize(name, coach, players)
@name = name
@coach = coach
@players = players
end
def total_salary
sum = 0
# binding.pry
players.each do |player|
sum = @players[0].salary + @players[1].salary
end
sum
end
... | true |
23cb1a6037d55319cef8c3f590f1bc2a2e279e4c | Ruby | plonk/100knock | /q30.rb | UTF-8 | 2,833 | 3.8125 | 4 | [] | no_license | =begin
30. 形態素解析結果の読み込み
形態素解析結果(neko.txt.mecab)を読み込むプログラムを実装せよ.ただし,
各形態素は表層形(surface),基本形(base),品詞(pos),品詞細分類
1(pos1)をキーとするマッピング型に格納し,1文を形態素(マッピング型)
のリストとして表現せよ.第4章の残りの問題では,ここで作ったプログラムを
活用せよ.
=end
module Enumerable
def split(pattern)
Enumerator.new do |yielder|
chunk = []
self.each do |elt|
... | true |
cfc2dd3613ad4d5229574912493c3a4952c02c33 | Ruby | KazukiHozumi/yukicoder | /725.rb | UTF-8 | 43 | 2.75 | 3 | [] | no_license | s = gets
puts s.gsub(/treeone/, "forest")
| true |
1ba80a01ab7775140d98694e06d286dbe2ecdc93 | Ruby | orest-kostiuk/OnApp-Search | /start.rb | UTF-8 | 179 | 3.0625 | 3 | [] | no_license | require './simple_json_search'
loop do
puts('Input your search')
query = gets.chomp
break if query == 'exit'
puts('result:')
puts(SimpleJsonSearch.new(query).call)
puts
end | true |
4284979b9615245d19fefa58d20d2dd8533464b8 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/combine_anagrams_latest/6672.rb | UTF-8 | 354 | 3.703125 | 4 | [] | no_license | def combine_anagrams(words)
anagrams = Hash.new()
words.each do |word|
if anagrams.has_key?(word.downcase.chars.sort.join)
anagrams[word.downcase.chars.sort.join].push(word)
else
anagrams[word.downcase.chars.sort.join] = [word]
end
end
return anagrams.values()
end
print comb... | true |
a1b14c78cbbcbab9922abd0a866f681b25389f99 | Ruby | dlyn1110/happy_hour | /lib/happy_hour/cli.rb | UTF-8 | 1,340 | 3.4375 | 3 | [
"MIT"
] | permissive | class HappyHour::CLI
def call
puts "*************************************"
puts ""
puts "Welcome! Let's get your Happy on!!!"
puts "-------------------------------------"
puts "-------------------------------------"
HappyHour::Bar.scrape_bars
bar_list
more_info
goodbye
end
... | true |
d4d1de11525d9ed25fc896a58e3504355154dfa1 | Ruby | Seva-Sh/RB101 | /codewars/ex46.rb | UTF-8 | 490 | 4 | 4 | [] | no_license | =begin
Problem:
-
-
-
-
-
Input: int
Output: int
Algorithm:
- Break the given integer into an array of numbers
- Reassign the integer to the sum of all the numbers in the array
if the result integer has only one digit -> return it
if not, repeat the process
-
=end
def digital_root(int)
loop do
ret... | true |
af767aecb4452b1c4730b314664911aa118048d9 | Ruby | CarolinaAntolin/Range_fundamentals | /desafio_range.rb | UTF-8 | 367 | 3.78125 | 4 | [] | no_license | x=Array (1..7)
print x
puts "Class Name: #{x.class}"
num_a=x[0]
puts num_a
if x.include? num_a
puts "incluye el" + num_a.to_s
else
puts "El numero no esta en la cadena"
end
puts "El ultimo numero de la cadena es :" + x.last.to_s
puts "El minimo valor de la cadena es :" + x.min.to_s
puts "El m... | true |
39c2396e4a1bc2cea609db528232da11b78109b0 | Ruby | Aquaj/rosetta | /spec/rosetta/serializers/csv_serializer_spec.rb | UTF-8 | 1,221 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'rosetta/element'
require 'rosetta/serializers/csv'
RSpec.describe Rosetta::Serializers::CSV do
it 'takes in Elements and returns csv' do
elements = [
Rosetta::Element.new('a' => 1),
Rosetta::Element.new('a' => 2)
]
serialized = Rosetta::Serializers::CSV.serialize(elements)
expec... | true |
49129ca14ee14f0182272bf7d06138a109bbbd1c | Ruby | Hollywilkerson/learning_by_doing | /arrays/array_practice.rb | UTF-8 | 1,111 | 4 | 4 | [] | no_license | #!/usr/bin/env ruby
starting_array = (1..10).to_a
puts "#{starting_array.join('...')}..."
puts "T-#{starting_array.reverse.join(', ')}... BLASTOFF!"
puts "The last element is #{starting_array.last}"
puts "The first element is #{starting_array.first}"
puts "The third element is #{starting_array[2]}"
puts "The element... | true |
76b9b405257db786e46fe868881474506c161666 | Ruby | tomdionysus/json2ruby | /lib/json2ruby/cli.rb | UTF-8 | 6,006 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'digest/md5'
require 'json'
require 'optparse'
module JSON2Ruby
# The CLI (Command Line Interface) functionality class for the json2ruby executable
class CLI
# Run the json2ruby command, using arguments in ARGV.
def self.run
puts "json2ruby v#{VERSION}\n"
# Do the cmdline options
... | true |
d4e44c9a23088ff1beab66ed39bf0f8f58f62b46 | Ruby | opendoor-labs/nomenclature | /app/models/term.rb | UTF-8 | 419 | 2.640625 | 3 | [] | no_license | class Term < ApplicationRecord
belongs_to :team
validates :name, presence: true
validates :description, presence: true
def self.from_text(text)
separator = if text.include?(':')
':'
else
' '
end
name, description = text.split(separator, 2).map(&:strip)
term = find_or_initialize_... | true |
3ecdce614ac9df8434c9ab86cd9dce46f7addf1d | Ruby | jacquelynoelle/hotel | /lib/bookingdates.rb | UTF-8 | 643 | 3.078125 | 3 | [] | no_license | module Hotel
class BookingDates
class InvalidBookingDatesError < StandardError
end
attr_reader :checkin, :checkout
def initialize(checkin, checkout)
unless checkout > checkin
raise InvalidBookingDatesError, "Checkin must be before checkout."
end
@checkin = checkin
@c... | true |
df9106baddd48b965756495d329fa2cae8cfbd7e | Ruby | PhilippePerret/Icare_AD_2018 | /_lib/_required/User/instance/options.rb | UTF-8 | 4,056 | 2.671875 | 3 | [] | no_license | # encoding: UTF-8
=begin
Les bits d'options de 0 à 15 sont réservés à l'administration
et les bits de 16 à 31 sont réservés à l'application elle-même.
C'est ici qu'on définit ces options propres à l'application.
Exemple de réglage forcé des options
------------------------------------
options = '0'*26
... | true |
ef4f2e7738d086b4d915627efc8aa93c5ef9c772 | Ruby | yura-poj/TaskForCurs2 | /lesson3/cargo_train.rb | UTF-8 | 210 | 2.59375 | 3 | [] | no_license | require_relative 'train'
require_relative 'cargo_carriage'
class CargoTrain < Train
def type
:cargo
end
def add_carriage_with_own_type(number)
add_carriage!(CargoCarriage.new(number))
end
end
| true |
20f8df0274a61dc0595808ef39a11338aa9dc048 | Ruby | bigtiger/vurl | /app/models/vurl.rb | UTF-8 | 3,628 | 2.65625 | 3 | [] | no_license | class Vurl < ActiveRecord::Base
require 'open-uri'
require 'nokogiri'
belongs_to :user
has_many :clicks
validates_presence_of :url, :user
validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
validate :appropriateness_of_url
before_... | true |
f3736216a9f2cab9b1693efb63057c5fc72713dc | Ruby | swatichauhan16997/orm | /app/services/master_order_handler.rb | UTF-8 | 1,495 | 2.578125 | 3 | [] | no_license | # Service for handling MasterOrders
class MasterOrderHandler
attr_accessor :params
def initialize(params, session, current_user,id)
@params = params
@session = session
@current_user = current_user
@restaurant = Restaurant.find(id)
end
def manage_master_order
search_session_order
create... | true |
e74d8aff5aeb0d887bf40d71bf7dbbb285515cc8 | Ruby | josornoc/josornoc.github.io | /course/week2Day4/oc5.rb | UTF-8 | 3,894 | 3.46875 | 3 | [] | no_license | # OC4. IronhackMDB
# Trumpets are playing, a choir is singing, and a really handsome TV presenter is introducing all you to… THE BIG EXERCISE!
# But don’t be scared. It’s just a bigger exercise than normal, using all the useful stuff we learned this week: testing with RSpec,
#the TDD methodology, Sinatra, ERB and Ac... | true |
b6d8628b6ed7f65643b8721595d006ab4e0d0e4d | Ruby | airblade/quo_vadis | /app/models/quo_vadis/recovery_code.rb | UTF-8 | 703 | 2.515625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module QuoVadis
class RecoveryCode < ActiveRecord::Base
belongs_to :account
has_secure_password :code
before_validation { send("code=", self.class.generate_code) unless code }
# Returns true and destroys this instance if the plaintext code is authentic, false otherwise... | true |
fd6983dc6ea6f7255f3786e0e97545cd1b3e3763 | Ruby | sbower/rbnd-toycity-part3 | /lib/transaction.rb | UTF-8 | 1,364 | 3.078125 | 3 | [
"MIT"
] | permissive | class Transaction
attr_reader :id, :product, :customer
@@id = 1
@@transactions = []
def initialize(customer, product)
@customer = customer
@product = product
@id = @@id
@@id += 1
if @product.in_stock?
@product.decrement_stock
else
raise OutOfStockError, "'#{@product.title}... | true |
f265dd44f04b841f67e9c87064b60503ba17a1b4 | Ruby | getadeo/code-snippets | /ruby-snippets/mixins.rb | UTF-8 | 994 | 3.078125 | 3 | [] | no_license | module Login
def login username, password
@username == username and
@password == password and
p "Succesfully logged in as #@username"
end
def logout
end
def sign_up
end
end
class Student
include Login
def initialize name, born_at, gender, username, password
@name = name
... | true |
bd33d271ac72a6f0cb86badfbd598b15bff7f290 | Ruby | multilang-depends/depends | /src/test/resources/ruby-code-examples/extends.rb | UTF-8 | 117 | 2.953125 | 3 | [
"MIT"
] | permissive | class Animal
def breathe
end
end
class Cat < Animal
def speak
puts "Miao~~"
end
end
| true |
2f1799c4a2a42e0e28d0eac7cddbd3b4777f7a04 | Ruby | counterbeing/mars-rover-challenge | /classes/format_validator.rb | UTF-8 | 492 | 3 | 3 | [] | no_license | class FormatValidator
def self.plateau_dimensions(string)
unless string =~ /^\d+ \d+$/
raise "Your plateau dimensions should be something like '5 5'"
end
end
def self.rover_location(string)
unless string =~ /^\d+ \d+ (N|S|E|W)$/
raise "Your rover location should be something like '5 4 E'"... | true |
d2accda42fb19601ae319c039d7ac7d9cba9a69a | Ruby | decal/zap-attack | /lib/zap_attack/api/core/action/delete_alerts.rb | UTF-8 | 925 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | # coding: utf-8
module ZapAttack::API
RMALRTS_JSON = 'http://zap:8080/JSON/core/action/deleteAllAlerts'
DELETE_ALERTS_JSON = RMALRTS_JSON
#
# Clear all current vulnerability alerts from the ZAP API.
#
# @return [String] Value of the JSON "Result" key received from the ZAP API JSON
# @example urlarray = ... | true |
7d4be591e7196466f5cab1f7147f027426c44343 | Ruby | shioju/jsonar | /lib/jsonar/indexer.rb | UTF-8 | 1,009 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'json'
require 'set'
module Jsonar
class Indexer
def self.from_files(files = [])
raise ArgumentError if files.empty?
index = {}
files.each do |file|
index = Jsonar::Indexer.from_string(File.read(file), index)
end
index
end
private_class_method
def self.... | true |
4927c6a4ab5ba38c1b97ec96d4029c9cc3f278f1 | Ruby | nayow/tictactoe_game | /lib/show.rb | UTF-8 | 6,672 | 2.96875 | 3 | [] | no_license | class Show
attr_accessor :tab
def self.header
@tab = ["","1","2","3","4","5","6","7","8","9"]
system "clear"
puts "","","","
███╗ ███╗ ██████╗ ██████╗ ██████╗ ██╗ ██████╗ ███╗ ██╗██╗
████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██║██╔═══██╗████╗ ██║██║
██╔████╔██║█... | true |
d880862dcd762293e25fca97b0c9d47788b1affc | Ruby | shannongamby/boris-bikes2 | /lib/van.rb | UTF-8 | 289 | 2.75 | 3 | [] | no_license | require_relative 'docking_station'
require_relative 'bike'
require_relative 'garage'
class Van
attr_reader :stored_bikes
def initialize
@stored_bikes = []
end
def take_broken_bikes(station)
@stored_bikes = station.docked_bikes.reject { |bike| bike.working? }
end
end
| true |
baa8ffe01536d2b3d63a065f3225f17e811a5ec2 | Ruby | rocky-jaiswal/smshelper | /lib/smshelper.rb | UTF-8 | 281 | 2.890625 | 3 | [] | no_license | require_relative "smshelper/version"
require_relative "smshelper/solver"
module Smshelper
puts "Enter text you want to send :"
puts "Helper will ignore case and space denotes pause"
text = gets.chomp
solver = Smshelper::Solver.new
puts solver.solve(text).inspect
end
| true |
4f6e73a62fe9fa9ea6a81f3f1c8c9e18d9d0bd19 | Ruby | moofmayeda/stanford-algorithms-part-1 | /week_1_practice.rb | UTF-8 | 1,162 | 3.734375 | 4 | [] | no_license | def merge_sort(array)
puts array.to_s
length = array.count
if length > 1
half = length / 2
left = merge_sort array[0..half-1]
right = merge_sort array[half..length-1]
merge(left, right)
else
array
end
end
def merge(left, right)
if left.empty?
result = right
elsif right.empty?
... | true |
1326da6475bc2876f6ec28b0c419522ee1a9b2f3 | Ruby | eregon/Classes | /extension.rb | UTF-8 | 867 | 3.359375 | 3 | [] | no_license | =begin
July 2009
Code taken from the Ruby Extension Project
http://rubyforge.org/projects/extensions
http://extensions.rubyforge.org/
=end
module Enumerable
#
# Like <tt>#map</tt>/<tt>#collect</tt>, but it generates a Hash. The block
# is expected to return two values: the key and the value for the new hash.
... | true |
a3ba4aa3eb0336fe0fc7b59e518b664029b1c0a0 | Ruby | Denisglb/TickTacToe | /lib/player.rb | UTF-8 | 113 | 2.921875 | 3 | [] | no_license | class Player
attr_reader :piece
def initialize
@piece = 'x'
end
end
player1 = Player.new
p player1.piece | true |
2d55bc5c21f5bdd433b4a94ec31f4e58cdc871f0 | Ruby | iwaseasahi/design_pattern_with_ruby | /iterator/main.rb | UTF-8 | 339 | 3.359375 | 3 | [] | no_license | require_relative 'book'
require_relative 'book_shelf'
class Main
book_shelf = BookShelf.new
book_shelf.append_book(Book.new('本1'))
book_shelf.append_book(Book.new('本2'))
book_shelf.append_book(Book.new('本3'))
iterator = book_shelf.iterator
while iterator.has_next?
book = iterator.next
puts book.na... | true |
6b4ee358453f61f4ad849044fece598dc9ea28b5 | Ruby | iAmXquisite/ttt-8-turn-cb-gh-000 | /lib/turn.rb | UTF-8 | 1,286 | 4.46875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Prints the Board
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
# Takes the number user enters and subtracts 1 to match array index
def inpu... | true |
5af2901d314b8f1f62bda865701c263a073adaa0 | Ruby | InflectProject/inflections | /lib/services/holliday_service.rb | UTF-8 | 1,321 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'net/http'
class HollidayService < Inflect::AbstractService
# A WORDS Array constant with the key words of the Service.
# @example Array for New York Times service
# words = %W[ NEWS TODAY NEW\ YORK\ TIMES]
# In case there are modules that provide similar contents the
# one with most PRIORITY is p... | true |
c771e72cd98e075b64dc9e1ea9e99cde0097c26a | Ruby | keram/refinerycms-inquiries2 | /app/models/refinery/inquiries/inquiry.rb | UTF-8 | 1,070 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'refinery/core/base_model'
require 'filters_spam'
module Refinery
module Inquiries
class Inquiry < Refinery::Core::BaseModel
self.table_name = 'refinery_inquiries'
default_scope -> { order(id: :desc) }
scope :fresh, -> { where(archived: false) }
scope :archived, -> { where(archiv... | true |
9e673746293729c3993cc71ff2f8ba2e992ab361 | Ruby | rdavid1099/poke-api-v2 | /lib/poke_api/common/name.rb | UTF-8 | 302 | 2.59375 | 3 | [
"MIT"
] | permissive | module PokeApi
module Common
# Name object handling lists of names and languages
class Name
attr_reader :name,
:language
def initialize(data)
@name = data[:name]
@language = Utility::Language.new(data[:language])
end
end
end
end
| true |
1a2162efcb20446dccad003eb5c6822a736ca6e1 | Ruby | tbfisher/puppet-php | /lib/puppet/parser/functions/to_php.rb | UTF-8 | 978 | 2.90625 | 3 | [] | no_license | def var_export(val)
if val.class == String
val = val.gsub(/'/, '\\\\\0')
"'#{val}'"
elsif val.class == Array
val = val.collect{|v| var_export(v) }.join(', ')
"array(#{val})"
elsif val.class == Hash
val = val.collect{|k,v| var_export(k) + ' => ' + var_export(v) }... | true |
657d8cdb8b710cf21f7dc12c150acda66fdebe7d | Ruby | lawhump/CS-Air | /tests/graph_stats_test.rb | UTF-8 | 694 | 2.71875 | 3 | [] | no_license | require 'minitest/autorun'
require 'json'
require '../app/graph'
# I don't really know how I'm expected to verify my answers.
# Reading through the JSON and comparing things by hand is not gonna happen.
class GraphStatsTest < Minitest::Test
# Called before every test method runs. Can be used
# to set up fixture i... | true |
a3a9b0829721a111a0bec8d1bc42cf1c0ef4e095 | Ruby | AshRhazaly/alphacamp | /Power_of_two.rb | UTF-8 | 146 | 3.40625 | 3 | [] | no_license |
def is_power_of_two(n)
if Math.sqrt(n) % 1 == 0
return true
else
return false
end
end
puts is_power_of_two(25)
puts "hello world"
| true |
e2966e31ce53d36b11db4acdeb951a49ac52d680 | Ruby | szareey/ministryDocs | /spec/ministry_docs/math_2007_doc/specific_parser_spec.rb | UTF-8 | 1,034 | 2.5625 | 3 | [] | no_license | require 'spec_helper'
describe MinistryDocs::Math2007Doc::SpecificParser do
subject(:parser) { MinistryDocs::Math2007Doc::SpecificParser.new }
let(:specific) { get_txt 'specific_parser/specific' }
describe '#parse' do
let(:parsed) { parser.parse(specific, '1').first }
let(:part) { '1.1' }
let(:des... | true |
bb07905019071a7fc809374bfc9ab011b7a82ace | Ruby | richardpattinson/oystercard-1 | /lib/journey.rb | UTF-8 | 318 | 3.21875 | 3 | [] | no_license | class Journey
MIN_FARE = 1
PENALTY_FARE = 6
def initialize(entry_station, exit_station)
@entry_station = entry_station
@exit_station = exit_station
end
def complete?
return false if @exit_station || @entry_station == nil
end
def fare
self.complete? ? MIN_FARE : PENALTY_FARE
end
end
| true |
2a79982b3d4b3c555de3bb4ab0c6711cb8899155 | Ruby | chackerian/Ruby | /formatfail.rb | UTF-8 | 328 | 3.203125 | 3 | [] | no_license | days = "Mon Tue Wed Thur Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJune\nJuly\nAug"
puts "Here are some days: ", days
puts "Here are some months ", months
puts <<PARAGRAPH
There's something going on here
With the PARAGRAPH thing
We'll be able to type as much as we like
Even 4 lines if we want or five or six.
PAR... | true |
7bc0e6e28c86fe3a9238a1392836f801275d6608 | Ruby | EricRicketts/RubyBooks | /MasteringRubyClosures/exercises/chapter_2_blocks/exercise_4_test.rb | UTF-8 | 1,421 | 3.515625 | 4 | [] | no_license | module Redis
class Server
# ... more code ...
def run
loop do
session = @server.accept
begin
return if yield(session) == :exit
ensure
session.close
end
end
resc... | true |
97d65c3dcfa42e8ea40b38e1942682d0b6bdb4bc | Ruby | mytestbed/omf_web | /lib/omf-web/rack/multi_file.rb | UTF-8 | 1,839 | 2.609375 | 3 | [] | no_license |
require 'rack/file'
module OMF::Web::Rack
# Rack::MultiFile serves files which it looks for below an array
# of +roots+ directories given, according to the
# path info of the Rack request.
#
# Handlers can detect if bodies are a Rack::File, and use mechanisms
# like sendfile on the +path+.
#
class Mul... | true |
ef0936f1f9a2d0572d08048f46c14da3b102487b | Ruby | alpiepho/rpn-calc-chrome-extension | /test_html/test_enter_drop.rb | UTF-8 | 1,314 | 2.859375 | 3 | [] | no_license | #
# Copyright (C) 2017 ThatNameGroup, LLC. and Al Piepho
# All Rights Reserved
#
###########################################################
# TEST - enter and drop
###########################################################
def test_EnterEachNumberThenDrop
puts "SUITE: test_EnterEachNumberThenDrop"
... | true |
c32d00dc9df237863eadb1d4a4b4cfb4793d3e15 | Ruby | RND-SOFT/lusnoc | /lib/lusnoc/mutex.rb | UTF-8 | 3,381 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'socket'
require 'lusnoc/session'
module Lusnoc
class Mutex
include Helper
attr_reader :key, :value, :owner
def initialize(key, value: Socket.gethostname, ttl: 20)
@key = key
@value = value
@ttl = ttl
end
def locked?
!!owner
end
def owned?
owner =... | true |
4595a67ead4058efbb6b99d3c1dfdc900bed4311 | Ruby | Zernov/projecteuler | /20-29/Problem 21.rb | UTF-8 | 398 | 3.78125 | 4 | [] | no_license | def divisors_of(number)
divisors = []
n = 1
while n <= number**0.5
if number % n == 0
divisors << n
divisors << number / n unless number / n == n or n == 1
end
n += 1
end
divisors.sort
end
result = []
(1..10000).each { |i| result << i if divisors_of(divisors_of(i).inject(:+)).inject(... | true |
aad70236f50f63e8bf9839ed61f911fa69a43d5d | Ruby | heedspin/m2mhub | /app/models/quality/customer_otd_report.rb | UTF-8 | 2,228 | 2.765625 | 3 | [
"MIT"
] | permissive | class Quality::CustomerOtdReport
class Month
attr_accessor :date, :num_releases, :late_releases
def initialize(date)
@date = date
@num_releases = 0
@late_releases = []
end
def add_late_release(release)
@late_releases.push release
end
def num_late_releases
@late_re... | true |
51524a79b48e8b9951867a974bbe6e894f396aef | Ruby | nettan20/qae | /app/pdf_generators/qae_pdf_forms/custom_questions/by_year.rb | UTF-8 | 2,403 | 2.78125 | 3 | [
"MIT"
] | permissive | module QaePdfForms::CustomQuestions::ByYear
YEAR_LABELS = %w(day month year)
YEAR_LABELS_TABLE_HEADERS = [
"Financial year", "Day", "Month", "Year"
]
IN_PROGRESS = "in progress..."
def render_years_labels_table
rows = financial_year_changed_dates_entries
rows.map do |e|
e[1] = to_month(e[1]... | true |
924f1cbe255412869224d7bee377ab5451bb7182 | Ruby | jsha1/cycling | /rides.rb | UTF-8 | 409 | 2.8125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
class Ride
def self.getStats(user, early)
page = Nokogiri::HTML(open("http://strava.com/athletes/#{user}"))
result = [ page.css("h1#athlete-name").text, early - page.css("ul.inline-stats li strong")[3].text.to_i]
end
end
users = {"usmanity" => 211, "hcabalic" => 697, ... | true |
648d48eb99a1186278572f843ddf9541fc584749 | Ruby | prashantGyeser/urbanzeak-leads-processor | /lib/tasks/check_words.rake | UTF-8 | 1,779 | 2.796875 | 3 | [] | no_license | require 'word_counter_processed_tweets'
# Usage sample
# rake check:word[<word to check. Takes only one word>]
# To run it on rake with multiple words
# heroku run rake 'check:word["want lunch"]'
# Make sure it is quoted properly
namespace :check do
desc "Check if a list of words exists in the leads and non leads"... | true |
83e6fbde2a030f6b01ae73848817d304e40037c5 | Ruby | englertjoseph/Fighter | /player.rb | UTF-8 | 3,587 | 3.25 | 3 | [] | no_license | require_relative 'animation.rb'
module Fighter
class Player
SCALE = 3
STEP_SIZE = 2
MAX_HEALTH = 100
ATTACKS = {
kick: MAX_HEALTH / 10,
punch: MAX_HEALTH / 20
}
attr_reader :side, :MAX_HEALTH
attr_accessor :health
def initialize(player_name, window, x, y, side)
@t... | true |
6fa22f0c08a3a1766564185d9512a223bc12d055 | Ruby | BenRKarl/WDI_work | /w01/d04/Rebecca_Strong/rental_app/spec/person.rb | UTF-8 | 242 | 3.71875 | 4 | [] | no_license | class Person
attr_accessor :name, :age, :income
def initialize(name, age, income)
@name = name
@age = age
@income = income
end
def to_s
"My name is #{name}, I am #{age} and I earn $#{income} per year."
end
end
| true |
e75f5f23b986eb0fbb481b9b3f864af36f264a62 | Ruby | ravelll/toy-compiler | /compiler.rb | UTF-8 | 4,517 | 3.484375 | 3 | [] | no_license | class Compiler
class Runner
def initialize(source)
@source = source
@source_index = 0
@tokens = []
@token_index = 0
end
def read_number(char)
number_chars = [char]
loop do
char = get_char
break unless char
if '0' <= char && char <= '9'
... | true |
aa51da339ad0a004e31267dac712e6809dcd15a2 | Ruby | nikita-ahuja/phase-0-tracks | /ruby/assessment_practice/newsroom.rb | UTF-8 | 2,547 | 3.703125 | 4 | [] | no_license | class Newsroom
attr_reader :name, :reporters
attr_accessor :budget
def initialize(name, budget)
@name = name
@budget = budget
@reporters = {}
end
def add_reporter(reporter_name, skills)
if has_budget?(reporter_name)
if @reporters.keys.include?(reporter_name)
puts "We can't hire an... | true |
0aa9d074dd0a75e4817548ba4494e53e52f463c1 | Ruby | Jenietoc/Ruby_kommit_course | /Arrays III/Remove_Array_Items_that_Exist_in_Another_Array.rb | UTF-8 | 253 | 3.578125 | 4 | [] | no_license | a = [1, 1, 2, 2, 2, 3, 3, 4, 5]
b = [1, 4, 5]
p a - b
#Challenge
def custom_subtraction(arr1, arr2)
new_array = []
arr1.each do |item|
new_array << item unless arr2.include?(item)
end
new_array
end
p custom_subtraction(a, b)
| true |
29dd8bd87e00665d5c89735e6703fa269f5d64aa | Ruby | tessa155/Software-Modelling-And-Design-Projects | /Project1/project1_codes/news/csv_formatter.rb | UTF-8 | 672 | 2.5625 | 3 | [] | no_license | # This script contains CsvFormatter class,
# which has common methods for the three csv formatters.
#
#
# Author:: Tessa(Hyeri) Song (songt@student.unimelb.edu.au)
# Student Number:: 597952
# Copyright:: Copyright (c) 2015 The University Of Melbourne
module News
class CsvFormatter < Formatter
# Call sup... | true |
f424890dbee318dd754b41ee11aac4e745d2def1 | Ruby | casualjim/caricature | /lib/caricature/clr/descriptor.rb | UTF-8 | 4,946 | 3.109375 | 3 | [
"BSD-3-Clause"
] | permissive | module Caricature
# Contains the logic to collect members from a CLR type
module ClrMemberCollector
attr_reader :class_events, :events
private
# collects the instance members for a CLR type.
# makes sure it can handle indexers for properties etc.
def build_member_collections(context={}, insta... | true |
b753205a216ace48ab4abf20259db554cff3748b | Ruby | anthonychen1109/boating-school | /app/models/student.rb | UTF-8 | 589 | 3.078125 | 3 | [] | no_license | class Student
attr_reader :first_name, :last_name
@@all = []
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
@@all << self
end
def self.full_names
self.all.map {|student| "#{student.first_name} #{student.last_name}"}
end
def self.all
@@all
... | true |
3e773b4bcad3f56efefd267ca198c94fab998245 | Ruby | Ben-CU/Ruby-Basic-TCP-Client | /tcp_server.rb | UTF-8 | 251 | 2.96875 | 3 | [] | no_license | require "socket"
#Creates a TCP Server on port 9999
server = TCPServer.new(9999)
#Listens for Connections and sends "Hello World! to them
loop do
Thread.start(server.accept) do |client|
client.puts "Hello World!"
client.close
end
end
| true |
c6e32ea67d0fd72366dafd5093126413fc492567 | Ruby | fabiocasmar/lenguajes-de-programacion-1 | /Proyecto2-Ruby/bfs.rb | UTF-8 | 8,161 | 3.578125 | 4 | [] | no_license | =begin
Nombre del archivo: bfs.hs
Realizado por: Fabio Castro 10-10132
Patricia Reinoso 11-10851
Organización: Universidad Simón Bolívar ... | true |
c565ecf8865410315cd55045c77ad42bab5cc5d2 | Ruby | annakim93/restricted-arrays | /lib/using_restricted_array.rb | UTF-8 | 6,205 | 3.734375 | 4 | [] | no_license | require_relative 'restricted_array.rb'
# RestrictedArray can be created using a specified size, or a random size in
# the range of 1-20 will be chosen for you.
# All values are integers in the range of 1-221.
# RestrictedArray cannot be resized.
# Get that nice colorized output
Minitest::Reporters.use! Minitest::Repor... | true |
6253d1aa0f4f4da708bd6183aaa2a213bece597f | Ruby | nelgau/xe | /lib/xe/enumerator/launchers.rb | UTF-8 | 1,166 | 2.78125 | 3 | [] | no_license | module Xe
class Enumerator
# Convenience methods for invoking the enumeration strategies, or choosing
# to short-circuit in favor of the standard enumerable methods when the
# context is disabled.
module Launchers
# Runs a computation, returning a value, within a single fiber. If the
# fib... | true |
46fabc01b70cadd86f306c24a58c81c48e414618 | Ruby | EPrenzlin/ruby-collaborating-objects-lab-onl01-seng-pt-030220 | /lib/song.rb | UTF-8 | 611 | 3.078125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
attr_accessor :name, :artist, :import
@@all = []
def self.new_by_filename(import)
title = import.split("-")[1].strip
artist_from_file = import.split("-")[0].strip
song = self.new(title)
song.artist = Artist.find_or_create_by_name(artist_from_file)
song... | true |
bdd35de20f5735e6d828d28e8cbcf3824e6a30a4 | Ruby | oceanep/UGHHHH | /app/models/girl.rb | UTF-8 | 790 | 2.59375 | 3 | [] | no_license | class Girl < ApplicationRecord
def rank(user)
ranking = Ranking.where(user: user, girl: self).first
if !ranking
0
else
ranking.rank
end
end
def total_rank
# Ranking.where(:girl_id => self.id).pluck(:rank).inject(:+)
end
def highest_rank
# highest_ranking_girl = Girl.all.sort_by{|i| i.total_rank... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.