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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
86ebc076621f02cd71d830fd098204a726ed847d | Ruby | troynt/AdventOfCode2018 | /challenges/12/plant_pot.rb | UTF-8 | 755 | 3.171875 | 3 | [] | no_license | class PlantPot
attr_accessor(
:state,
:next,
:prev,
:next_state,
:location
)
def initialize(state, location: nil)
@state = state
@location = location
end
def state_with_neighbors
self_with_neighbors.map(&:state).map {|x| !x.nil? && x == true ? '#' : '.'}.join ''
end
def ... | true |
815a6ed65f9a8fac912c12793c9b324f67c666e6 | Ruby | smellman/chiba_5374_generator | /make_data.rb | UTF-8 | 1,907 | 2.78125 | 3 | [] | no_license | # coding: utf-8
require 'csv'
sites = %w(hanamigawa midori mihama tyuuou wakaba)
# for target.csv
use_target = %w(可燃ごみ びん・缶・ペットボトル 古紙・布類 不燃ごみ・有害ごみ(危険物))
target_header = %w(label name notice furigana)
base_target_csv = 'chiba_target.csv'
# for area_days.csv
area_days_header = %w(地名 センター 可燃ごみ びん・缶・ペットボトル 古紙・布類 不燃ごみ・有害ご... | true |
cf0ae781b93a08e2fea3cfa1b3d074fc811dd4e6 | Ruby | jake-webber-au/toy_robot | /Table.rb | UTF-8 | 245 | 3.140625 | 3 | [] | no_license | require_relative './errors.rb'
class Table
def initialize(x = 5, y= 5)
@x = x
@y = y
end
def check_boundary(x,y)
if !x.between?(0,@x) || !y.between?(0,@y)
raise RobotOutOfBounds.new
end
return true
end
end
| true |
08bf772aee93afd99eca95f32ba24ca6cfded246 | Ruby | exchai93-zz/student-directory | /directory_ex12.rb | UTF-8 | 2,779 | 4.53125 | 5 | [] | no_license | # loading procedure is going to be the reverse of what we've done to save the data to the file
# 1. open file for reading
# 2. read contents of the file
# 3. iterate over all lines
# 4. split every line at the comma
# 5. put a new hash into the array @students
# 6. close the file
@students = [] # an empty array access... | true |
59c2e7016aeacc209399d8cf9bfaa7af117bfb7d | Ruby | justinnnnnnnn/aaclasswork | /w4d4/first tdd projects/lib/00_first_tdd.rb | UTF-8 | 941 | 3.6875 | 4 | [] | no_license | def my_uniq(a)
banana = []
a.map do |el|
banana << el if !banana.include?(el)
end
banana
end
def two_sum(arr)
pairs = []
arr.each_with_index do |el1, i1|
arr.each_with_index do |el2, i2|
if arr[i1] + arr[i2] == 0 && i2 > i1
pairs << [i1, i2]
... | true |
bbcef4e0b5819c203d1b7d95753aa44b9c8e1d7e | Ruby | iamianami/ian_calculator | /ian_calculator.rb | UTF-8 | 1,271 | 3.90625 | 4 | [] | no_license | # def say(msg)
# puts "------#{msg}------"
# end
# say("Please type your first number")
# number1 = gets.chomp.to_i
# say("Please type your second number ")
# number2 = gets.chomp.to_i
# say("Choose 1)add 2)sub 3)multi 4) divided")
# operation = gets.chomp.to_i
# if operation == 1
# result = number1 + number... | true |
c0a36cf998b3f2bb27b7dc2ccd0f4bb9dee8993a | Ruby | fadhlinahamdan/webhook-shopify-ruby | /app.rb | UTF-8 | 4,108 | 2.53125 | 3 | [] | no_license | require 'rubygems'
require 'base64'
require 'openssl'
require 'sinatra'
require 'active_support/security_utils'
require 'shopify_api'
require 'rails'
require 'sendgrid-ruby'
include SendGrid
require 'twilio-ruby'
# The Shopify app's shared secret, viewable from the Partner dashboard
# webhook string
SHARE... | true |
9c002e4c1960164ec61c2a640edaae7e283470fb | Ruby | dhan0406/ride-share-rails | /test/models/passenger_test.rb | UTF-8 | 2,505 | 2.734375 | 3 | [] | no_license | require "test_helper"
# file replaced with one sent by Jared
describe Passenger do
let (:new_passenger) {
Passenger.new(name: "Kari", phone_num: "111-111-1211")
}
it "can be instantiated" do
# Assert
expect(new_passenger.valid?).must_equal true
end
it "will have the required fields" do
# Arrange
new_pass... | true |
71d058479a47abe743c999e046e5dfd5c047cffb | Ruby | Damnedlag/Ruby-exercises | /03_simon_says/simon_says.rb | UTF-8 | 896 | 4.15625 | 4 | [] | no_license | #write your code here
def echo(thing)
thing
end
def shout(thing)
thing.upcase
end
def repeat(*arr)
array = *arr
if !array[1]
array << 2
end
solution = (array[0] + ' ') * array[1]
solution.chomp(' ')
end
def start_of_word(word, num)
i = 1
solution = word[0]
while i < n... | true |
246d8c1fed3c415cba17c6a40088b3dff8e0aff1 | Ruby | bethsecor/tealeaf-intro-to-programming | /Workbook/Easy/Quiz3/exercise3.rb | UTF-8 | 210 | 2.609375 | 3 | [] | no_license | # Tealeaf Academy Prep Course
# Intro to Programming Workbook
# Easy Questions - Quiz 3
# Exercise 3
flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
flintstones << "Dino"
flintstones.push("Dino","Hoppy")
| true |
e4129e9642fd72d26e63b6305b5c4eedb2256c01 | Ruby | codeauslander/actualize-class | /intro_to_apis/reddit_app.rb | UTF-8 | 914 | 3.171875 | 3 | [] | no_license | require 'unirest'
looking_up_words= true
while looking_up_words
url = "https://www.reddit.com/r/programming/.json"
response = Unirest.get(url).body
posts = response['data']['children']
print "Please enter the post number from 0 to #{posts.length}: "
number = gets.chomp.to_i
puts
permalinks = []
p... | true |
f3967c8af1b514726020d3761a0455c51e50bc0b | Ruby | fastmode/badges-and-schedules-v-000 | /conference_badges.rb | UTF-8 | 1,183 | 4.34375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
attendees = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
def badge_maker(name)
"Hello, my name is #{name}."
end
#This will create array of all the attendess with the welcome message.
def batch_badge_creator(attendees)
badges = []
attendees.each do |attendee|
badges << badge_maker(attendee... | true |
3d93f1862ec5984ae14e51539100b91c4b7d2fc7 | Ruby | inbabbini/ttps_ruby_2015 | /Practicas/Practica3/exceptions/e4.rb | UTF-8 | 421 | 3.484375 | 3 | [] | no_license | # retry
# retry sirve para, justamente, volver a ejecutar el bloque en el cual
# se encuentra, desde la sentencia begin (es decir, desde el principio)
begin
#dangerous code
rescue Exception
puts 'Something broke'
#do something to fix problems
retry
end
# Ejemplo boludo:
num = 0
begin
if num == 5
'ok... | true |
b54ab468bc40c9d517ddee9a50ecb44b1dab4e23 | Ruby | TDA/Ruby-GithubAPI | /language_dictionary_generator.rb | UTF-8 | 1,542 | 3.1875 | 3 | [] | no_license | require 'json'
#language_dictionary_generator
File.open('/Users/schandramouli/PycharmProjects/GithubAPI/languages_data_sorted.json') do |file|
data = file.readlines
data_string = ""
data.each {|line| data_string += line.chomp}
language_data = JSON.parse(data_string)
# set the LoC for all the languages to 0... | true |
a5856c467b598560b06adde93205f08e1c4835bf | Ruby | k2works/ruby-design-pattern | /factory/duck_pond.rb | UTF-8 | 284 | 2.96875 | 3 | [] | no_license | require './pond'
#
# == アヒル@池クラス
#
# Author:: k2works
# Version:: 1.0.0
# License:: Ruby License
#
class DuckPond < Pond
def new_organism(type, name)
if type == :animal
Duck.new(name)
else
raise "Unknown organism type: #{type}"
end
end
end
| true |
bd623103c7b1867ad301bfe909753b7b2fd9ace5 | Ruby | NotReady/memo | /ruby/chapter2/2-2-2b.rb | UTF-8 | 405 | 4.09375 | 4 | [] | no_license | # 引数と戻り値をもつメソッド
# 戻り値は最終行の式結果
def triangle(base, height)
return nil if base == 0 || height == 0
result = base * height / 2.0
result
end
area = triangle(11, 9)
puts "面積は#{area}です。"
area = triangle 11, 9 #=> 呼び出しの小かっこは省略可能
puts "面積は#{area}です。"
area = triangle 0, 1
puts "面積は#{area}です。"
| true |
9812eae5483f4db37ee7ed48af71404ba9472aaf | Ruby | ElaErl/Challenges-1 | /Easy1/perfect_number.rb | UTF-8 | 266 | 3.5 | 4 | [] | no_license | class PerfectNumber
def self.classify(num)
raise RuntimeError if num < 0
sum = 0
1.upto(num-1) {|n| sum += n if num % n == 0}
case
when sum == num then 'perfect'
when sum < num then 'deficient'
else 'abundant'
end
end
end
| true |
a3767cf60b376667025f127f3edabd99b65cd4b4 | Ruby | ericak11/project_euler | /number_6_squares.rb | UTF-8 | 855 | 4.03125 | 4 | [] | no_license | # ############################## sum of square difference - #6 ###########################
# The sum of the squares of the first ten natural numbers is,
# 12 + 22 + ... + 102 = 385
# The square of the sum of the first ten natural numbers is,
# (1 + 2 + ... + 10)2 = 552 = 3025
# Hence the difference between the sum of... | true |
68bf2db8f961b46c66a54cd74198449a9504ecb0 | Ruby | KlotzAndrew/algorithms | /lib/graph/depth_first_search.rb | UTF-8 | 939 | 3.5 | 4 | [] | no_license | class DepthFirstSearch
def traverse(adjacency_list, node)
@result = []
@stack = []
@traversed_graph = []
adjacency_list.length.times do
@traversed_graph << [false, nil]
end
search_nodes adjacency_list, node
@traversed_graph
end
private
def search_nodes(adjacency_list, node)... | true |
f8b1aea68afaab25d669151f6eb071018206288f | Ruby | JasonP77/programming-univbasics-nds-nds-to-insight-with-methods-dc-web-012720 | /lib/nds_extract.rb | UTF-8 | 718 | 3.171875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'directors_database'
# Find a way to accumulate the :worldwide_grosses and return that Integer
# using director_data as input
def gross_for_director(director_data)
total = 0
i = 0
while i < director_data[:movies].length do
total += director_data[:movies][... | true |
9fcf5fcaaf417034f34ee7a040e3e551500ae35b | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/eb71d15b94994b0bacbd53f47600f5db.rb | UTF-8 | 307 | 3.421875 | 3 | [] | no_license | class Words
attr_reader :words
def initialize(string)
@words = normalize_input(string)
end
def count
words.each_with_object(Hash.new(0)) do |word, hash|
hash[word] += 1
end
end
private
def normalize_input(string)
string.downcase.gsub(/\W+/, ' ').split(" ")
end
end
| true |
0569967dc9b0e3979c1ad1e47bc215442c0bc759 | Ruby | alphagov-mirror/tv-radio-fillers-reporting-dashboard | /tests/helpers/csv_parser_radio_test.rb | UTF-8 | 1,811 | 2.6875 | 3 | [] | no_license | require_relative '../../app/helpers/csv_parser_radio.rb'
require_relative '../../app/models/transmission.rb'
require 'test/unit'
require 'csv'
class CsvParserRadioTest < Test::Unit::TestCase
DATE_FORMAT = '%d-%b-%y'
SAMPLE_FILE_FULL_PATH = "tests/helpers/csv_samples/radio_fillers_sample.csv"
def setup
... | true |
48839ae7f90eb263eaf8e20dfbcc87eec843e0c3 | Ruby | MihirKale89/Ruby_code | /TimeProcessor/lib/time_processor.rb | UTF-8 | 1,995 | 3.921875 | 4 | [] | no_license | =begin
Without using any built-in date or time functions, write a function or method
that accepts two mandatory arguments: the first argument is a 12-hour time
string with the format "[H]H:MM {AM|PM}", and the second argument is a (signed)
integer. The second argument is the number of minutes to add to the time of day
... | true |
99786877d828de548c60d1f0e9a9e8d3413cb4fd | Ruby | hogeline/weather-analysis | /getaverage.rb | UTF-8 | 752 | 2.953125 | 3 | [] | no_license | #!/usr/bin/env ruby
# coding: utf-8
require 'fileutils'
array = Array.new
ARGV.each_with_index do |file, i|
array[i] = Array.new(13, 0.0)
count = Array.new(13, 0.0)
array[i][0] = file.to_i
open(file+'.csv', 'r:utf-8') do |f|
f.each do |line|
fields = line.chomp.split(',')
date = fields[0].chom... | true |
d5d0e23430420c3ba97a3e40cb83d906d516b567 | Ruby | covaithe/project_euler | /lib/permutations.rb | UTF-8 | 907 | 3.8125 | 4 | [] | no_license |
class Permutations
def self.of(list, n)
raise "The list is nil" if list.nil?
raise "There are not that many items in the list" if n > list.size
raise "Cannot pick #{n} items from a list" if n < 0
return [] if n == 0
return [ list ] if n == list.size
result = []
indexes = (0..n-1).to_a
... | true |
08c142a841b6986e553939a03d35ca8f47c85822 | Ruby | willcannings/impromptu | /lib/impromptu/resource.rb | UTF-8 | 9,370 | 2.765625 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | module Impromptu
# Resources represent the modules or classes that are tracked by
# Impromptu and which can be lazy loaded. You should never create
# resources yourself - use component definitions to define folders
# of files which will implement resources.
class Resource
attr_reader :name, :base_symbol, ... | true |
05d4deaee223fee00bc0ab08d843c77cf39809f0 | Ruby | douglasf/base | /bin/web.watchr.rb | UTF-8 | 1,363 | 2.828125 | 3 | [] | no_license | require "fileutils"
# @key is pre compiled file type.
# @value is
# :compiler, what compiler to use, the compiler must print result to stdout
# :ending, the file ending to use after compilation
@settings = {
"less" => {
:compiler => "lessc",
:ending => "css"
},
"haml" => {
:compiler => "haml",
... | true |
c6c1a0190ac8072ae119c19c672dcf820ac3dc78 | Ruby | collinschaafsma/pedal | /lib/pedal/presenter.rb | UTF-8 | 296 | 2.578125 | 3 | [
"MIT"
] | permissive | module Pedal
class Presenter
attr_reader :subject
def initialize(subject)
@subject = subject
end
# Proxy to the Builder, adds itself to the scope
# so we can access the @subject
def build(&block)
Pedal::Builder.build(scope: self, &block)
end
end
end
| true |
f21415f73d030e47972a537d83f4804e8bc3b97d | Ruby | Claire7514/exo_ruby | /exo_09.rb | UTF-8 | 88 | 2.8125 | 3 | [] | no_license | user_name = gets.chomp
name = gets.chomp
puts "Bonjour " + user_name + " " + name + "!"
| true |
69b4423eab0cb21ed64ebd039e473b436131ec57 | Ruby | bhserna/guests | /lib/invitations.rb | UTF-8 | 740 | 2.765625 | 3 | [] | no_license | module Invitations
def self.save_record(list_id, invitation, store)
store.create(
list_id: list_id,
invitation_id: invitation["id"].to_i,
raw_data: invitation)
end
def self.update_record(list_id, invitation, store)
record = store.find_for_list_by_invitation_id(list_id, invitation["id"])... | true |
1ae8296f86427228acd3513c5fe601974e1237fd | Ruby | JonathanUriel/RailsWeb | /blog/app/controllers/articles_controller.rb | UTF-8 | 2,116 | 2.984375 | 3 | [] | no_license | class ArticlesController < ApplicationController
#Variables con "@" sirven para manipular esa variable ya sea
#vistas o controladores, la variable sin @ solo se puede usar
#en el controlador, en el cual fue declarada
#GET /articles
def index
#Todos los registros
@article = Article.all #Trae todos los datos ... | true |
2142bd3df573c0dded9f5ce903498dcbe5cc3a97 | Ruby | bogdanovich/cadence-ruby | /examples/workflows/branching_workflow.rb | UTF-8 | 404 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | require 'activities/random_number_activity'
require 'activities/hello_world_activity'
class BranchingWorkflow < Cadence::Workflow
def execute
random_number = RandomNumberActivity.execute!(max: 100)
if random_number > 50
HelloWorldActivity.execute!('top half')
else
HelloWorldActivity.execute!... | true |
6a9a5a678f622c9d8ac46686ad386bab0f675964 | Ruby | rohanphillips/activerecord-tvland-online-web-sp-000 | /app/models/actor.rb | UTF-8 | 358 | 2.515625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Actor < ActiveRecord::Base
has_many :shows, through: :characters
has_many :characters
def full_name
self.first_name + " " + self.last_name
end
def list_roles
collection = []
self.characters.joins(:show).each{|item|
collection << (item.name + " - " + item.show.name)
... | true |
722a5a7d1158fd6fbcda30017ccc9bec38b15298 | Ruby | jeik0210/prueba_capistrano | /app/models/user.rb | UTF-8 | 305 | 2.59375 | 3 | [] | no_license | class User < ActiveRecord::Base
belongs_to :editorial
before_save :up_full_name
def full_name
paternal.to_s + " " + maternal.to_s + " " + name.to_s
end
def up_full_name
self.name = self.name.upcase
self.paternal = self.paternal.upcase
self.maternal = self.maternal.upcase
end
end
| true |
e5e71c9bf9b4dedbbfaa01eb86cedcb58418d7aa | Ruby | reasonset/installed-font-list-html | /installed-font-list-html.rb | UTF-8 | 3,659 | 2.609375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
require 'erb'
ERB_TEMPLATE = <<EOF
<html>
<head>
<title>Installed Fonts (<%= ([modename] + optionname).join(",") %>)</title>
<style>
p { margin-left: 40px; }
section {
margin-top: 15px;
border-top: #339 solid 2px;
}
</style>
</head>
<body>
<h1>In... | true |
08533550ada040ba7229c175d6dab15e3f6e606e | Ruby | tylergreason/pokemon_backend | /db/seeds.rb | UTF-8 | 2,538 | 3.015625 | 3 | [] | no_license | require 'faker'
# Pokemon.delete_all
User.delete_all
Team.delete_all
# reset all pokemon types
# natures
# only seed natures if Nature.all is empty
if Nature.all.count == 0
natures = PokeApi.get(:nature).results
natures.each do |nature|
name = nature.name
Nature.find_or_create_by(name:... | true |
16aced0ae01cf9e539877ead3d81dee6ea12bff2 | Ruby | kupolak/codewars | /Ruby/7 KYU/Nickname Generator.rb | UTF-8 | 159 | 3.046875 | 3 | [] | no_license | def nickname_generator(name)
if name.length >= 4
/\A[auieoAUIEO]\z/.match(name[2]) ? name[0..3] : name[0..2]
else
"Error: Name too short"
end
end | true |
2b22f4f2eb68a8a6afef82f95624fca7970fa364 | Ruby | reneeknox/prime-ruby-online-web-pt-071519 | /prime.rb | UTF-8 | 483 | 3.734375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(integer) # 11
if integer < 2
false
else
a = (2..integer - 1).to_a
# [3,4,5,6,7,8,9]
# a = [3,4,5,6,7,8,9,10]
# integer % n == 0 is prime
# [].none? # None of the numbers prior to integer are divisible by integer
# Madeline told me this is a good idea to include; I read that ... | true |
89826b68188ab75e503c6a7caabeaa8dd4d3a6c1 | Ruby | Artforge/has_many_translations | /lib/has_many_translations/control.rb | UTF-8 | 1,805 | 2.6875 | 3 | [] | no_license | module HasManyTranslations
module Control
def self.included(base) # :nodoc:
base.class_eval do
include InstanceMethods
# alias_method_chain :create_translation?, :control
# alias_method_chain :update_translation?, :control
end
end
module InstanceMet... | true |
5c6141454f1e0349a5bb009539c44248fa73c788 | Ruby | shoehead0125/crawler-study | /chapter-1/sbcr-sample/sbcr1.rb | UTF-8 | 491 | 2.9375 | 3 | [] | no_license | #! /usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'pry'
require 'cgi'
def parse(page_source)
dates = page_source.scan(
%r!(\d+)年 ?(\d+)月 ?(\d+)日<br />!)
url_titles = page_source.scan(
%r!^<a href="(.+?)">(.+?)</a><br />!)
url_titles.zip(dates).map { |(aurl, atitle), ymd|
[
CGI.unescapeHTML(... | true |
ead40f498e599c58f6d5d9380e3b0c201f70a7e8 | Ruby | mvz/ripper_ruby_parser | /test/samples/loops.rb | UTF-8 | 378 | 3.140625 | 3 | [
"MIT"
] | permissive | # Loop samples
def for_samples
for foo in bar
end
for foo, bar in baz
end
for foo, in bar
end
end
# begin..end in conditions
#
def while_until_samples
while begin foo end
bar
end
until begin foo end
bar
end
while begin foo end do
bar
end
until begin foo end do
bar
end
... | true |
acbb70446386aad295f8f93d882f70d221e3d874 | Ruby | dafoxia/mumble-ruby | /lib/mumble-ruby/packet_data_stream.rb | UTF-8 | 3,408 | 3.171875 | 3 | [
"MIT"
] | permissive | module Mumble
class PacketDataStream
def initialize(data=nil)
@data = data || 0.chr * 8192
@data = @data.split ''
@pos = 0
@ok = true
@capacity = @data.size
end
def valid
@ok
end
def size
@pos
end
def left
@capacity - @pos
end
def... | true |
b6c04964c0a96fdf8abc3f0bd92bdd09af4c35f9 | Ruby | kunks001/boris_bikes | /boris_bikes.rb | UTF-8 | 278 | 3.640625 | 4 | [] | no_license | # class Person
# def initialize(name)
# @name = name
# @bike = 0
# end
# def name
# @name
# end
# def id
# end
# def bike
# @bike
# end
# def gets_bike
# @bike +=1
# end
# def returns_bike
# @bike -=1
# end
# end | true |
c0d3c4b9f2fe9690ecffa5651868569e774919a8 | Ruby | skunath/STAT | /phoneme.rb | UTF-8 | 6,887 | 2.9375 | 3 | [] | no_license | class Phoneme
def initialize(args)
@cskip = -10.0
@csub = 35.0
@cexp = 45.0
@cvowel = 10.0
@epsilon = 0.0
@character = args[:character]
@type = args[:type] # vowel, consonant, diacritic
@manner = args[:manner]
@place = args[:place]
@high = args[:high]
@back = args[:bac... | true |
b076f8978f2f51233968c40cafb911da7ea22421 | Ruby | sujankh/SimPlParser | /simplparser.rb | UTF-8 | 655 | 3.1875 | 3 | [] | no_license | #!/usr/bin/ruby
require_relative './lexer'
require_relative './parser'
def getTokenKind()
$tokenizer.getTokenKind()
end
def getTokenText()
$tokenizer.getTokenText()
end
#consume token
def nextToken()
$tokenizer.nextToken()
end
def parseProgram()
inputFile = ARGV[0]
begin
$tokenizer.readFile(in... | true |
cfe0c4cb1d8f7b017e7b337507fa9a30f4e7a645 | Ruby | DavidPAdams/nlr | /Lesson_1_hw/calculator.rb | UTF-8 | 148 | 3.015625 | 3 | [] | no_license |
def add(a,b)
a + b
end
def subtract(c,d)
c - d
end
def multiply2(e,f)
e * f
end
def divide2(g,h)
h != 0 ? g/h : "undefined"
end
| true |
435e0a014017addf59e0d5837188a3436b5a6bd5 | Ruby | dbirtwell/RubyLearning_32 | /Week_7/rubyprograms/lesson7exercise3.rb | UTF-8 | 1,509 | 4.65625 | 5 | [] | no_license | # lesson7exercise3.rb
# David Birtwell
=begin
Week 7 Exercise 3.
Write a method called month_days, that determines the number of days in a
month. Usage:
days = month_days(5) # 31 (May)
days = month_days(2, 2000) # 29 (February 2000)
Remember, you could use the Date class here. Read the online d... | true |
b01cbb60fbaea909777bd1791b0921f794220ee2 | Ruby | ruben/smalltalk-best-practice-patterns | /3-behaviour/2-messages/3-intention_revealing_message/1-paragraph_editor.rb | UTF-8 | 372 | 3.515625 | 4 | [] | no_license | # How do you communicate your intent when the implementation is simple?
#
# Send a message to “self.” Name the message so it communicates what is to be done rather than how it is to be done.
# Code a simple method for the message.
# We highlight a rectangle (WHAT) by reversing it (HOW)
class ParagraphEditor
def high... | true |
2b9dfea91af9ec88509bd6b28c4b25310574dbfa | Ruby | avescodes/botfly | /lib/botfly/callback_context.rb | UTF-8 | 1,629 | 2.765625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Botfly
class CallbackContext
def initialize(caller, params)
setup_params(params)
@caller = caller
end
def method_missing(name, *args)
@caller.send(name,*args) if name.to_s.scan(/^setup/).empty?
end
private
# OK, so. Get the instance's eigenclass, then, call the private m... | true |
70b038d2f1ea28c74e0ab5ee01e3adace44c24cc | Ruby | takahiro825/furima-28705 | /spec/models/user_spec.rb | UTF-8 | 5,697 | 2.734375 | 3 | [] | no_license | require 'rails_helper'
describe User do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー登録' do
context 'ユーザー登録がうまくいくとき' do
it "nicknameとemail、passwordとpassword_confirmation、family_name、first _name、family_name_kana、first _name_kana、birthdayが存在すれば登録できる" do
expect(@user).to be_vali... | true |
83b6236399857bfa000814239d608205f72daf6e | Ruby | Zoratoostar/Exercise_9 | /cargo_train.rb | UTF-8 | 170 | 2.625 | 3 | [] | no_license |
class CargoTrain < Train
def hitch_carriage(car)
super(car) if car.is_a?(FreightWagon)
end
def to_s
"#{unique_number}_cargo_#{carriages.count}"
end
end
| true |
4db89e62b28142104ae898e29ade0cd4b4eb8bc1 | Ruby | yoshida-eth0/async_enum | /lib/enumerator/async.rb | UTF-8 | 2,086 | 2.96875 | 3 | [] | no_license | class Enumerator
class Async < Enumerator
class Lockset
def initialize
@semaphores = Hash.new do |locks, key|
locks[key] = Mutex.new
end
end
def lock(key = :__default__, &thread_unsafe_block)
@semaphores[key].synchronize(&thread_unsafe_block)
... | true |
5ab454070399ce5448d45bc7b1048b04361bfc4b | Ruby | loushark/battle | /spec/player_spec.rb | UTF-8 | 316 | 2.625 | 3 | [] | no_license | require 'player'
describe Player do
let(:player) { Player.new("Crazy Teaspoon") }
it 'initializes a name on a new player instance' do
expect(player.name).to eq("Crazy Teaspoon")
end
it 'initializes a deafult hitpoint value on a new player instance' do
expect(player.hitpoints).to eq(60)
end
end
| true |
1c98fa3bf47ba4e84d90afacef8c7f210ee2b28a | Ruby | pychap/Launch_school_101 | /lesson_3/medium_1.rb | UTF-8 | 1,834 | 3.828125 | 4 | [] | no_license | require 'pry'
# stoneage_rock = "The Flintstones Rock!"
# n = 23
# 10.times do
# # n = n += 1
# puts stoneage_rock.center(n += 1)
# end
# 10.times {|num| puts (" " * num) + stoneage_rock}
# statement = "The Flintstones Rock!"
# flintstones_hash = {}
# letters = ('A'..'Z').to_a + ('a'..'z').to_a
# letters.each do ... | true |
fa59bf57da8f5a0febc23ea56fc64b089091c658 | Ruby | DanielVartanov/isp-logs-parser | /lib/traffic_splitter.rb | UTF-8 | 380 | 2.84375 | 3 | [
"MIT"
] | permissive | class TrafficSplitter
def self.split_traffic!(traffic)
hosts = traffic.daily.internal.highest_twenty_hosts +
traffic.nightly.internal.highest_twenty_hosts +
traffic.daily.world.highest_twenty_hosts +
traffic.nightly.world.highest_twenty_hosts
hosts.sort! { |left, right| right.amount_of_traf... | true |
ba8f9b57f2d9dc4e3e1d90ede3382b3029aadce0 | Ruby | slbug/test_img | /app/models/image.rb | UTF-8 | 439 | 2.546875 | 3 | [] | no_license | class Image < ActiveRecord::Base
validates :title, :presence => true, :length => { :minimum => 3 }
validates :url, :presence => true, :length => { :minimum => 10 }
before_save :ensure_uid
private
def ensure_uid
if uid.blank?
allowed_symbols = ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a
... | true |
a154896e0969d98155f169a98c77c8c8131824ea | Ruby | mizuhoiimori/rubybook | /private.rb | UTF-8 | 166 | 3.171875 | 3 | [] | no_license | class Cafe
def staff
makanai
end
private
def makanai
"店員スペシャルメニュー"
end
end
cafe = Cafe.new
puts cafe.staff
puts cafe.makanai | true |
b73ce11b5edde4c06e1f2c904e6608b3ef0a827d | Ruby | RichardCharman/takeaway-challenge | /spec/customer_spec.rb | UTF-8 | 799 | 2.734375 | 3 | [] | no_license | require 'customer'
describe Customer do
it { expect(subject).to respond_to(:show_menu) }
describe '#ordering' do
it 'should take an order for food with 2 arguments' do
expect(subject).to respond_to(:order_item).with(2).argument
end
it { expect(subject).to respond_to(:view_order) }
i... | true |
2e09106b0fa5478524f95e5cd61da1987aba2e62 | Ruby | biancaguzenski/basic-algorithms-and-data-structures | /Others/is_palindrome.rb | UTF-8 | 617 | 3.53125 | 4 | [] | no_license | require "test/unit/assertions"
include Test::Unit::Assertions
def to_char(string)
string = string.downcase.chars
string = string.keep_if {|c| c =~ /[abcdefghijklmnopqrstuvwxyz]/ }.join
is_palindrome(string)
end
def is_palindrome(string)
i = string.size-1
reversed = ""
while i >= 0
rever... | true |
7640ea18727d0ca0f1884b9755e7d45b92e9588a | Ruby | sithobog/seo_tool | /lib/seo/user.rb | UTF-8 | 1,032 | 2.609375 | 3 | [] | no_license | require 'sequel'
require 'bcrypt'
module Seo
class User
attr_accessor :id
DB = Sequel.connect(:adapter => 'postgres', :host => 'localhost',
:database => 'warden_test', :user => 'tester', :password => 'test_password')
def initialize(id, username, password, ip)
@id = id
... | true |
239a53c5500c6187dc4a0644b3d836edb2aafeb8 | Ruby | liyijie/span_report | /app/span_report/logfile/csv_file_operate.rb | UTF-8 | 4,027 | 2.71875 | 3 | [] | no_license | # encoding: utf-8
module SpanReport::Logfile
class CsvReader
###################################################
# 这里传入的files并不是普通的文件名,而是封装的结构
##################################################
def initialize(files, is_temp=false)
@files = files
@is_temp = is_temp
end
def parse(... | true |
710f5273f61dc58c0fb0b13300a706c306711ca9 | Ruby | tsunagun/cheats | /webapi/yahoo/assistsearch.rb | UTF-8 | 1,068 | 2.90625 | 3 | [] | no_license | # -*- coding: utf-8 -*-
# Yahoo Web APIを使って関連検索ワードの取得を行うスクリプト
class Yahoo
# ライブラリ読み込み
require 'pp'
require 'open-uri'
require 'nokogiri'
require 'cgi'
# Yahoo Web APIのアプリケーションIDをyahoo_key.txtから読み込む
load 'yahoo_key.txt'
# APIへのリクエストURLを生成する
def self.make_request_url(query)
base_uri = "http://s... | true |
8c03794f02fdea2f7956f361af6bbdd3e8173987 | Ruby | angelv8a8/SP1Ruby | /Tarea1/Tarea1.rb | UTF-8 | 5,708 | 3.546875 | 4 | [] | no_license | module Tarea1
def atoi(str)
valor = 0
digitos = str.split("")
digitosC = digitos.count
digitosC -= 1
mul = 1
digitosC.downto(0) do | i |
case digitos[i]
when "0"
valor = valor
when "1"
valor += 1 * mul
when "2"
... | true |
085048caa650229e2bfe0a807d3ab35698a28855 | Ruby | eriese/risqueFactr | /app/models/partner.rb | UTF-8 | 1,489 | 2.5625 | 3 | [] | no_license | # == Schema Information
#
# Table name: partners
#
# id :integer not null, primary key
# user_id :integer
# pref_id :integer
# name :string(255)
# frequency :string(255)
# familiarity :integer
# exclusivity :string(255)
# created_at :datetime not null
# updated_at :... | true |
621b7828249eceb670d5c8d180e2d654e0037a90 | Ruby | mattcrowe5/prime-ruby-prework | /prime.rb | UTF-8 | 239 | 3.828125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(number)
if number == 0 || number == 1 || number == -1
return false
end
x = 2
stop = number/x
while x <= stop
if number % x == 0
return false
end
x+=1
stop = number/x
end
return true
end | true |
2c0d7194c26d2c4c281000aff8eda7b9ea5af79a | Ruby | pongsanti/mcotv3 | /lib/util/record_op.rb | UTF-8 | 214 | 3.046875 | 3 | [] | no_license | class RecordOp
def initialize(array, skip)
@array = array
@skip = skip
end
def split
return [], [] if @array.empty?
return @array[0, @skip] || [], @array[@skip, @array.length] || []
end
end | true |
37d71161e4e43ca08ad17d28f7e45a215b8f8a17 | Ruby | SVRourke/pantry_backend | /test/models/user_test.rb | UTF-8 | 1,588 | 2.828125 | 3 | [] | no_license | require "test_helper"
class UserTest < ActiveSupport::TestCase
def setup
@good_user = User.create(name: 'sam', email: 's@s.com', password: 'pass')
@email_user = User.new(name: 'sam', password: 'pass')
@password_user = User.new(name: 'sam', email: 's@s.com')
@lists = [
List.create(name: "list o... | true |
caee6c35cc9c1eb3a1fc4dea0efd0ff4f028b20c | Ruby | denalibalser/compost_cli | /lib/cli.rb | UTF-8 | 2,782 | 3.875 | 4 | [
"MIT"
] | permissive | #our CLI Controller, welcoming the user and dealing with user input
class CLI
def start
list_boroughs
select_boroughs
list_addresses
select_address
collection_day
go_compost
end
def list_boroughs
puts "Welcome! Composting is an easy way to reduce waste. However, urban compost... | true |
0db8d3c1f1065294feba0a034401ca400c4c537e | Ruby | Nitemaeric/coding-lessons | /ruby/1-programming-fundamentals/oop.rb | UTF-8 | 341 | 3.796875 | 4 | [] | no_license | class Me
attr_accessor :age
attr_writer :name
attr_reader :story
def initialize(name = nil, age, story: nil)
@age = age
@name = name
@story = story
end
def name(addon = '')
"#{@name} is #{story} #{addon}"
end
def do_something(&block)
puts "hi"
block.call(20) if block
puts ... | true |
4a17d313d24e22f7c26ce0799eabdffe910b3f08 | Ruby | chrisrobertspdx/flatiron-store-project-v-000 | /app/models/cart.rb | UTF-8 | 930 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Cart < ActiveRecord::Base
belongs_to :user
has_many :line_items
has_many :items, through: :line_items
def add_item(item_id)
existing = self.line_items.detect{|l| l.item_id == item_id.to_i}
if !existing
#self.line_items << Line_Item.new({item_id: item_id, cart_id: ... | true |
6f36509fc3a963edb7333c26db43a0692c48a919 | Ruby | coderjonny/myrubyscripts | /meta.rb | UTF-8 | 3,643 | 3.890625 | 4 | [] | no_license | class Test
def one
@var = 99
two
end
def two
puts @var
end
end
p t = Test.new
p t.one
class Test
puts "In the definition of class Test"
puts "self = #{self}"
puts "Class of self = #{self.class}"
end
class Test
@var = 99
def self.value_of_var
@var
end
end
puts Test.value_of_v... | true |
6098e883352425e7ee7a6c395ed153f919d73f5f | Ruby | AlexanderCleasby/ruby-objects-has-many-lab-online-web-pt-102218 | /lib/artist.rb | UTF-8 | 415 | 3.328125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Artist
attr_accessor :name, :songs
@@library =[]
def initialize(name)
@name=name
@songs=[]
end
def add_song(song)
song.artist=self
@songs.push(song)
@@library.push(song)
end
def add_song_by_name(songname)
newsong = Song.new(songname)
... | true |
1206f4061c920671861c00f632e58775b2dfd8c3 | Ruby | eljefesun/assignment_ruby_warmup | /anagram-testing.rb | UTF-8 | 384 | 3.28125 | 3 | [] | no_license | # # Note: "pears" doesn't appear in the output
# > anagrams("pears")
# # => ["APERS","APRES","ASPER","PARES","PARSE","PRASE","PRESA","RAPES","REAPS","SPARE","SPEAR"]
# > anagrams("zygote")
# #=> []
words = %w[cars scar for four creams scream racs]
anagrams = words.group_by { |word| word.chars.sort }.values
# => [["c... | true |
96015b5ee01cea46a737835e3fc0585d0eb8b6f4 | Ruby | billgloff/data-engineering | /data_normalizer/app/services/import_service.rb | UTF-8 | 837 | 3.046875 | 3 | [] | no_license | require 'csv'
class ImportService
attr_accessor :total_amount_gross
def initialize(file)
@file = file
@total_amount_gross = 0.0
end
def parse
CSV.parse(@file, headers: true, col_sep: "\t").each do |row|
customer_name, item_description, item_price = row[0], row[1], row[2].to_f
purchase_... | true |
7ec192cf66f3d7abff5173a3bb9de72e78202f9f | Ruby | rashmiagar/some_programs | /are_anagrams.rb | UTF-8 | 626 | 3.734375 | 4 | [] | no_license | module AreAnagrams
def self.are_anagrams?(string_a, string_b)
if string_a.length != string_b.length
false
elsif
hash_string_a = Hash.new
string_a.downcase.each_char{|chr|
if hash_string_a.has_key?(chr)
hash_string_a[chr] += 1
else
hash_string_a[chr] = 1
... | true |
5b02f0e0bb7ad0d9f1d630e589c7fb2a6025e6ce | Ruby | LogaJ/CukeSalad | /Examples/Calculator/features/lib/alternative/roles/calculating_web_user.rb | UTF-8 | 2,002 | 2.96875 | 3 | [] | no_license | # To run with this version of the Calculating Individual:
# cucumber --profile alternative
require 'web_calculator'
require 'capybara'
require 'capybara/dsl'
Capybara.app = WebCalculator
Capybara.default_driver = :rack_test
module CalculatingIndividual
# Uses a Browser to perform its tasks
include Capybara
#... | true |
ca7a91c4a3b8001d0981aa19dbd7eda13b3067ba | Ruby | jsiny/101_programming_foundations | /exercises/12_medium_2/ex_04.rb | UTF-8 | 2,134 | 4.34375 | 4 | [] | no_license | def balanced_1?(string)
has_opening = 0
has_closing = 0
string.chars.each do |char|
has_opening += 1 if char == '('
has_closing += 1 if char == ')'
break if has_closing > has_opening
end
has_opening == has_closing
end
p balanced_1?('What (is) this?') == true
p balanced_1?('What is) this?') == f... | true |
fee458ef5658aad7d2329dfd5f2ba43b77cfe3b6 | Ruby | heavenchou/cbwork-bin | /xml2epub/unicode_service.rb | UTF-8 | 453 | 2.875 | 3 | [] | no_license | require 'Unihan2'
class UnicodeService
def initialize
@u2 = Unihan2.new
end
def level1?(code)
return false if code.nil?
# Unicode 3.0 以內 在 mobile 可以正確顯示
v = @u2.ver(code)
raise CbetaError.new(500), "Unihan2.ver 回傳 nil, code: #{code}" if v.nil?
v <= 3
end
def level2?(code)
return ... | true |
5d3d6bc419bc9554c23f0ffdd6e489b3a770b25b | Ruby | mpeiros/mediocritter | /app/models/user.rb | UTF-8 | 947 | 2.625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class User < ActiveRecord::Base
has_many :comments
has_many :searches
has_many :favorites
has_many :favorited_tweets, through: :favorites, source: :tweet
validates_presence_of :email, :username, :password_hash
validates_uniqueness_of :email, :username
def password
@password ||= BCrypt::Password.new(... | true |
86bb9490fcff1198db279cd6dc9a8681b761e3ba | Ruby | evelynnkaplan/matrix_convert_to_zero | /lib/matrix_convert_to_zero.rb | UTF-8 | 1,550 | 4.09375 | 4 | [] | no_license | # Updates the input matrix based on the following rules:
# Assumption/ Given: All numbers in the matrix are 0s or 1s
# If any number is found to be 0, the method updates all the numbers in the
# corresponding row as well as the corresponding column to be 0.
# Time complexity: O(n*m) where n is the length of the matrix... | true |
d7a179bfa72eb98eb17c6415186dbabd9fac9bfa | Ruby | smernick/square_array-001-prework-web | /square_array.rb | UTF-8 | 333 | 4.125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
new_array = [] #defines a new array
array.each do |number| #tells program to iterate throught the array
new_array << (number**2) #tells program to square each number and add it to the back of the new_array
end
return new_array #returns the value of the new_array at the end of the i... | true |
082002b598742027165abc6e74d82ba343c9976f | Ruby | jamensky/programming-univbasics-4-building-nested-hashes-online-web-prework | /intro_to_ruby_hashes_lab.rb | UTF-8 | 1,254 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def base_hash
hash = {:railroads => {} }
end
def monopoly_with_second_tier
hash = {:railroads => {} }
hash[:railroads][:pieces] = 4
return hash
end
def monopoly_with_third_tier
hash = {:railroads => {} }
hash[:railroads][:pieces] = 4
hash[:railroads][:rent_in_dollars] = {:one_piece_owned => 25, :two_... | true |
28b7e5e7e1cdd8cca1c0e1ca33523566024e324c | Ruby | TwiceNo/Patterns | /1/projecteuler40.rb | UTF-8 | 523 | 3.5625 | 4 | [] | no_license | def get_digit(n)
curr_block = 0
curr_upper = 0
prev_upper = 0
while curr_upper < n
prev_upper = curr_upper
curr_upper += 9 * 10 ** curr_block
curr_block += 1
end
offset = n - prev_upper - 1
sequence = 1
while sequence * curr_block < offset
sequence += 1
end
fraction = ""
for i in prev_upper + 1..prev... | true |
8928f80734828e3a26073de7d7dc4b0409c1b73e | Ruby | sgeorgi/pageflow | /app/helpers/pageflow/files_helper.rb | UTF-8 | 597 | 2.78125 | 3 | [
"MIT"
] | permissive | module Pageflow
module FilesHelper
def file_format(file)
file.format.presence || '-'
end
def file_dimensions(file)
if file.width && file.height
"#{file.width} x #{file.height}px"
else
"-"
end
end
def file_duration(file)
if file.duration_in_ms
... | true |
ac61ab9e1d574456ea1d95bec66e67724e509a85 | Ruby | mixophrygian/Text-Adventure | /text_adventure.rb | UTF-8 | 8,294 | 4.03125 | 4 | [] | no_license | #How to play this file! Open the command line, type "irb" then type "load 'text_adventure.rb'" whenever you want to play! The game will quit itself if you win or lose. Load the file again to replay.
class Dungeon
attr_accessor :player
def initialize(player_name)
@player = Player.new(player_name)
@rooms = []... | true |
de5cf0029aa89b1427a56ff9d7c136c7bf2c11d4 | Ruby | Elazp/Online_week1 | /Ejercicio2_Fruta_Solución.rb | UTF-8 | 1,376 | 3.984375 | 4 | [] | no_license | require 'pry'
class ShoppingCart
@@prices_list = {
:apple => 10,
:orange => 5,
:grape => 15,
:banana => 20,
:watermelon => 50
}
def initialize
@cart = Hash.new 0
end
def get_item_price item
@@prices_list[item]
end
def add_item_to_cart item
@cart[item] += 1
end
def show
shopping_c... | true |
8ca76452bae77847d1d42080a02ad539496bafe5 | Ruby | pravsingh/Algorithm-Implementations | /Insertion_Sort/Ruby/mitogh/insertion_sort.rb | UTF-8 | 206 | 3.515625 | 4 | [
"MIT"
] | permissive | def insertion_sort(arr = [])
arr.each_with_index do |element, i|
j = i
while(j > 0 and (prev = arr[j-1]) > element) do
arr[j] = prev
j -= 1
end
arr[j] = element
end
end
| true |
86421313bbbda763dd01bf7efb319fc070c71490 | Ruby | romero-c-raul/ruby-basics | /strings/pr2.rb | UTF-8 | 80 | 2.625 | 3 | [] | no_license | puts 'It\'s now 12 o\'clock.'
# These are the same
puts "It's now 12 o'clock." | true |
86fd793fb46cf29e2bf427d912f0104b45f7d46c | Ruby | sp0gg/katas_and_exercises | /ruby/lib/codility/tape_equilibrium.rb | UTF-8 | 453 | 3.265625 | 3 | [] | no_license | class TapeEquilibrium
def self.solution a
#add all together.
sum = a.reduce :+
puts "sum #{sum}"
left = a[0]
right = sum - left
puts "l #{left} r #{right}"
min_diff = (right-left).abs
puts "mindiff #{min_diff}"
#run p through entire array.
1.upto(a.size-2) do |i|
left... | true |
7afb4ceac6dbcc6255d39137928781efb8ef40f4 | Ruby | duong110397/learn-ruby | /300-children-exercises/array-exercises/ex6.rb | UTF-8 | 172 | 2.75 | 3 | [] | no_license | =begin
Thay the cac gia tri am co trong mang bang 0
=end
arr = 10.times.map{rand(-10..10)}
negativ = []
arr.each{|a| negativ.push(a < 0 ? 0 : a)}
puts negativ.inspect
| true |
2378154ff94fdb670a5309a8d97b329053706307 | Ruby | emmabeynon/rps-challenge | /spec/game_spec.rb | UTF-8 | 3,617 | 2.890625 | 3 | [] | no_license | require 'game'
describe Game do
subject(:game) { described_class.new(player_1, player_2)}
let(:player_1) { double :player_1, weapon: :rock }
let(:player_2) { double :player_2, weapon: :scissors }
describe 'default' do
it 'accepts two players' do
expect(game.player_1).not_to be_nil
expect(game.... | true |
8d720dd72fa3e5d80b152165b2b6cc963602d1a2 | Ruby | charlesduan/photobook | /test/test_layout.rb | UTF-8 | 2,066 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'photobook'
require 'minitest/autorun'
require_relative 'helper'
class TestLayout < Minitest::Unit::TestCase
include TestHelper
def test_new
try_cases(
[ 1, 'h', 1, [ :h ] ],
[ 2, 'hlvpa*', 6, [ :h, :h, :v, :v, :a, :a ] ],
[ 1, 'hhhh', 4, [ :h, :h, :h, :h ] ]
) do |pages, pat, e... | true |
64bcb50deadf3c0e8ced8898130504bc02e4657f | Ruby | jaredonline/Ruby-Prolog-Solutions | /spec/01.Lists/03.kth_element_spec.rb | UTF-8 | 840 | 3.28125 | 3 | [] | no_license | require '01.Lists/03.kth_element'
describe LinkedList do
before do
@list = LinkedList.new(1)
@list.next = LinkedList.new(2)
@list.next.next = LinkedList.new(3)
@list.next.next.next = LinkedList.new(4)
end
context 'OO' do
[1, 2, 3, 4].each_with_index do |element, index|
index += 1 ... | true |
edd9c752ca9790f83ac9e3ce2ca63760f8b340df | Ruby | kalkrishnan/PhatStatsServer | /lib/news/news_factory.rb | UTF-8 | 1,399 | 2.796875 | 3 | [] | no_license | require 'set'
require 'mechanize'
require 'json'
require 'lib/util/word_count'
require_relative 'news'
class NewsFactory
def initialize()
@news = Set.new
@wordCount = WordCount.new
end
def get_top_news
if(!@news.empty?)
json_news
elsif
build_news_repo
end
end
def build... | true |
4f379f53b07533075fd868da1e459168b33d6f30 | Ruby | aijoskobi/class_two | /hr/hr.rb | UTF-8 | 949 | 3.828125 | 4 | [] | no_license | require 'employee'
require 'salaried_employee'
require 'hourly_employee'
class HumanResources
def initialize()
@employee_list = []
@employee_list << HourlyEmployee.new("George", "Monkey", 10)
@employee_list << HourlyEmployee.new("Sally", "Summers", 12)
@employee_list << HourlyEmployee.new("Thomas"... | true |
fbd437980082b1a548971cb6d49e01418d7131b3 | Ruby | La-Pulga/Learn-Ruby-the-Hard-way | /ex19bis.rb | UTF-8 | 418 | 4.28125 | 4 | [] | no_license | def kiss_away(kiss1, kiss2)
puts " I'd like to give you a kiss #{kiss1}"
puts "Me too! #{kiss2}"
puts "We can't do it both"
puts "Yeah we can!\n"
end
puts "-------How many ways are there to do this?-------"
kiss_away(':*', "xxx")
puts "--------------Using variables-------------"
kiss1 = ":*"
kiss2 = "xxx"
kiss_... | true |
897cff2c8ae89145646f73de400c814f9ae6dead | Ruby | helenndoo/collections_practice-v-000 | /collections_practice.rb | UTF-8 | 1,173 | 4.40625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #1 array of integers and returns a copy of array in ascending order
def sort_array_asc(array)
array.sort do |a, b|
a <=> b
end
end
#2 same, but in descending order
def sort_array_desc(array)
array.sort do |b, a|
a <=> b
end
end
#3 ascending order by length
def sort_array_char_count(array)
array.sort_b... | true |
28b7eab9395d29129975907f8c9581c2b373771c | Ruby | kimdcottrell/sombra | /script/arg_guesses/numani_flights/test_flightboard.rb | UTF-8 | 664 | 2.984375 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative '../../../module/data_dump'
DataDump::FLIGHT_LIST.each do |fl|
abbr = fl[:flight_abbr]
num = fl[:flight_num]
time_raw = fl[:time]
time = time_raw.split(":")
time[0].rjust(2,'0')
time[1].rjust(2,'0')
##XOR num by zerofilled time
print (num[0].to_i ^ time[0].to_i).chr... | true |
2fc72f45a48108a34da39f702e7c593e0535c722 | Ruby | atjohnfeng/aa_homework | /W3D5/map.rb | UTF-8 | 750 | 2.984375 | 3 | [] | no_license | class Map
def initialize
@map = []
end
def set(key, value)
map.each_with_index do |defin|
if defin[0] == key
defin[1] == value
return true
end
end
map << [key, value]
self
end
def get(key)
map.... | true |
44778d4ff6e044f898189d54c93498362fa82e11 | Ruby | jasondegraw/AFN2017 | /scripts/buildAFNtest.rb | UTF-8 | 68,222 | 2.65625 | 3 | [
"BSD-2-Clause"
] | permissive | require 'openstudio'
#
#
# +-------------------------------------------------------------+
# | Surface_15 |
# | |
# | |
# | ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.