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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
0466abef11785e1061de39c19c890fa4c9662dd8 | Ruby | rda1902/transport | /lib/estimate/position.rb | UTF-8 | 1,752 | 2.65625 | 3 | [] | no_license | module Estimate
class Position
attr_accessor :lat
attr_accessor :lon
attr_accessor :direction
attr_accessor :timestamp
attr_accessor :velocity
attr_accessor :route_id
attr_accessor :direction_id
attr_accessor :vehicle_label
attr_accessor :order_number
attr_accessor :license_pla... | true |
bf1b012051f1ba34bdc83dd208b6f8e5bf3869cf | Ruby | MarioRuiz/create_tests | /example/requests/uber.yaml_Products.rb | UTF-8 | 1,658 | 2.625 | 3 | [
"MIT"
] | permissive | ##################################################
# Uber API
# version: 1.0.0
# description:
# Move your app forward with the Uber API
##################################################
module Swagger
module UberApi
module V1_0_0
module Products
# operationId: listProducts, method: get
... | true |
41a56f57a89a2b61385c66bc9ed8ba9103bb625f | Ruby | BrentBauman86/tic-tac-toe-rb-v-000 | /lib/tic_tac_toe.rb | UTF-8 | 1,982 | 4.09375 | 4 | [] | no_license | require "pry"
WIN_COMBINATIONS = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
]
def display_board(board = ["X", "X", "X", "X", "O", "O", "O", "X", "O"])
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]... | true |
6ebd61295b83e14d812368738b203c1fb5707e0e | Ruby | redinger/numerex_test | /app/controllers/ws_controller.rb | UTF-8 | 2,471 | 2.5625 | 3 | [] | no_license | # Controller that receives readings from HTTP devices
# Verifies that the device currently exists and associates data
# with appropriate device and account
class WsController < ApplicationController
# Supports url params imei, lat, lng, spd, dir alt
def index
# Check that the device exists
device = Device.... | true |
d3174705e812f9063fb1666a8b128d7f7300d75a | Ruby | gusworks/sparse | /spec/number_spec.rb | UTF-8 | 336 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'spec_helper'
describe Sparse do
context 'Boolean values' do
before :each do
@parser = Sparse.new
end
it 'should return a integer' do
@parser.parse('(1)').should == [[1]]
end
it 'should return a decimal' do
@parser.parse('(1.1)').should == [[1.1]]
end... | true |
3f989730b298a5487d8e0c8445603cb04714ca8a | Ruby | roughl/SecondHome-Tools | /Scripts/msg_parser/parser.rb | UTF-8 | 3,310 | 3.21875 | 3 | [] | no_license | #!/usr/bin/env ruby
#Encoding: UTF-8
require 'date'
require './handels_parser.rb'
$Debug = 0
$Version = "0.3.0"
def dputs(arg)
if $Debug == 1
puts arg
end
end
def parsefile(file)
if not file.class == File
puts " ERROR! parsefile(<file>) <file> must be class File"
return
end
start_of_message = fa... | true |
bf38b9ab3b1b7d231091da8800ecc1bbbd1d6c2f | Ruby | yunjin-cloud/2020-winter | /OOP_Variable/set&get.rb | UTF-8 | 610 | 4.1875 | 4 | [] | no_license | class C
def initialize(v)
@value = v
end
def show()
p @value
end
def getValue()
return @value
end
def setValue(v)
@value = v
end
end
c1 = C.new(10)
# p c1.value #루비는 얘를 함수로 해석하려고 해
# c1.value = 20 # 허용되지 않음
#루비에선 instance 변수에 class 밖에서(method 밖에서) 접근하는 게 허용되지 않음
#이게 ... | true |
1ce238fa06c1a110f05c31e86eb636715a639a4f | Ruby | wenbo/rubyg | /sample/CHAPTER07/166/partition.rb | EUC-JP | 380 | 3.890625 | 4 | [] | no_license | # 15ζȴ̤˵롣
(1..5).select{|n| n%2 == 0 } # => [2, 4]
(1..5).reject{|n| n%2 == 0 } # => [1, 3, 5]
# Ʊ˵ˤϡpartitionץåɤȤ
(1..5).partition{|n| n%2 == 0 } # => [[2, 4], [1, 3, 5]]
# Ruby 1.8.7ʹߤǤϤΤ褦ˤ롣
(1..5).partition(&:even?) # => [[2, 4], [1, 3, 5]]
| true |
aeac4eac2384665eec8057d2128274fec6a95d67 | Ruby | krainboltgreene/scripts | /sample.rb | UTF-8 | 131 | 3.3125 | 3 | [] | no_license | (1..100).map do |i|
x = ''
x += 'Fizz' if i % 3 == 0
x += 'Buzz' if i % 5 == 0
if x.empty? then puts i else puts x end
end
| true |
1c4d6a1d1096570c8c2924b4e3f12979751b506d | Ruby | dballenger/exercises | /2020-02-09-count-unival-trees/solution.rb | UTF-8 | 1,111 | 3.75 | 4 | [] | no_license | class Solution
def self.count_univals(tree)
# if there are no left nor right nodes, that counts as a unival subtree
# Otherwise we look for the case where starting at each node, all left and rights are the same value
# base case
if tree.nil?
return 0
end
(children_of_same_value?(tree, ... | true |
f3f184ad40fe57c7d3f6e129731258717258b477 | Ruby | abatish/business_time | /test/test_business_minutes.rb | UTF-8 | 2,144 | 2.984375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'helper'
class TestBusinessMinutes < Test::Unit::TestCase
context "with a standard Time object" do
should "move to tomorrow if we add 480 minutes" do
first = Time.parse("Aug 4 2010, 9:35 am")
later = 480.business_minutes.after(first)
expected = Time.parse("Aug 5 2010, 9:35 am")
a... | true |
f50cb607e62e2699f666e8278751c23c9d3f86b0 | Ruby | niklaslong/epicodus-lessons | /Ruby/dictionary/spec/dictionary_spec.rb | UTF-8 | 1,314 | 3.234375 | 3 | [] | no_license | require "dictionary"
require "rspec"
require "pry"
describe Word do
before do
Word.clear
end
describe "#initialize"
it "initialises a new instance of Word and child object definition" do
test_word = Word.new("word", "definition")
expect(test_word.definitions[0].word_definition).to(eq("definition"))
e... | true |
1496e67bdd39e4376f6b4ed4e56eb4f4867e7a3e | Ruby | Williampangestu/phase_0_unit_2 | /week_4/2_creative/make_a_homework_cheater/my_solution.rb | UTF-8 | 2,805 | 4.125 | 4 | [] | no_license | # U2.W4: Homework Cheater!
# I worked on this challenge by myself.
# 2. Pseudocode
# Input: topic, title, name, date, thesis
# Output: string of paragraph
# Steps:
# create a method called essay_cheater that take the following parameters: essay_topic, title, name, date, and thesis statement
# create an if stateme... | true |
1634b4624470ac169a3e00d194b5ce7408f0340a | Ruby | layoel/Civitas | /CivitasR/lib/civitas/dado.rb | UTF-8 | 2,208 | 3 | 3 | [] | no_license | # encoding: UTF-8
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
require 'singleton'
require 'securerandom'
#require "byebug"
module Civitas
class Dado
# //singleton
include S... | true |
42198c6695285bdfd09f6cdead07f65961ce761f | Ruby | hiroshiuk1991/OO-Animal-Zoo-london-web-102819 | /lib/Zoo.rb | UTF-8 | 769 | 3.265625 | 3 | [] | no_license | class Zoo
attr_reader :name, :location
attr_accessor :animal
@@all = []
def initialize(name, location, animal)
@name = name
@location = location
@animal = []
@@all << self
end
def self.all
@@all
end
def self.all
@@all
end
def animal... | true |
f8944b37cc85d4c22250929cf2cd355110605d68 | Ruby | bryant1410/jeanny | /lib/jeanny/extend.rb | UTF-8 | 5,203 | 3.03125 | 3 | [] | no_license | class Module
# Проверка наличия метода
def jeanny_extension(method)
if method_defined?(method)
$stderr.puts "WARNING: Possible conflict with jeanny extension: #{self}##{method} already exists"
else
yield
end
end
end
class File
jeanny_extension('ope... | true |
f428ca80a5ec0bea7004cd880f17f110131ed2cd | Ruby | akeboshi/discord_bots | /fez_info/fez_info_fetcher.rb | UTF-8 | 2,292 | 3.015625 | 3 | [] | no_license | require 'httpclient'
require 'json'
require 'nokogiri'
require 'yaml'
class FezInfo
attr_accessor :id, :subject, :detail, :url, :category_str, :create_at
def initialize(id, subject, detail, url, category_str, create_at)
@id = id
@subject = subject
@detail = detail
@url = url
@category_str = ca... | true |
74563ec227424e3145c29a5865328db91e1ef704 | Ruby | jonnymacs/hackerrank | /fibonacci/prog.rb | UTF-8 | 168 | 3.609375 | 4 | [] | no_license | #!/bin/ruby
def fibonacci(n)
return n if n < 2
fib = [0,1]
(2..n).each { fib = [fib.last, fib.first + fib.last] }
fib.last
end
n = gets.to_i
puts fibonacci(n)
| true |
3f6bfeae40c5ca30e5d953e76c1910667dae720d | Ruby | ArpanMaheshwari144/Complete-Ruby-Programming | /tut57.rb | UTF-8 | 436 | 4.1875 | 4 | [] | no_license | # Array basics and fundamentals
a = [1,1,2,2,3,3,4]
b = [5,5,4,4,3,3,2]
# c = a | b # merge these two arrays a and b and remove duplicate data and stores it to c
# c = b | a # merge these two arrays b and a and remove duplicate data and stores it to c
# c = a & b # compare common elements in the array a and arr... | true |
1557e405cf0e233a43842e8bab294abe9062fd9d | Ruby | jalquisola/robot-simulator | /lib/services/instruction_manager.rb | UTF-8 | 271 | 2.546875 | 3 | [] | no_license | require File.expand_path("../command_manager", __FILE__)
class InstructionManager
def initialize(command_manager)
@command_manager = command_manager
end
def process(instruction)
command = @command_manager.create(instruction)
command.execute
end
end
| true |
896ef20de79906aff9df22429a587d6707dc025b | Ruby | sorankov/UNT | /main.rb | UTF-8 | 34,801 | 2.546875 | 3 | [] | no_license | # coding: utf-8
require 'dxopal'
include DXOpal
require_remote 'player.rb'
require_remote 'player2.rb'
require_remote 'enemy.rb'
require_remote 'bone.rb'
require_remote 'ball.rb'
require_remote 'ball_break.rb'
require_remote 'laser.rb'
require_remote 'laser2.rb'
Image.register(:player, 'images/player.png')
Image.reg... | true |
e75af7e16e31cd27970cb2cd97c715863ab849dc | Ruby | wescreations/poker | /test/controllers/poker_controller_test.rb | UTF-8 | 3,278 | 2.703125 | 3 | [] | no_license | require 'test_helper'
class PokerControllerTest < ActionDispatch::IntegrationTest
test "check royal flush" do
post "/poker/submit_hand", params: { poker_hand: "jd qd kD ad 10d" }
assert_includes flash[:notice], "Hand: Royal Flush. Rank: 1st"
end
test "check straight flush" do
post "/poker/submit_ha... | true |
6d35bdf9cc2cc27f25aed3e9ee1aa3e69a5f2c3d | Ruby | marzg510/mediaclassify | /show_tag.rb | UTF-8 | 669 | 2.515625 | 3 | [] | no_license | require 'taglib'
require 'csv'
HEADER=['dirname','filename','title','artist','album','album artist',
'genre','track','year','disc#']
def array_tag(filename)
TagLib::MPEG::File.open(filename) do |mp3|
[
File.dirname(filename),File.basename(filename),
mp3.tag.title,mp3.tag.artist,
mp3.tag... | true |
dccf9c5d3b63e056e1bfaef07e7f5cc9a7babc75 | Ruby | skwak/advent-of-code | /2016/day6_test.rb | UTF-8 | 580 | 2.921875 | 3 | [] | no_license | require "minitest/autorun"
require_relative "day6.rb"
class Day6Test < Minitest::Test
def test_should_store_letters_in_arrays_by_column
input = File.open("day6_test_input.txt").read
code_breaker = CodeBreaker.new input
expected = ["e", "d", "e", "r", "a", "t", "s", "r", "n", "n", "s", "t", "v", "v", "d"... | true |
64ba32b2f26587ccb1e3bbe47a18b07d1e11aad4 | Ruby | bignos/battleDev | /Le_meilleur_restaurant/process.rb | UTF-8 | 570 | 3.5 | 4 | [] | no_license | #*******
#* Read input from STDIN
#* Use puts to output your result
#* Use:
#* local_print( variable );
#* to display simple variables in a dedicated area.
#*
#* ***/
input = Array.new
while i = $stdin.gets
input << i.strip
end
best_score = 0
tableau_note = input[1..Integer(input[0])]
tableau_note.each do |el... | true |
6e1a97e98ffdf03871c6bc551bbbae337c35fad8 | Ruby | FayeCarter/boris-bikes-2 | /lib/garage.rb | UTF-8 | 132 | 2.8125 | 3 | [] | no_license | class Garage
attr_accessor :storage
def initialize
@storage = []
end
def store(bikes)
@storage = bikes
end
end | true |
21ea2f4127d408bd722845e2edae0c87382b0829 | Ruby | mgorski/DevZone | /API/examples/ruby_synopsis.rb | UTF-8 | 1,985 | 2.78125 | 3 | [] | no_license | #!/usr/bin/ruby
# Implementation of sample scenario using GetResponse API:
#
# Add new contact to campaign 'sample_marketing'.
# Start his follow-up cycle and set custom field
# 'last_purchased_product' to 'netbook'.
#
# @author Sebastain Nowak, Pawel Pabian
# http://implix.com
# http://dev.getresponse.com
require 'r... | true |
9e913a909fd0e1cca974fffb06e219729f84852c | Ruby | DDB-/projectEuler | /problems/problem23.rb | UTF-8 | 294 | 3.265625 | 3 | [] | no_license | require 'Euler'
abun, sums = [], []
i, sss= 1, 0
while i < 20200
abun << i if Euler.abundant(i)
i += 1
end
length = abun.length-1
for i in 0..length
for j in 0..length
sums << (abun[i] + abun[j])
end
end
sums = sums.uniq
for k in 1..20200
sss += k unless sums.include? k
end
print sss
| true |
0c8f678db3c7eef0337dfeead441e149224b4a3f | Ruby | Saicheg/bsuir-courses | /2015/Ponomarenko/homework2/gemfiler/lib/main.rb | UTF-8 | 617 | 2.609375 | 3 | [] | no_license | #!/usr/bin/env ruby
class Gemfiler
def execute
gem_name = parse_arguments[:name]
version_specs = parse_arguments[:versions]
searcher = Searcher.new(gem_name)
searcher.search
filter = Filter.new(version_specs, searcher.versions)
filter.match do |version, matches|
puts matches ? versio... | true |
40fea8e0766a42b5df6eeaeaa3e8d4906eda6ad5 | Ruby | ToniRib/turing-module1 | /Collection_Challenges/age_ordering.rb | UTF-8 | 987 | 4.3125 | 4 | [] | no_license | require 'pry'
data = [
['Frank', 33],
['Stacy', 15],
['Juan', 24],
['Dom', 32],
['Steve', 24],
['Jill', 24]
]
# Level 1: Write code that'll output the names (and only the names) in order by ascending age
puts 'Level 1:'
data.sort_by { |name, age| age }.each { |person| puts person[0] }
puts ""
# Level 2: ... | true |
9d487d176c683f63775ad5dbaf082e31601a8510 | Ruby | AgileVentures/shf-project | /spec/lib/one_time_tasker/evaluated_rake_task_spec.rb | UTF-8 | 5,995 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
lib_dir = File.join(__dir__, '..', '..', '..', 'lib',)
require_relative File.join(lib_dir, 'one_time_tasker', 'evaluated_rake_task')
RSpec.describe OneTimeTasker::EvaluatedRakeTask do
describe 'Unit tests' do
let(:dt_2019_06_14_010101) { DateTime.new(2019, 06, 14, 01, 01, 01) }
let(... | true |
5ad0d858416586ed005038b25115769a4d8081c0 | Ruby | Demener/socket_tester | /socket_client.rb | UTF-8 | 930 | 3.515625 | 4 | [] | no_license | require 'socket'
class SocketTester
attr_accessor :sock
def open_port (hostname='127.0.0.1', port=2000)
puts "Opening Host " + hostname + " on Port " + port.to_s + "."
@sock= TCPSocket.open(hostname, port)
end
def write_port s_send
puts "Sending: " + s_send
@sock.write(s_send)
end
def... | true |
984a0fd8ddb0c2ae51ac6bb7ccb39be2320f6dd5 | Ruby | o0gway/BlackJack | /main.rb | UTF-8 | 5,165 | 3.671875 | 4 | [] | no_license | # BlackJack
require 'byebug'
require_relative 'player'
require_relative 'dealer'
require_relative 'deck'
require_relative 'card'
require_relative 'game'
puts
puts '*' * 80
puts 'Добро пожаловать в игру BlackJack'
puts
class Interface
attr_accessor :game
def initialize(game)
@game = game
end
def start_ga... | true |
601110e0c7db340c9ca616c58565ae0a12171a40 | Ruby | danherr/ar-lite | /lib/associatable.rb | UTF-8 | 5,504 | 2.796875 | 3 | [] | no_license | require 'active_support/inflector'
class AssocOptions
attr_accessor :foreign_key, :class_name, :primary_key
def model_class
class_name.constantize
end
def table_name
model_class.table_name
end
end
class ThroughOptions
attr_accessor :through, :source, :self_class
def initialize(name, self_cla... | true |
fca48aa1a3c4e48c7260a908ec95594bb6fad6ff | Ruby | kaalm1/queue | /queue_stack.rb | UTF-8 | 1,018 | 3.609375 | 4 | [] | no_license | class QueueStack
attr_accessor :s1, :s2
def initialize
@s1, @s2, @max = [], [], []
@max2 = nil
end
def push(val)
@s1 << val
if !@max2 || val >= @max2
@max2 = val
end
end
def peek
if @s2.empty?
until @s1.empty?
val = @s1.pop
@s2 << val
@max << va... | true |
6e271ad1c013befc3f4722b57b04f7932bd8a31e | Ruby | FernandoBasso/programming-how-to | /ruby/well-grounded-rubyist/05-self-default-obj/10-cvars.rb | UTF-8 | 1,575 | 4.21875 | 4 | [] | no_license | #
# BEWARE: Ruby class CLASS VARIABLES.
#
# BEHOLD: Ruby has CLASS INSTANCE VARIABLES as well.
#
# DESPAIR: It is easy to get confused.
#
# HAVE FAITH IN THE FORCE: it is not so hard to understand them.
#
# Attr accessors don't work for class variables. We can't do
#
# class << self
# attr_reader :my_cvar
# end... | true |
d9fdad5391e55782cea4ce767e7d64f860241a65 | Ruby | pradeepto/mars-rover | /rover-test.rb | UTF-8 | 1,357 | 3.203125 | 3 | [] | no_license | require 'test/unit'
require_relative 'rover'
class TestPosition< Test::Unit::TestCase
def setup
@pos = Position.new(5,7,'N')
end
def test_position
assert_equal(5, @pos.x)
assert_equal(7, @pos.y)
assert_equal('N', @pos.bearing)
assert_not_equal(2, @pos.x)
assert_not_equal(6, @... | true |
3de2d9086772c1ec6fd59e76d7de843998cac1a9 | Ruby | wouterl/aoc2017 | /day7/tower.rb | UTF-8 | 635 | 3.421875 | 3 | [] | no_license |
nodes = {}
parent = {}
leafs = []
File.open(ARGV[0]).each_line do |line|
str_node, str_children = line.chop.split(" -> ")
# processing node
node, str_weight = str_node.split(" ")
weight = str_weight[1..-2].to_i
# puts "Node #{node} of weight #{weight}"
# process children
if str_children
... | true |
37cbaf755a7addf7ec1cd9b094fc1e96527ed4a0 | Ruby | Quasimonomial/App_Academy_Week1 | /w1d3/mastermind.rb | UTF-8 | 5,886 | 3.578125 | 4 | [] | no_license | #stole some array extending functionality form this guy:
# => http://www.dzone.com/snippets/full-intersection-between-2
class Array
def real_intersection(arr2)
self_sorted = self.sort
target_sorted = arr2.sort
intersection= []
jstart=0
for i in (0..self_sorted.length-1)
for j in (jstart..tar... | true |
871cb1beb6fd3b454e4944adb745985acd430ca8 | Ruby | thehimalayanleo/thehimalayanleo.github.io | /vendor/bundle/ruby/2.6.0/gems/csl-1.5.2/lib/csl/extensions.rb | UTF-8 | 1,302 | 2.640625 | 3 | [
"BSD-2-Clause",
"AGPL-3.0-only",
"GPL-1.0-or-later",
"AGPL-3.0-or-later",
"LicenseRef-scancode-other-copyleft",
"BSD-2-Clause-Views",
"MIT"
] | permissive |
# Some methods in this file are taken from ActiveSupport
# and are copyright (c) 2005-2010 David Heinemeier Hansson.
# They are loaded only if ActiveSupport is not present.
module CSL
module Extensions
# ActiveSupport Fallback
module SymbolizeKeys
def symbolize_keys
inject({}) do |options, (k... | true |
ddb0938aef9d64b1054f0f1ec3a6ab3108e02193 | Ruby | elisha2kyakpo1/Enumerables-project | /spec/our_test_spec.rb | UTF-8 | 2,901 | 3.546875 | 4 | [] | no_license | require_relative '../ruby'
describe Enumerable do
let(:my_array) { [1, 2, 3] }
let(:my_array1) { [1, 2, 30] }
describe '#my_each' do
it 'Performs a block of code if given and returns the passed enumerable' do
expect(my_array.my_each { |x| 5 * x }).to eq(my_array)
end
it 'Performs a block of cod... | true |
4abecdd1556b639412f5a52c968c5882daf3f268 | Ruby | awye765/learn_to_program | /ch10-nothing-new/civilization_III_without_edge_fix.rb | UTF-8 | 5,539 | 2.9375 | 3 | [] | no_license | # These are just to make the map easier for me to read.
# "M" is visually more dense than "o".
M = 'land' # => "land"
o = 'water' # => "water"
world = [
[o,o,o,o,o,o,o,o,o,o,o], # => ["water", "water", "water", "water", "water"... | true |
e74ef015ac2891fa8bcddb8427239d1f45cf05fe | Ruby | paige4521/Hangman | /hangman.rb | UTF-8 | 6,144 | 3.9375 | 4 | [] | no_license | my_dict = ["jordan", "justin", "jennifer", "granite", "classical", "tutorials"] #creats a list of words to be used for the game.
#Use the position fo the array to determine the word
random_word = my_dict[rand(6)]
rand_word = random_word.split(//) # assign a new variable to hold the characters of the randomly generate... | true |
b7ba85d350821097e33fa8c7b1f3fd35b4185528 | Ruby | catf62/Wk_2_wk_end_caraoke_homework | /guest.rb | UTF-8 | 997 | 3.421875 | 3 | [] | no_license | require_relative('room')
class Guest
attr_reader :guest_name, :booking_name, :guest_purse, :favourite_song, :guest_room
def initialize (guest_name, booking_name, guest_purse, favourite_song)
@guest_name = guest_name
@booking_name = booking_name
@guest_purse = guest_purse
@favourite_song = favourit... | true |
13e124d7d79bf715307f3c996522e0c70d0aaf6f | Ruby | hijazi/Scrapping | /scrapYears.rb | UTF-8 | 1,332 | 2.71875 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
#getting web pages links
sYear = 2008
while (sYear>2006)
sYear-=1
print "started with year: #{sYear}\n"
Dir.mkdir(sYear.to_s)
page1 = Nokogiri::HTML(open("http://www.cbssyr.org/yearbook/2007/SYR-2007-AR.htm"))
print "got #{sYear} link\n"
baseUri = "h... | true |
c4bf3a035726b057b6e1a5811e1c22e9da49ac65 | Ruby | ArayB/advent_of_code_2017 | /lib/day_ten/knot_hash.rb | UTF-8 | 1,255 | 3.28125 | 3 | [] | no_license | module DayTen
class KnotHash
def part_one(elements, lengths)
current_position = 0
skip_size = 0
lengths.each do |val|
elements.rotate!(current_position)
section = elements.shift(val)
elements = section.reverse + elements
elements.rotate!(-current_position)
... | true |
c81e35bbfda0a69044228bb4e351bec90b5268d2 | Ruby | sh6khan/ruby-algo | /graphs/topological_sort/graph.rb | UTF-8 | 215 | 3.234375 | 3 | [] | no_license | class Graph
attr_accessor :nodes
def initialize
@nodes = []
end
# add node to adjacent nodes
#
# @param from [Node]
# @param to [Node]
def add_edge(from, to)
from.adjacents << to
end
end
| true |
b8467e9eddf5ff59b01e1018565596bf727bfd8b | Ruby | luckypan123/learngit | /hello.rb | UTF-8 | 116 | 2.53125 | 3 | [] | no_license | class Hello < ParentClass
def initialize(args)
end
Hello=First.new(123,"luckypan")
puts Hello.Helloxxx
end | true |
95a38fcdf1a570d4eb7de1529e1bd3fdc3175dea | Ruby | mecampbellsoup/codewars | /anagrams.rb | UTF-8 | 1,887 | 3.984375 | 4 | [] | no_license | require_relative 'spec_helper'
# What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example:
# 'abba' & 'baab' == true
# 'abba' & 'bbaa' == true
# 'abba' & 'abbba' == false
# Write a function that will find all the anagrams of a word from a list. You will be g... | true |
aa54bb8a79ab5d3d23e26695b1cddc5bf93209ef | Ruby | TeamCheckmate/chess_app | /test/models/knight_test.rb | UTF-8 | 738 | 2.90625 | 3 | [] | no_license | require 'test_helper'
class KnightTest < ActiveSupport::TestCase
test "knight_move_valid" do
game = create_pieceless_game
knight = game.pieces.create(x_coord: 2, y_coord: 2, piece_type: "Knight")
# valid moves, king moves one square in any direction
[:+,:-].each do |operation|
# vertically
assert_... | true |
89ef1081edce55cd81e6dd95d59e99bda77dc28d | Ruby | amandatom/flash | /test/models/photo_test.rb | UTF-8 | 1,074 | 2.546875 | 3 | [] | no_license | # Author: Amanda Tom
# Last Updated: 14/11/2015
# This file specifies the default configuration to run tests of the Photo model
require 'test_helper'
class PhotoTest < ActiveSupport::TestCase
# test to determine if model can be used to create object with all attributes defined
test "create photo" do
photo = Photo.... | true |
7b4df31b33b8032bd1231195504d125d2a4334e2 | Ruby | zokioki/jun | /lib/jun/active_record/migrator.rb | UTF-8 | 2,346 | 2.515625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module ActiveRecord
class Migrator
ALLOWED_DIRECTIONS = %w[up down].freeze
def initialize(direction:)
unless ALLOWED_DIRECTIONS.include?(direction.to_s)
raise ArgumentError, "direction must be one of: #{ALLOWED_DIRECTIONS.inspect}"
end
@direction = di... | true |
bc5d3f9415a6e30c57e62d90b90a35035f919cbc | Ruby | wtfspm/advent_of_code | /2017/25/turing.rb | UTF-8 | 3,152 | 3.484375 | 3 | [] | no_license | #!/usr/bin/env ruby
class Turing
attr_accessor :states, :current_state, :current_position, :tape
def initialize(states, initial_state)
@states = states.dup
@current_state = initial_state
@current_position = 0
@tape = ['0']
end
def step(times = 1)
times.times do
cv = current_value
... | true |
6406289aba828423ec81ec7c2dc4f412bf2390bd | Ruby | nog/atcoder | /contests/abc184/c/main.rb | UTF-8 | 476 | 3.15625 | 3 | [] | no_license | r1, c1 = gets.split.map(&:to_i)
r2, c2 = gets.split.map(&:to_i)
if r1 == r2 && c1 == c2
puts 0
exit
end
if (r2 - r1).abs + (c2 - c1).abs <= 3
puts 1
exit
end
if (r1 + c1 == r2 + c2) || (r1 - c1 == r2 - c2)
puts 1
exit
end
if (r2 - r1).abs + (c2 - c1).abs <= 6
puts 2
exit
end
if ((r... | true |
a2121d18675de08f579ea5925e32ecf21e649ac8 | Ruby | AlessioMorselli/lab_programmazione_concorrente | /app/helpers/session_helper.rb | UTF-8 | 4,078 | 2.734375 | 3 | [] | no_license | module SessionHelper
# Esegue il log in dell'utente passato
def log_in(user)
session[:user_id] = user.id
end
# Restituisce l'utente attualmente loggato
def current_user
if (user_id = session[:user_id])
@current_user ||= User.find(user_id)
elsif (user_id = cookies... | true |
894b61abf40db681edc1d952902740c1b7d42c05 | Ruby | StefanRudvin/CodeMarkerBack | /demo/Ruby/resource.rb | UTF-8 | 43 | 2.734375 | 3 | [] | no_license | puts(gets.split.map{|i|i.to_i}.reduce(:+)); | true |
570d0dbc3c56d28768556f962b108a008cd35654 | Ruby | eknovoa/Programming_Foundations | /Small_Problems/easy_5/bannerizer.rb | UTF-8 | 2,607 | 4.34375 | 4 | [] | no_license | =begin
Problem
-write a method that will take a short line of text and print it within a box.
Input:
-string
Output:
-string display
Rules:
-you may assume that the input will always fit in your terminal window
Examples/Test Cases
print_in_box('To boldly go where no one has gone before.')
+--------------... | true |
9c3ea0dae2843a1bb5639a33e2a92c8e0788d6c8 | Ruby | dmccapes4/W3D2 | /sql/questions.rb | UTF-8 | 10,003 | 2.828125 | 3 | [] | no_license | require 'sqlite3'
require 'singleton'
class QuestionsDatabase < SQLite3::Database
include Singleton
def initialize
super('questions.db')
self.type_translation = true
self.results_as_hash = true
end
end
class ModelBase
def initialize
@table
@class
end
def self.all
data = Question... | true |
cd9560fbd3ab1f95a117b65f559ba9d26d46333e | Ruby | collabnix/dockerlabs | /vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/atomic/thread_local_var.rb | UTF-8 | 3,058 | 3.515625 | 4 | [
"Apache-2.0",
"MIT",
"Ruby"
] | permissive | require 'concurrent/utility/engine'
require 'concurrent/atomic/ruby_thread_local_var'
require 'concurrent/atomic/java_thread_local_var'
module Concurrent
###################################################################
# @!macro thread_local_var_method_initialize
#
# Creates a thread local variable.
#... | true |
95b5d6481f548e4a7792dd177cd2d4116f354127 | Ruby | michalg-/roda_graphql_boilerplate | /graphql/error_mapper.rb | UTF-8 | 685 | 2.921875 | 3 | [] | no_license | # frozen_string_literal: true
class ErrorMapper
attr_reader :message, :field, :code
def self.build(error)
case error
when Hash
new(field: error[:field], code: error[:code], message: message)
when ErrorMapper
error
when String
new(field: nil, message: error)
else
raise N... | true |
d55c02e99ca7235ba67becd958413753f416eca5 | Ruby | mjmb1995/ruby-object-initialize-lab-online-web-pt-120919 | /lib/dog.rb | UTF-8 | 277 | 3.390625 | 3 | [] | no_license | class Person
def initialize(this_persons_name)
@name=(this_persons_name)
end
attr_accessor :name
end
class Dog
def initialize(this_dogs_name, this_dogs_breed = "Mutt")
@name=(this_dogs_name)
@breed=(this_dogs_breed)
end
attr_accessor :name, :breed
end
| true |
85d67cbfc1205945036a040117dffd8ad54a6b72 | Ruby | florianroesler/finanzen.net-fundamentals | /transform.rb | UTF-8 | 2,696 | 2.859375 | 3 | [] | no_license | # encoding: utf-8
require 'pry'
require 'nokogiri'
require 'csv'
require_relative './lib/options_parser'
OPTIONS = OptionsParser.parse
def text_to_number(text)
text.gsub('.', '').gsub(',', '.').to_f
end
def extract_name(document)
document
.css('h2')
.first
.text
.encode('UTF-8', invalid: :replac... | true |
b7346e25531a37ebf507152576af1091291ee6e1 | Ruby | edsimpson/fibonacci-evs | /test/test_fibonacci-evs.rb | UTF-8 | 809 | 2.984375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'helper'
# class TestFibonacciGem < Test::Unit::TestCase
# should "probably rename this file and start testing for real" do
# flunk "hey buddy, you should probably rename this file and start testing for real"
# end
# end
class TestFibonacci < Test::Unit::TestCase
should "find the largest integer val... | true |
35af02d326a61f1ae77fd3eb706434446f630f41 | Ruby | Naoki-Nomi/learning | /c-learning/e.rb | UTF-8 | 238 | 3.21875 | 3 | [] | no_license | q = [*1..600]
p = q.reverse
n = 0
# while g <= 5000
# x = []
# g = 0
# p.each do |p|
# x << p
# g = x.sum
# end
# n += 1
# end
x = []
p.each do |p|
x << p
if x.sum >= 5000
n += 1
x.clear
end
end
puts n | true |
0046c0f8f366be5580f90a44c91055b256ac0bd5 | Ruby | alphagov-mirror/search-api | /lib/indexer/bulk_payload_generator.rb | UTF-8 | 2,429 | 2.75 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT"
] | permissive | module Indexer
class BulkPayloadGenerator
def initialize(index_name, search_config, client, is_content_index)
@index_name = index_name
@search_config = search_config
@client = client
@is_content_index = is_content_index
end
# Payload to index documents using the `_bulk` endpoint
... | true |
e0a62fa616a1a2f00527f667c2797921f3002b37 | Ruby | jiseruk/eventbus | /integration_tests/lib/subscriber_connector.rb | UTF-8 | 463 | 2.5625 | 3 | [] | no_license | class SubscriberConnector
attr_reader :last_response
attr_accessor :host
def initialize env = "localhost"
@host = (env == "docker") ? "subscriber" : "localhost"
puts "Using host for subscriber: #{@host}" if $debug
puts "events => #{last_event}" if $debug
self
end
def last_event
events.first
end
de... | true |
b56448d788e4c497dc2b3fad0a77b001af0a81e8 | Ruby | yoshinari-nomura/enumdate | /lib/enumdate.rb | UTF-8 | 2,330 | 2.8125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Enumerator for recurring dates
module Enumdate
class Error < StandardError; end
require "date"
dir = File.expand_path("enumdate", File.dirname(__FILE__))
autoload :EnumMerger, "#{dir}/enum_merger.rb"
autoload :DateEnumerator, "#{dir}/date_enumerator.rb"
autoload :Date... | true |
bd0e837056a8e74cf3827e527c42facaa30085f9 | Ruby | simplecov-ruby/simplecov | /lib/simplecov/exit_codes/maximum_coverage_drop_check.rb | UTF-8 | 2,364 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module SimpleCov
module ExitCodes
class MaximumCoverageDropCheck
def initialize(result, maximum_coverage_drop)
@result = result
@maximum_coverage_drop = maximum_coverage_drop
end
def failing?
return false unless maximum_coverage_drop && las... | true |
d9e0100b2183735cc10ca705c8764939aa98c550 | Ruby | Soph1ia/Ruby-Image-Processing-G | /app.rb | UTF-8 | 817 | 3.265625 | 3 | [] | no_license | require "functions_framework"
require "json"
require 'mini_magick'
# This function receives an HTTP request of type Rack::Request
# and interprets the body as JSON. It prints the contents of
# the "message" field, or "Hello World!" if there isn't one.
FunctionsFramework.http "hello_world" do |request|
input = JSON.p... | true |
04cc5de2ab915caea7d740526a9760f497cf862d | Ruby | lorenkp/App-Academy | /W2D2/chess/test.rb | UTF-8 | 404 | 3.28125 | 3 | [] | no_license | def horizontal_vertical_movement(pos)
horizontal_vertical_moves = []
(0..8).each { |x| horizontal_vertical_moves <<
[x, pos[1]] unless x == pos[0] }
(0..8).each { |y| horizontal_vertical_moves <<
[pos[0], y] unless y == pos[1] }
horizontal_vertical_moves
end
p horizontal_vertical... | true |
657f3aef6e7fadb9cd945f6f5a309a7563b8d362 | Ruby | NachoPal/golden_eggs_hen | /app/models/market_service/retrieve.rb | UTF-8 | 999 | 2.515625 | 3 | [] | no_license | module MarketService
class Retrieve
def fire! (market, currencies, price, volume)
name = market['MarketName']
unless currencies_present?(currencies)
primary = Currency.where(name: currencies.first).first
secondary = Currency.where(name: currencies.last).first
Market.create(n... | true |
5417d56b82910014fc0ad9094d1ac18afb98cc95 | Ruby | dl184/bearsRiversFishHW | /specs/river_spec.rb | UTF-8 | 645 | 3.265625 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../fish.rb")
require_relative("../river.rb")
require_relative("../bears.rb")
class RiverTest < MiniTest::Test
def setup
@fish1 = Fish.new("Steve")
@fish2 = Fish.new("John")
@fish3 = Fish.new("Clive")
@rivers = River.new("Amazon", ... | true |
7be06174e374cca84bca3e1b96cbdef4f45fe99f | Ruby | ChrisBarthol/project_euler | /problem17.rb | UTF-8 | 1,535 | 4.78125 | 5 | [] | no_license | #If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
#If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
#NOTE: Do not count spaces or hyphens. For example, 342 (th... | true |
a8644c98505bbb6da240476ff393063a16c002e3 | Ruby | innervisions/object-oriented-programming | /06_easy_2/04.rb | UTF-8 | 281 | 3.890625 | 4 | [] | no_license | # 04 - Reverse Engineering
class Transform
def initialize(str)
@text = str
end
def uppercase
@text.upcase
end
def self.lowercase(str)
str.downcase
end
end
my_data = Transform.new('abc')
puts my_data.uppercase
puts Transform.lowercase('XYZ')
# ABC
# xyz
| true |
d2d59e7665f0fa67f8c5a294635d54db82fc5ebd | Ruby | nubs/euler | /036-palindromic-bases.rb | UTF-8 | 209 | 3.859375 | 4 | [] | no_license | class Array
def sum
inject(0) {|sum, a| sum + a }
end
end
class String
def palindrome?
self == self.reverse
end
end
puts (1..999999).to_a.select {|i| i.to_s.palindrome? && i.to_s(2).palindrome? }.sum
| true |
6fc1cf874690100e0d101944347302003a3f3c4f | Ruby | MASisserson/rb101 | /small_problems/med_2/6.rb | UTF-8 | 595 | 3.984375 | 4 | [] | no_license | # Tri-Angles
=begin
input: 3 integers
return: one of 4 symbols
Rules:
1. Valid if
1. Sum of integers == 180
2. All angles > 0
2. right: One integer == 90
3. obtuse: One integer > 90
4. acute: all others
=end
def triangle(a, b, c)
angles = [a, b, c]
case
when angles.sum != 180 || angles.min <= 0
:in... | true |
e20c36cd99ace5ab879124a4dc1d9cbe16afdb8b | Ruby | scottalexandra/dinner_dash | /spec/models/item_spec.rb | UTF-8 | 3,773 | 2.78125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Item, :type => :model do
let!(:valid_item) do
@category = Category.create(name: "NewCategory")
@category2 = Category.create(name: "NewCategory2")
item = Item.new(title: "title", description: "desc", price: 10)
item.categories << @category
item.categories << ... | true |
b93c25e76a5c1ef64ecf9a25f50aa53fca8dd57c | Ruby | heavenchou/cbwork-bin | /note/chk_bm_note.rb | UTF-8 | 20,521 | 2.71875 | 3 | [] | no_license | # 檢查校注檔及 BM 經文檔,看二者是否有搭配與不合理的問題 ~by Heaven
#
#校注類型: [01]、[01A]、[A01]、【科01】、【標01】、【解01】。
#以「頁」為單位,比對「校注檔注標」及「內文檔注標」
#「校注檔注標」與「內文檔注標」的順序可以不一樣,只要各類型有連續且能夠"吻合"即可。
#如底下這樣是可以比對過關的:
#「校注檔注標」順序作:[01]→[02]→[03A]→[03B]→[04]→[A01]→【科01】→【科02】
#「內文檔注標」順序作:[01]→【科01】→[02]→[A01]→[03A]→[04]→[03B]→【科02】
#除以上狀況外,兩有不一致的地方(包括頁碼錯誤... | true |
eb3707ceca96b8372dbe329afbb6f4d1218abe70 | Ruby | CJStadler/state_machine_checker | /lib/state_machine_checker/ctl/api.rb | UTF-8 | 1,442 | 2.78125 | 3 | [
"MIT"
] | permissive | require_relative "and"
require_relative "atom"
require_relative "a_x"
require_relative "a_f"
require_relative "a_g"
require_relative "a_u"
require_relative "e_f"
require_relative "e_x"
require_relative "e_g"
require_relative "e_u"
require_relative "not"
require_relative "or"
require_relative "implication"
module State... | true |
053741aba3fc38dca96230d7c7adbb0fee5c0b1b | Ruby | signedcash/RailsLabs | /LR5/1_1.rb | UTF-8 | 160 | 3.03125 | 3 | [] | no_license | # frozen_string_literal: true
# Eval Class
class Eval
def self.eq(x_val, r_val, z_val)
Math.cos(x_val + 3.1 * z_val) / Math.tan(x_val / r_val)
end
end
| true |
4515b0a0a74e2bbf782a7a91279a7e85f0d137cd | Ruby | Bradicus/XCTE3 | /lib/plugins_core/lang_csharp/method_test_engine.rb | UTF-8 | 3,946 | 2.515625 | 3 | [
"Zlib",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class MethodTestEngine
end
##
#
# Copyright XCTE Contributors
# This file is released under the zlib/libpng license, see license.txt in the
# root directory
#
# This plugin creates a constructor for a class
require "x_c_t_e_plugin.rb"
module XCTECSharp
class MethodTestEngine < XCTEPlugin
def i... | true |
7100442eab1a84dacfa4b994261c7b8273bcc922 | Ruby | openpartners/Ruby | /38/storeapp/real_item.rb | UTF-8 | 163 | 2.734375 | 3 | [] | no_license | class RealItem < Item
attr_reader :weight
def initialize(name, options)
@weight = options[:weight]
super
end
def info
yield(weight)
super
end
end
| true |
39b832e4b296539cde72206154edb71d3313b928 | Ruby | alexmcbride/futureprospects | /app/controllers/staff/categories_controller.rb | UTF-8 | 2,303 | 2.59375 | 3 | [] | no_license | # * Name: Alex McBride
# * Date: 25/05/2017
# * Project: Future Prospects
# Controller class to allow staff member to manage course categories.
class Staff::CategoriesController < Staff::StaffController
before_action :set_staff_category, only: [:show, :edit, :update, :remove, :destroy]
# GET /staff/categories
#
... | true |
b68d2ce30f2709357867599bbcf0fb6c7c521715 | Ruby | rolentle/checkers | /lib/checkers.rb | UTF-8 | 1,569 | 3.5625 | 4 | [] | no_license | require './lib/piece'
class CheckersModel
attr_accessor :board, :white_pieces, :black_pieces
def initialize
create_board
populate_board
end
def create_board
@board = []
8.times do
@board << Array.new(8, "")
end
end
def populate_board
populate_white_pieces
populate_black_... | true |
a6cf2ee97f693a41e8d834e22f85a1e31311396f | Ruby | casualjim/caricature | /lib/caricature/isolator.rb | UTF-8 | 10,710 | 2.875 | 3 | [
"BSD-3-Clause"
] | permissive | require 'rubygems'
require 'uuidtools'
require File.dirname(__FILE__) + '/messenger'
require File.dirname(__FILE__) + '/descriptor'
module Caricature
# Groups the methods for interception together
# this is a mix-in for the created isolations for classes
module Interception
# the class methods of this inte... | true |
9bb6b3dfd17e5c5e581cc7e87a48d5ed77080357 | Ruby | irshadkhan248/ruby | /Section 8:Array-II/L112-forLoop.rb | UTF-8 | 139 | 3.390625 | 3 | [] | no_license | number=[10,20,45,20]
for num in number
print " #{num}" # IDEA:op=> 10 20 45 2020
end
puts num # IDEA: num accessed outside the loop also
| true |
03a7aac18ebe92cbcfed19107c8478b752189980 | Ruby | leahriffell/world_cup | /lib/world_cup.rb | UTF-8 | 683 | 3.390625 | 3 | [] | no_license | class WorldCup
attr_reader :year, :teams
def initialize(year, teams)
@year = year
@teams = teams
end
def active_players_by_position(position)
active_players = []
@teams.each do |team|
if team.eliminated? == false
active_players << team.players_by_position(position)
end
... | true |
43e71f565cf3db0d9106e85bcb2adc2864fd1343 | Ruby | thinkybeast/ruby-exercises | /small_problems/easy_4/easy_4_8.rb | UTF-8 | 1,405 | 4.6875 | 5 | [] | no_license | # Write a method that takes a String of digits, and returns the appropriate number as an integer. The String may have a leading + or - sign; if the first character is a +, your method should return a positive number; if it is a -, your method should return a negative number. If no sign is given, you should return a pos... | true |
382aa4e2558d1df44f23a0e84a432b60c1046e8a | Ruby | SilasOtoko/tealeaf-exercises | /Intro/more_stuff/exercise1.rb | UTF-8 | 212 | 2.6875 | 3 | [] | no_license | def has_lab?(string)
if /lab/i.match(string)
p string
else
p "no match"
end
end
has_lab?("laboratory")
has_lab?("experiment")
has_lab?("Pans Labyrinth")
has_lab?("elaborate")
has_lab?("polar bear") | true |
e8753c808e75662941ae840ece9125cd1e8d4283 | Ruby | eliaswebdev/RubyOnRailsSemest20153 | /aulas/aula5/test_classes.rb | UTF-8 | 279 | 2.8125 | 3 | [] | no_license | load 'student.rb'
# require_relative 'student'
alex = Person.new('Alexandro', 'Sousa', '1973-03-21' )
puts alex.full_name
puts alex.age
ely = Student.new('Elyamara', 'Araujo', '1991-11-05', '123456')
puts ely.full_name
puts ely.registration
puts ely.profile
puts ely.instancia | true |
da37eb4456a3fa0306c617d983744be881a0f793 | Ruby | rachelinkala/brainteaser8 | /brain_teaser8.rb | UTF-8 | 548 | 3.46875 | 3 | [] | no_license | require 'httparty'
require 'pry'
def main_menu
puts 'Welcome. What would you like to do?'
puts '1. Create a user'
puts '2. View all users'
puts '3. Show a user'
@input = gets.chomp.to_i
choices
end
def choices(@input)
if @input === 1
create_user
elsif @input === 2
v... | true |
8c8d5e51409dfbb43e984916b6e0e03c0b62e18b | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/binary-search-tree/6aa70a87ca954fe5991298f7e912afa9.rb | UTF-8 | 408 | 3.640625 | 4 | [] | no_license | class EmptyBst
def insert(n)
Bst.new(n)
end
def each(&block) end
end
class Bst
EMPTY = EmptyBst.new
attr_reader :left, :right, :data
def initialize(n)
@data = n
@left = @right = EMPTY
end
def insert(n)
n <= data ? @left = @left.insert(n) : @right = @right.insert(n)
self
end
... | true |
807d27e68e6d7e2f9c9dd30c78fa6009306246f1 | Ruby | dinhdothuy/learn_the_hard_way | /test_module.rb | UTF-8 | 611 | 4.15625 | 4 | [] | no_license |
module AgeCalc
# define a class method of a module - use syntax <module name>.<method name>
def AgeCalc.age_now(birth_year)
Time.now.year - birth_year
end
end
# Use Module class method: Call directly, using syntax <module name>.<method name>
puts "AgeCalc.age_now = #{AgeCalc.age_now(1971)}"
module MathCalc... | true |
bb7cdbaf034a0b46985cd7fe64b09ba209107f49 | Ruby | IDolgirev/solid-principles-ruby | /spec/integration/battle_spec.rb | UTF-8 | 2,309 | 2.859375 | 3 | [] | no_license | require 'spec_helper'
require_relative '../../lib/hero'
require_relative '../../lib/monster'
require_relative '../../lib/attack_action'
require_relative '../../lib/flee_action'
require_relative '../../lib/dicepool'
describe "Battle" do
let(:monster) { Monster.new toughness: 2,
notice:... | true |
acf68f5fe927625679c70a1b2ffe9addc32a8e03 | Ruby | victormartins/katas | /docker_katas/03_rack_with_middleware/src/lib/middleware/request_tracer.rb | UTF-8 | 2,747 | 2.875 | 3 | [] | no_license | # frozen_string_litera: true
require 'securerandom'
module MyApp
module Middleware
# Adds headers to the request to help tracing.
class RequestTracer
# Header in is normal format
RESPONSE_X_REQUEST_ID = 'X-Request-Id'
# Header in the env format
REQUEST_HTTP_X_REQUEST_ID = 'HTTP_X_REQ... | true |
bf429d8ff70ca6b7f0e2dcc99edc58ca9c7075cb | Ruby | Aniretaka/AutomatedTesting | /features/step_defenitions/Lesson_6_Advanced/Lesson_6_Advanced.rb | UTF-8 | 2,361 | 2.828125 | 3 | [] | no_license | # encoding: UTF-8
#Line above is for understanding Russian language in Xpath
def toUtf8(str)
str = str.force_encoding('UTF-8')
return str if str.valid_encoding?
str.encode("UTF-8", 'binary', invalid: :replace, undef: :replace, replace: '')
end
Then /^Login using different credentials$/ do
#1) spreadsheet gem ... | true |
f6d4768e853e32d8f4a92d3be02635939f286e13 | Ruby | wombleton/ensmartle | /lib/written_question_parser.rb | UTF-8 | 2,861 | 2.828125 | 3 | [] | no_license | require 'hpricot'
class WrittenQuestionParser
def parse html
q = WrittenQuestion.new
@doc = Hpricot.parse(html)
date_text = @doc.at("meta[@name='DC.Date']").get_attribute(:content)
q.date_asked = Date.parse(date_text[0,10])
title = @doc.at("meta[@name='DC.Title']").get_attribute(:content)
m... | true |
4a5991df25ea4cbf4671a42f374888a81d11e1b0 | Ruby | natesholland/tdd-rspec-training-prototype | /sinatra/tdd_rspec.rb | UTF-8 | 601 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'sinatra'
require 'sinatra/contrib'
require 'json'
require 'mhem'
# require 'pry'
get '/' do
{hello: 'world'}.to_json
end
get '/encode' do
message = params[:message]
if message
{ message: Mhem.encode(message) }.to_json
else
status 400
{ error: "please pass in a message to encode" }.to_js... | true |
d169cbb5a917025f6f508ec956e9e46e0254a97b | Ruby | AteroConfigs/hairball | /test/template_test.rb | UTF-8 | 1,031 | 2.546875 | 3 | [] | no_license | require "test_helper"
require 'ostruct'
Treetop.load File.join(File.dirname(__FILE__), '../lib/hairball/hairball')
class TemplateTest < Test::Unit::TestCase
def setup
@html = Hairball::Template3000.new(:ruby_no_block, :user => OpenStruct.new(:name => "Eric Allam")).to_html
end
def test_instance_variabl... | true |
0b67c09235786748dcabfa021600a43af1d5ea2a | Ruby | thomation/Snow-Lang | /Core/ASTree/ASTLeaf.rb | UTF-8 | 248 | 2.734375 | 3 | [
"MIT"
] | permissive | require_relative 'ASTNode'
class ASTLeaf < ASTNode
def initialize(token)
@token = token
end
def token
return @token
end
def test(level, tag)
debug_log(level, tag, "ASTLeaf #{@token.debug_s}")
end
end | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.