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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
d9797e50510030ed8bebffe3993b38a3efd02516 | Ruby | adamgriffis/code-eval-solutions | /longest-lines/test.rb | UTF-8 | 213 | 3.09375 | 3 | [] | no_license | n = -1
lines = []
File.open(ARGV[0]).each_line do |line|
if n < 0
n = line.strip.to_i
else
lines.push(line.strip)
end
end
lines = lines.sort_by{|word| word.length}.reverse
puts lines[0..(n-1)].join("\n") | true |
9424e1bd58dabbfc1d79e7636cae43349df368f3 | Ruby | shoes/shoes-deprecated | /samples/simple-bounce.rb | UTF-8 | 515 | 2.65625 | 3 | [
"MIT"
] | permissive | xspeed, yspeed = 8.4, 6.6
xdir, ydir = 1, 1
Shoes.app do
background "#DFA"
border black, :strokewidth => 6
nostroke
@icon = image "#{DIR}/static/shoes-icon.png", :left => 100, :top => 100 do
alert "You're soooo quick."
end
x, y = self.width / 2, self.height / 2
size = @icon.size
animate(30) do
... | true |
fb4f3f0dcdfd96a31f777e2aa5c10438e9f5ec7b | Ruby | danishnaseem05/CLI-Tic-Tac-Toe-Ruby | /lib/game.rb | UTF-8 | 1,900 | 4.0625 | 4 | [
"MIT"
] | permissive | require 'pry'
class Game
WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[6,4,2]
]
attr_accessor :player_1, :player_2, :board
def initialize(player_1 = Players::Human.new("X"), player_2 = Players::Human.new("O"), board = Board.new)
@play... | true |
3a3595076d1395307571ffdf98921211a239cd44 | Ruby | tihom/fnv_api | /app/crawlers/nokogiri_node.rb | UTF-8 | 3,595 | 3.03125 | 3 | [] | no_license | # This is a generic class that holds the methods to extract data from a html/xml page using Nokogiri
class NokogiriNode
class << self
# Return the text value of an node.
def get(node, path='.')
return unless node
result = node.xpath(path)
result = textf(result.text) if result
result
end
... | true |
bb2f0f5d24beaf71d0d73510e3fb4ea0473f54cb | Ruby | b-studios/doc.js | /test/configs.rb | UTF-8 | 1,397 | 2.890625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # ../data.img#1818355:1
require_relative '../lib/configs.rb'
describe Configs, ".new" do
it "should throw an error, when trying to instantiate" do
begin
Configs.new.should == nil
rescue NoMethodError
# Maybe there is a better way for this
true.should == true
end
end
end
describ... | true |
82710efcfe5ac0bf353aff11b2d4ed190e131ca4 | Ruby | codystair/ruby_small_problems | /Easy_7/10.rb | UTF-8 | 436 | 4.28125 | 4 | [] | no_license | =begin
input: string
output: string
rules:
- returns next to last word in string
- string will contain at least 2 words
examples:
penultimate('last word') == 'last'
penultimate('Launch School is great!') == 'is'
algorithm:
- set words to str split into array of words
- return words at index -2
=end
def penultimate(s... | true |
afc01e8b19425372a98ea2ee308edd2a68ff48c9 | Ruby | jamesottaway/rspec-the | /spec/support/counter.rb | UTF-8 | 94 | 2.78125 | 3 | [
"MIT"
] | permissive | class Counter
def initialize
@counter = 0
end
def next
@counter += 1
end
end
| true |
4d83d53db809e707a3f5a485849b2a1d54c87963 | Ruby | danwagnerco/ps-blocks-course | /song.rb | UTF-8 | 2,169 | 3.875 | 4 | [] | no_license | require_relative "my_enumerable" # <~ part of the bonus exercise
class Song
attr_reader :name, :artist, :duration
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
def play
puts "Playing '#{name}' by #{artist} (#{duration} mins)..."
end
def eac... | true |
5ded0673fa9fc0b0471166a5d9c68224ed7aa4a4 | Ruby | seungeunlee/coderbyte | /LongestWord.rb | UTF-8 | 280 | 3.484375 | 3 | [] | no_license | def LongestWord(sen)
# code goes here
sen = sen.delete "^a-z" "^A-Z" " "
sen = sen.split(" ")
return sen.max{|a,b| a.length <=> b.length}
end
# keep this function call here
# to see how to enter arguments in Ruby scroll down
LongestWord(STDIN.gets)
| true |
16fa650f57dc95d0b997b600892b5236c77fd029 | Ruby | DanielCoffey1/Launch-Academy-Assignments | /day-at-the-park/code.rb | UTF-8 | 616 | 3.5 | 4 | [] | no_license | # Variables
sundae_size = "large"
who = "Diane"
cotton_candy_color = "red"
water_temp = "80 degrees"
emotion = "crazy"
# Phrases
puts "I ordered a " + sundae_size + " " + "sundae, and it was too big!"
puts "The rides were intense, my mother " + who + " " + "couldn't stop
screaming."
puts "They had all sorts of treats ... | true |
0f9cc3701728db5cfeeed8c2b7308f809b3ddf94 | Ruby | sckirk/cs-fun-practice | /practice_2_stretch.rb | UTF-8 | 1,681 | 4.15625 | 4 | [] | no_license | def stretch(an_array)
stretched_array = []
i = 0
an_array.length.times do
split_value = an_array[i] / 2
if an_array[i] % 2 == 0
stretched_array << split_value
else
stretched_array << split_value + 1
end
stretched_array << split_value
i ... | true |
40880b0c6af5a3c21b33f9cb6c89a93770c1db70 | Ruby | kat-star/sinatra-mvc-lab-sf-web-091619 | /models/piglatinizer.rb | UTF-8 | 395 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
attr_reader :text
def initialize
end
def piglatinize(text)
words = text.split
words.map do |word|
if word =~ /^[aeiou]/i
"#{word}way"
else
next_vow = word =~ /[aeiou]/i
consonants = word.slice(0...next_vow)
rest = word.slice(next_vow.... | true |
78bd95ab46f7c4ed7f281a31d4781078c1e8991b | Ruby | ClaudeJardin/Pre-course-Exercises | /Chapter06/exercise06_1.rb | UTF-8 | 116 | 3.078125 | 3 | [] | no_license | puts 'What do you want? '.chomp
thing = gets.chomp
puts 'WHADDAYA MEAN "' + thing.upcase + '"?!? YOU\' RE FIRED!!' | true |
d722cd582ade5d94f8407b50d7541c7b828f0b35 | Ruby | dineshkummarc/address_book-2 | /vendor/plugins/tld/rakelib/tld.rb | UTF-8 | 2,948 | 2.625 | 3 | [
"MIT"
] | permissive | require 'hpricot'
require 'open-uri'
require 'erubis'
class TLD
module Task
def self.to_ruby(tlds, klass, type)
tmpl = File.read(File.join(File.dirname(__FILE__), 'tld.rb.erb'))
eruby = Erubis::Eruby.new(tmpl)
eruby.result(:tlds => tlds, :klass => klass, :type => type)
end
module Upda... | true |
a499ab2746870e759ccba5e29f1242236dad2cf0 | Ruby | JMakkonen/Primes | /P1004.rb | UTF-8 | 3,436 | 3.890625 | 4 | [] | no_license |
# This program defines a number of functions for
# number theory purposes.
# makeFile(x) makes a file of x number of primes.
# ReadPrimes() reads a file of primes
# Factor(x, p) factors the number x using a list of primes in p.
# lcm(x, y) returns the lowest common denominator between x and y
# gcf(x, y) returns the... | true |
1c1fa92f5ccce48d5220a34f6da927ae484b43c8 | Ruby | GSergeevich/ror | /Ruby_basic/lesson7/modules/interface_methods.rb | UTF-8 | 7,113 | 3.28125 | 3 | [] | no_license | module InterfaceMethods
INTERFACE_METHODS = [{ meth: 'create_station!', desc: 'Создать станцию' },
{ meth: 'create_train!', desc: 'Создать поезд' },
{ meth: 'create_route!', desc: 'Создать маршрут' },
{ meth: 'route_change!', desc: 'Добавить или уда... | true |
5c22b1576d02f84ca2abd35dc33f7510371c655e | Ruby | jannesbrunner/ruby-workshop | /0_playground/classes.rb | UTF-8 | 472 | 4.25 | 4 | [] | no_license | class MyThing
attr_reader :name
def initialize(name)
@name = name
end
def say_hello(strangername)
puts "Hello #{strangername}, my name is #{name} !"
end
end
mt = MyThing.new('Jay')
mt.say_hello('Mario')
10.times { |n| puts n }
def some_method
puts 'Hello World'
end
def hello_world(name = 'Worl... | true |
5e4b732dd44322a72c27eec3dac403914011ce65 | Ruby | airhorns/Snake-Bot | /move_bench.rb | UTF-8 | 645 | 2.640625 | 3 | [] | no_license | require './dumb_robot'
require 'benchmark'
player = SnakePlayer.new
player.prepare_for_game
player.x = 252
player.y = 4
n = 100
Benchmark.bm(15) do |x|
x.report "sequential" do
n.times do
player.go(:up, 0)
player.go(:right, 0)
end
end
q = Queue.new
n.times do
q.push [:up, 0]
q.pu... | true |
530c09705ee1edd35c9862eb28d633461b49096f | Ruby | snmgian/ruy | /lib/ruy/conditions/in.rb | UTF-8 | 573 | 3.328125 | 3 | [
"MIT"
] | permissive | module Ruy
module Conditions
# Expects that a context attribute is included in a set of values.
class In < Condition
attr_reader :ary, :attr
# @param ary Expected set of values
# @param attr Context attribute's name
def initialize(ary, *attrs)
super
@ary = ary
... | true |
d8c1595d164b4cf3f1c976aeb55ad48917be163c | Ruby | wildfauve/tracer | /app/models/import.rb | UTF-8 | 1,834 | 2.515625 | 3 | [] | no_license | class Import
def initialize(path)
@path = path
self
end
def parse
json = ActiveSupport::JSON.decode(File.open(@path).read)
# import types
type_map = {}
json["export"]["types"].each {|type| type_map[type["id"]] = Type.import(type).id }
# import reltypes
reltype_map = {}
js... | true |
438387cac6d600e412fd0479a8b83ea38e4b8495 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/7f7a1cc9b92f446488685721856f73d2.rb | UTF-8 | 284 | 3.25 | 3 | [] | no_license | module Hamming
def self.compute(strand1, strand2)
array1 = strand1.split('')
array2 = strand2.split('')
min_size = [array1.size,array2.size].min
counter = 0
(0...min_size).each do |n|
counter += 1 if array1[n] != array2[n]
end
counter
end
end
| true |
48a6e6d882915d191eda0549a90ece81cf84fc16 | Ruby | nikone/stormpath-sdk-ruby | /lib/stormpath-sdk/ext/hash.rb | UTF-8 | 844 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | #
# Copyright 2012 Stormpath, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... | true |
d9952c15676b7fa4802dfea17649a914e419aab9 | Ruby | EnFen/morning-challenges-term1 | /27_maze.rb | UTF-8 | 861 | 3.84375 | 4 | [] | no_license | require 'matrix'
class Maze
def initialize(map)
@map = Matrix[*map]
@position = @map.index(2)
end
def walk(moves)
direction = {N: [-1, 0], S: [1, 0], E: [0, 1], W: [0, -1]}
moves.each do |move|
row_traverse = direction[move.to_sym][0]
col... | true |
87b5aa541377a80cdfb43c3274e1b62f1d6f1d16 | Ruby | erikchau/checkers | /piece.rb | UTF-8 | 3,011 | 3.4375 | 3 | [] | no_license | class Piece
SLIDES = [[-1, 1], [-1, -1]]
KING_SLIDES = [[-1, 1], [-1, -1], [1, -1], [1, 1]]
attr_accessor :color, :king
def initialize(color, position, board)
@color = color
@pos = position
@symbol = {b: "x", w: "o"}
@king = false
@board = board
end
def symbol
@symbol[@color]
... | true |
81ba647a08b8a593a48372612e0606f12b696aa7 | Ruby | Anthonyph/tests-ruby | /lib/04_simon_says.rb | UTF-8 | 1,015 | 3.984375 | 4 | [] | no_license | def echo(string)
p string
end
def shout(string)
p string.upcase
end
def repeat(string="hello", n=2)
repeat_string = []
for n in (1..n)
repeat_string << string
n=n+1
end
#p repeat_string
repeat_string.join(' ')
# sinon plus court repeat_string = Array.new(string, n).join(' ')
end
def start_of_wor... | true |
140aa25a01559aafc1760b8aff59055edf8649df | Ruby | yurii-kurylenko/restoran | /lib/restoran_app.rb | UTF-8 | 2,683 | 2.6875 | 3 | [] | no_license | class RestoranApp
include Restoran::UserInterface
COMMANDS = ['i', 'u', 'd', 'h' ,'q']
def initalize
@exit = false
end
def init!
check_migration
return if @exit
show_startup_info
until @exit
print '> '.chomp
process_command(gets)
end
end
private
def process_comma... | true |
d273cb958a0523ee1ed0c64023dec03b353cee5c | Ruby | ventskus-roman/bodylog | /app/helpers/workout_sets_helper.rb | UTF-8 | 356 | 2.609375 | 3 | [] | no_license | module WorkoutSetsHelper
def time_from_duration(set)
if set.duration && set.duration > 0
format_time_unit(set.hours) + ":" + format_time_unit(set.minutes) + ":" + format_time_unit(set.seconds)
end
end
def format_time_unit(unit)
if unit && unit >= 0
unit_formatted = unit < 10 ? "0" + unit... | true |
6147f00eda873c12bbbad309f97b0e85448a8247 | Ruby | aisatou/rspec-fizzbuzz-prework | /fizzbuzz.rb | UTF-8 | 186 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def fizzbuzz(phrase)
if phrase % 3 == 0 && phrase % 5 == 0
return "FizzBuzz"
end
if phrase % 3 == 0
return "Fizz"
end
if phrase % 5 == 0
return "Buzz"
end
end | true |
d2e200c7bd4714887f80c4fb90877bef0b1996f3 | Ruby | sco-bo/flight-booker | /test/models/airport_test.rb | UTF-8 | 510 | 2.515625 | 3 | [] | no_license | require 'test_helper'
class AirportTest < ActiveSupport::TestCase
def setup
@flight = flights(:two)
@airport = airports(:iad)
@return_flight = flights(:four)
end
test "should be valid" do
assert @airport.valid?
end
test "departing flights should include appropriate flight" do
asser... | true |
97e37c7a318e170e8f6c9e3032a720d4fbab13d2 | Ruby | BlakeBalbirnie/ruby-music-library-cli-v-000 | /lib/music_importer.rb | UTF-8 | 480 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class MusicImporter
attr_accessor :path, :files
def initialize(path)
@path = path
@files = []
end
def files
filenames = Dir.entries(@path)
to_split = []
filenames.each do |file_name|
if file_name.include?(" - ")
to_split << file_name
end
end
@files... | true |
04eae93f55bcae4e7c2d04d9e8f06f65ad43714e | Ruby | Adria1988/ProgrammingExercises | /Ruby/Hashes/UniqueElements.rb | UTF-8 | 258 | 3.890625 | 4 | [] | no_license | #Write a method unique_elements that takes in an array and returns a
#new array where all duplicate elements are removed. Solve this using a hash.
def unique_elements(arr)
hash = Hash.new(0)
arr.each { |element| hash[element] += 1}
hash.keys
end | true |
30ed3bf4467bc80dde6f0ad043dcc24571df9dd5 | Ruby | AvalancheOfFox/guided-module-one-project-assessment-dumbo-web-071519 | /lib/interface.rb | UTF-8 | 8,135 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Interface
attr_accessor :prompt, :user
def initialize
@prompt = TTY::Prompt.new
end
def welcome
system "clear"
puts "🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚🔥📚"
puts " "
... | true |
59c425b1ed47fb8e7000bf145eb2f6f8772f2a7e | Ruby | maratnasyrov/borodach | /app/policies/work_day_policy.rb | UTF-8 | 369 | 2.640625 | 3 | [] | no_license | class WorkDayPolicy
attr_reader :work_day
def initialize(work_day)
@work_day = work_day
end
def smth_records_added?
bool = true
work_day.records.all.each do |record|
if !record.client_added? && !record.closed_record?
bool = true
else
bool = false
b... | true |
c4c6d1b9921395d13bb030d859895d37cb44ba02 | Ruby | arr-dev/cron_when | /lib/cron_when/parser.rb | UTF-8 | 1,246 | 2.65625 | 3 | [] | no_license | module CronWhen
class Parser
# http://www.manpagez.com/man/5/crontab/
# http://guides.rubygems.org/make-your-own-gem/
# http://railscasts.com/episodes/135-making-a-gem
# TODO bin http://ruby-doc.org/stdlib-1.9.3/libdoc/optparse/rdoc/OptionParser.html
# TODO lib parser
# TODO tests
def init... | true |
9baa878a62e9a98e05dbd5b15da12ac14704da96 | Ruby | rasensio1/black-jacky | /black_jack_test.rb | UTF-8 | 936 | 3.15625 | 3 | [] | no_license | require 'minitest/autorun'
require './black_jack'
class BlackJackTest < MiniTest::Test
def test_it_creates_a_card
card = Card.new("Hearts", "3")
assert_equal "Hearts", card.suit
assert_equal "3", card.value
end
def test_it_creates_a_deck
deck = Deck.new
assert_equal 52, deck.cards.count
... | true |
cefe7d3574c45288d94e7ac1feecc26ef8e38b1e | Ruby | rekapap/logdata_parser | /lib/log_data_handler.rb | UTF-8 | 1,040 | 3.046875 | 3 | [] | no_license | # frozen_string_literal: true
# Handles logdata
# Stores it and returns data depending on the query
class LogDataHandler
def initialize
@data = {}
@comparison_proc = proc { |a, b|
a[1] == b[1] ? a[0] <=> b[0] : b[1] <=> a[1]
}
end
# add an uri ip pair to data
#
# parameters: uri,ip
def p... | true |
2876bc06693d13b559526cb4d5246aed349e4a20 | Ruby | doug7410/tealeaf_course_1 | /Lesson2/OOR-I.rb | UTF-8 | 2,201 | 3.890625 | 4 | [] | no_license | class GoodDog
attr_accessor :name, :height, :weight
def initialize(n,h,w)
@name = n
@height = h
@weight = w
end
def speak
"#{name} says arf!"
end
def change_info(n,h,w)
self.name = n
self.height = h
self.weight = w
end
def info
"#{self.name} weighs #{self.weight} and i... | true |
6cbb7005415856b5d7630f278fa65ef3bf92169b | Ruby | thib123/TPJ | /Notes/Ruby/sample_code/ex0139.rb | UTF-8 | 104 | 2.8125 | 3 | [
"MIT"
] | permissive | # Sample code from Programing Ruby, page 65
name = "Fats Waller"
name =~ /a/
name =~ /z/
/a/ =~ name
| true |
24ba65c40ce540d18759809d19509922d6184633 | Ruby | LeandroFigueredo/learning-to-fly | /instance_eval.rb | UTF-8 | 206 | 3.3125 | 3 | [] | no_license | class Hello
end
Hello.instance_eval do
def say_hi
puts "Hiiii from instance"
end
end
Hello.say_hi
p = Hello.new
p.instance_eval do
def say_hi
puts "Hello From instance"
end
end
p.say_hi | true |
aadd1ca9950691b918c24c4208b81acf4746885c | Ruby | jakef203/RB101-ProgrammingFoundations | /Exercises/Easy7/lettercase_counter.rb | UTF-8 | 990 | 4.15625 | 4 | [] | no_license |
UPPERCASE_CHARS = ('A'..'Z').to_a
LOWERCASE_CHARS = ('a'..'z').to_a
def letter_case_count(string)
counts = { lowercase: 0, uppercase: 0, neither: 0 }
string.each_char do |ch|
if LOWERCASE_CHARS.include?(ch)
counts[:lowercase] += 1
elsif UPPERCASE_CHARS.include?(ch)
counts[:uppercase] += 1
... | true |
cdaee2c02778bff032456257af81bde230d86923 | Ruby | Murodjon000/ruby-linter | /lib/check.rb | UTF-8 | 4,330 | 3.078125 | 3 | [] | no_license | require 'colorize'
require 'strscan'
require_relative './file_reader'
class CheckError
attr_reader :checker, :errors
def initialize(file_path)
@checker = FileReader.new(file_path)
@errors = []
@keywords = %w[begin case class def do if module unless]
end
def check_trailing_spaces
@checker.file... | true |
4891359784dcd9c7a037a2d93761e6beb56cc42b | Ruby | KlimekM/phase-0 | /week-4/triangle-side/9-triangle-side/my_solution.rb | UTF-8 | 236 | 2.8125 | 3 | [
"MIT"
] | permissive | # I worked on this challenge with Karen Ball.
# Your Solution Below
def valid_triangle?(a, b, c)
if a == 0 || b == 0 || c == 0
return false
elsif (a+b) < c || (b+c) < a || (a+c) < b
return false
else
return true
end
end | true |
5286fbf086afc4059b04445fe4583bec832cf8fa | Ruby | fathergoose/songs_to_go | /songs2g | UTF-8 | 891 | 3.203125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'highline'
require 'fileutils'
require './lib/copier.rb'
cli = HighLine.new
if ARGV.length > 1
copier = Copier.new(ARGV[0], ARGV[1])
else
src = cli.ask 'From where would you like to copy?'
dst = cli.ask 'To where would you like these files copied?'
copier = Copier.new(src, dst)
en... | true |
dc228375e5bb30fed49ae02394ef82a4d6df60a3 | Ruby | kymmt90/hatenablog | /lib/hatenablog/feed.rb | UTF-8 | 1,657 | 2.921875 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'time'
require 'hatenablog/entry'
module Hatenablog
class Feed
# @dynamic uri, next_uri, title, author_name, updated
attr_reader :uri, :next_uri, :title, :author_name, :updated
# Create a new blog feed from a XML string.
# @param [String] xml XML string representation
... | true |
0102c598356534f7e1f95c8b83e1ad318a6c6d7f | Ruby | galuropek/ruby_ror_education | /task_3/entities/cargo_wagon.rb | UTF-8 | 178 | 2.59375 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'wagon'
class CargoWagon < Wagon
def take_place(units)
@taken_place += units if @place >= (@taken_place + units)
end
end
| true |
58bbf5b70a8d83230625ee072ef85aced56ee69d | Ruby | mgmilton/mythical-creatures | /werewolf.rb | UTF-8 | 735 | 3.046875 | 3 | [] | no_license | require_relative 'werewolf_test'
class Werewolf
attr_reader :name
:location
def initialize (name, location= "London")
@name = name
@location = location
@human = true
@wolf = false
@hungry = false
end
def location
@location
end
def human?
@human
end
def wolf... | true |
6f7aac03cedc779dcba479958e9dee080d54f281 | Ruby | nchambe2/phase-0 | /week-4/calculate-grade/my-solution.rb | UTF-8 | 726 | 4.25 | 4 | [
"MIT"
] | permissive | # Calculate a Grade
=begin
INPUT: Obtain the average
IF average is >= 90 THEN
return a letter grade of A
IF average is >= 80 THEN
return a letter grade of B
IF average is >= 70 THEN
return a letter grade of C
IF average is >= 60 THEN
return a letter grade of D
IF average is < 60 THEN
r... | true |
84921e8ee566163ce8d980fde0bde9b6c97b749f | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/c304ab7783594385919171154aafdd97.rb | UTF-8 | 651 | 3.796875 | 4 | [] | no_license | module Hamming
# variant 1: map zip reduce
def self.compute(a, b)
length = [ a.length, b.length ].min
l = ->(t) { t.bytes.take(length) }
l.(a).zip(l.(b)).map {|a,b|
a == b ? 0 : 1
}.reduce(0, &:+)
end
# variant 2: classical iterative
def self.compute(a, b)
sum = 0
a.bytes.each_w... | true |
1221fcac8de22169552e070b8586453d60568067 | Ruby | debsfong/poker | /spec/deck_spec.rb | UTF-8 | 501 | 3.109375 | 3 | [] | no_license | require 'rspec'
require 'deck'
describe Deck do
let(:stack) { Deck.new }
let(:queen) { double("queen", :value => 12, :suit => "♥") }
describe "initialize" do
it "creates a deck of 52 cards" do
expect(stack.deck_of_cards.length).to eq(52)
end
it "has Queen of Hearts" do
expect(stack.deck_... | true |
0ea1454f1dd4bf281b95a147d2504d56060e8ce1 | Ruby | MMurgor/yield-and-blocks-onl01-seng-pt-030220 | /lib/hello.rb | UTF-8 | 161 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def hello_t (array)
if block_given?
i = 0
while i < array.length
yield (array[i])
i += 1
end
array
else
puts "Hey! No block was given!"
end
end | true |
0decbff51efb12c0fed8e461c6993e1f5163b256 | Ruby | zawawa0722/fleamarket_sample_79c | /spec/models/user_spec.rb | UTF-8 | 6,133 | 2.734375 | 3 | [] | no_license | # require 'rails_helper'
# describe User do
# describe '#create' do
# # 入力されている場合のテスト ▼
# it "全ての項目の入力が存在すれば登録できること" do
# user = build(:user)
# expect(user).to be_valid
# end
# # nul:false, presence: true のテスト ▼
# it "nicknameがない場合は登録できないこと" do
# user = buil... | true |
4ca1902a9fd99bb74f25a50d9a40925e4bfd0282 | Ruby | LauraNgy/Week_02_Day_02_Homework | /specs/test_bear.rb | UTF-8 | 1,008 | 3.109375 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../fish")
require_relative("../river")
require_relative("../bear")
class RiverTest < MiniTest::Test
def setup
@fish1 = Fish.new("nemo")
@fish2 = Fish.new("frank")
@fish3 = Fish.new("ponyo")
@fish_population = [@fish1, @fish2, @fish... | true |
ef4c63f93f62b0207c389c4b62c37f130fb04e81 | Ruby | lazy-night/procon | /006_best_cow_line/ym19851201/cow_sort.rb | UTF-8 | 498 | 3.921875 | 4 | [] | no_license | def sort_array(array, new_array)
if array.length == 1
new_array << array[0]
return
end
index = head_or_tail?(array)
new_array << array[index]
array.delete_at(index)
sort_array(array, new_array)
end
def head_or_tail?(array)
if array.length == 0 || array[0] < array[-1]
return 0
elsif arr... | true |
4f6677facf09e52fffe06398cc14c27c983589af | Ruby | dinks/RubyTests | /test7.rb | UTF-8 | 657 | 3.640625 | 4 | [] | no_license | class LispyEnumerable
include Enumerable
def initialize(tree)
@tree = tree
end
def each
while @tree
car,cdr = @tree
yield car
@tree = cdr
end
end
end
class Lazy
def initialize(&generator)
@generator = generator
end
def method_missing(method, *args, &block)
evaluate... | true |
7c95159bd3b9aab712bd736aeffe7b7527495ec2 | Ruby | jy300x2/launch_school | /lesson_3/easy_3/q3.rb | UTF-8 | 308 | 3.671875 | 4 | [] | no_license | # easy 3 - question 3
# How can we add multiple items to our array? (Dino and Hoppy)
flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
flintstones.insert(-1,"Dino", "Hoppy")
flintstones.push("Dino").push("Hoppy") # launch school solution
flintstones.concat(%w(Dino Hoppy)) # launch school solution
| true |
b53548a4b69618d49aeeb11cd5ac86a437d87490 | Ruby | juliantrueflynn/bootcamp-exercises | /w3d2/reply.rb | UTF-8 | 2,657 | 2.84375 | 3 | [] | no_license | require_relative 'database'
require_relative 'question'
require_relative 'user'
class Reply
def self.all
results = QuestionsDatabase.instance.execute('SELECT * FROM replies')
results.map { |result| Reply.new(result) }
end
def self.find_by_id(id)
data = QuestionsDatabase.instance.execute(<<-SQL, id)
... | true |
61ff827dbc25dbe7c4dc7922069b5bad7d7c18cf | Ruby | drbarq/ruby-objects-has-many-lab-denver-web-career-042219 | /lib/artist.rb | UTF-8 | 731 | 3.3125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Artist is on the many side, will hold the SSOT
require "pry"
class Artist
attr_reader :name, :all
attr_writer
attr_accessor :songs
@@all = []
def self.all
@@all
end
def self.song_count
@@all.select do |artist|
!artist.songs.empty?
end.count
end
def initialize(name)
@name ... | true |
30a5503bf2dc9c71cda65c195ebf2a829fce57ec | Ruby | jadehopepunk/habitat | /lib/record_mixins/has_fixed_currency_money.rb | UTF-8 | 581 | 2.578125 | 3 | [
"MIT"
] | permissive | class ActiveRecord::Base
def self.has_fixed_currency_money(name)
cents_name = "#{name}_cents".to_sym
define_method(name) do
Money.new(send(cents_name), currency) if send(cents_name) && currency
end
define_method("#{name}=") do |value|
if value.respond_to?(:blank?) && value.blank?... | true |
c20553ca4afeb2c541f2234e02c90a1942a36fd4 | Ruby | U-Play/profiles | /spec/profiles/services/find_country_spec.rb | UTF-8 | 679 | 2.75 | 3 | [] | no_license | require 'spec_helper'
describe Services::FindCountry do
it 'returns nil when country is nil' do
clean_country = Services::FindCountry.new(country: nil)
clean_country.find.should be_nil
end
it 'returns the country uppercased when the argument is an alpha2' do
country = 'pt'
clean_country = Servi... | true |
9c4c1c717c97efecf6710a426344c4b8899b5608 | Ruby | justinsaul/snips | /lib/snips.rb | UTF-8 | 952 | 2.515625 | 3 | [
"MIT"
] | permissive | # Snipz
require 'digest/sha1'
module Snips
#AUTHENTICATION
@@user_digest = nil
class << self
def should_auth
@@user_digest
end
def logout
@@user_digest = nil
end
def digest(user, pass)
Digest::SHA1.hexdigest(user.to_s + pass.to_s)
end
def protect(user, pa... | true |
1f625e2e93ffa8adbca6ee3d9279a0188bb2b656 | Ruby | c-hee-rup/my_1st_blockchain | /chleebot.rb | UTF-8 | 1,695 | 2.6875 | 3 | [] | no_license | #encoding: UTF-8
require 'telegram/bot'
require 'httparty'
token = '561672078:AAEb0mZRrNXuLGMlNbebLBx85CoJMwL40gs'
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message.text
when '/start'
bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")... | true |
c163c271221c8a5738bd1ca322c8cbbb5a1109fb | Ruby | Daysip5272/05-caesar-cipher-lab | /lib/caesar.rb | UTF-8 | 720 | 3.4375 | 3 | [] | no_license |
$abc_up = [*?A..?Z]
$abc_low = [*?a..?z]
def caesar_encode(string, offset)
string.split("").map do |character|
if $abc_low.include?(character)
new_character = $abc_low[($abc_low.index(character)+ offset)%26]
elsif $abc_up.include?(character)
new_character = $abc_up[($abc_up.index(character)+ offset)%26]
el... | true |
8e5b816c2c054a1eb30b946a5b29d010324e1c10 | Ruby | streamalbert/learn_rails | /test/models/micropost_test.rb | UTF-8 | 990 | 2.71875 | 3 | [] | no_license | require 'test_helper'
class MicropostTest < ActiveSupport::TestCase
def setup
@user = users(:albert)
# When a new micropost is made in this way, its user_id is automatically set to the right value.
# To get code like @user.microposts.build to work, we need to update the User and Micropost models with ... | true |
c62a43deb1481035a536196cc59d9e90e8acc352 | Ruby | jomontanari/circuits | /spec/boxing_rules_engine_spec.rb | UTF-8 | 619 | 2.59375 | 3 | [] | no_license | module Circuits
describe BoxingRulesEngine do
before do
@rule = double(OneSingleMoveSequenceRule)
@rule.stub(:invalid?)
OneSingleMoveSequenceRule.stub(:new).and_return(@rule)
end
it "returns an array of all numbers between min and max when there are no previous sequences" do
Box... | true |
712969ee1e6be37654537ac671ba8d2b4f327245 | Ruby | beechnut/mbta-alerts | /helpers/tweet_helpers.rb | UTF-8 | 2,703 | 2.671875 | 3 | [] | no_license | module TweetHelpers
# Make MBTA alerts tweetable
@bitly = Bitly.new 'mbtaalerts', ENV['BITLY_TOKEN']
def self.tweetify(alert)
tweet = alert['message'].dup
tweet = hash_transit_line(tweet)
tweet = shorten_locales(tweet)
#tweet = decap_tweet(tweet)
unless alert['link'].nil?
shortlin... | true |
15f3c4476ffcdf99969a3b40792879be5dcee1ac | Ruby | patternblue/ruby_testfirst | /08_book_titles/book.rb | UTF-8 | 516 | 3.546875 | 4 | [] | no_license | class Book
attr_accessor :title
def title=(value)
small_words = ["a", "an", "and", "the", "in", "of"]
the_title = value.split(" ").map(&:downcase).map(&:capitalize)
new_title = Array.new
the_title.each do |word|
if small_words.include? word.downcase
new_title << word.downcase
else
new_title <... | true |
f00413c363e4a33172dad2824df7d92f4b9ce38d | Ruby | threeplanetssoftware/keyed_archive | /lib/keyed_archive.rb | UTF-8 | 847 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'cfpropertylist'
require 'keyed_archive/unpacked_objects'
require 'keyed_archive/version'
class KeyedArchive
attr_accessor :archiver, :objects, :top, :version
#
# Take the same sort of arguments as CFPropertyList
# :file => filename to load
# :data => variable with the data to load directly
def ... | true |
5d2f58745e3acde7fbadb192b6b205ecad6ae892 | Ruby | CrossRef/tinypub | /vendor/bundle/ruby/1.9.1/gems/actionpack-1.4.0/lib/action_controller/support/breakpoint.rb | UTF-8 | 15,737 | 2.875 | 3 | [
"MIT"
] | permissive | # The Breakpoint library provides the convenience of
# being able to inspect and modify state, diagnose
# bugs all via IRB by simply setting breakpoints in
# your applications by the call of a method.
#
# This library was written and is supported by me,
# Florian Gross. I can be reached at flgr@ccan.de
# and enjoy gett... | true |
2126194bff7af402c623e25d8f4500ed2e63fd3a | Ruby | coderoshi/gendict | /scripts/make-images.rb | UTF-8 | 3,086 | 2.9375 | 3 | [] | no_license | #!ruby
#
# Takes YAML for slides from STDIN and generates slide images. Image paths
# are added back to slides and YAML pushed out to standard output
#
# TODO:
# - Only create image if the file doesn't already exist
# - Add command line argument to force overwriting of files even if they exist
# - Make image outp... | true |
1daad7527004f3770328bff376ecbc7dc14ceb3e | Ruby | zliu1020-zz/Ruby-demos | /classex4.rb | UTF-8 | 409 | 4.0625 | 4 | [] | no_license | class GoodDog
# Class variable
@@num_of_dog = 0
def initialize
@@num_of_dog += 1
end
# getter for class variable, this is a Class Method
def self.num_of_dog
@@num_of_dog
end
# override default to_s method
def to_s
"This is a dog!"
end
end
... | true |
25571a73229bd858dc925362f65801f19131625b | Ruby | KalyanAkella/code | /ruby/lib/rank_scale.rb | UTF-8 | 881 | 3.203125 | 3 | [] | no_license | class Rank
Tuple = Struct.new(:user_id, :value)
def initialize
@heap = []
@user_vals = {}
end
def left(i)
1 + (i << 1)
end
def right(i)
2 + (i << 1)
end
def max_heapify(i)
l = left(i)
r = right(i)
if l < @heap.length and @heap[l][:value] > @heap[i][:value]
largest =... | true |
5413962a563e2932b57a58c5d3232dc123046280 | Ruby | sblackstone/project_euler_solutions | /stuff.rb | UTF-8 | 488 | 3.46875 | 3 | [] | no_license | require './primes.rb'
Primes.setup(2_000_000)
def f(x)
s = 1
Primes.primes.each do |p|
break if p > 100
s *= Math.sin(Math::PI*x / 2)
end
return s
end
t = false
a = 0
1_000_000.upto(1_000_100) do |i|
f_i = f(i)
if f_i == -1
if t == false
t = true
a = i
else
a.upto(i) ... | true |
a6071669fbf323ba93d3db5f40ed027a20085093 | Ruby | example-apps/largest_prime | /abraham/lib/factor.rb | UTF-8 | 747 | 3.859375 | 4 | [] | no_license | require 'prime'
class Factor
def initialize(number=nil)
begin
factor_error if number <= 1
@number = number
@largest_factor = Math.sqrt(number).floor
rescue Exception
factor_error
end
end
def self.get_prime(number=nil)
return number if Prime.prime?(number)
gt_factor = ... | true |
ffdddcd03d89be5920fc2841547869a84025fbd9 | Ruby | clonex10100/ttt-with-ai-project-online-web-ft-090919 | /lib/players/human.rb | UTF-8 | 117 | 2.625 | 3 | [] | no_license | class Players::Human < Player
def move(board)
print "Enter Position to Place Piece: "
gets.chomp
end
end
| true |
4d9e84a0f6cb47747f7cf0bb2585c7f613ab2c2e | Ruby | erran/controls.rb | /lib/controls/objects/event.rb | UTF-8 | 863 | 2.640625 | 3 | [
"MIT"
] | permissive | module Controls
# A representation of the Event resource
class Event < Dish::Plate
coerce :createdAt, ->(value) { Time.at(value / 1000) if value }
# Coerces the payload into the appropriate type
#
# @return [Controls::SecurityControlChangeEventPayload,Controls::SiteChangeEventPayload,Controls::Prod... | true |
44ad050b2c049f1992c92b3a329c0c10a9a0de5a | Ruby | chadpalmer2/mod-1-whiteboard-challenge-multiples-of-three-and-five-yale-web-yss-052520 | /lib/multiples.rb | UTF-8 | 452 | 3.453125 | 3 | [] | no_license | def collect_multiples(limit)
(1..(limit - 1)).select {|n| n % 3 == 0 || n % 5 == 0}
end
def sum_multiples(limit)
collect_multiples(limit).sum
end
###
# def sum_multiples(limit)
# true_limit = limit - 1
# multiple_adder(true_limit, 3) + multiple_adder(true_limit, 5) - multiple_adder(true_limit, 15)
# ... | true |
df3d9399462336a14c1fb1a4d128bd194fc18b9e | Ruby | epoch/appleandroids | /04-ruby/ruby_intro/arrays.rb | UTF-8 | 704 | 3.984375 | 4 | [] | no_license | numbers = [1,2,3,4] # im obviously an array
numbers.push 5
numbers << 6 # append / shovel
numbers.pop
numbers.each do |number|
puts "i am number " + number.to_s
end
numbers.each do |number|
puts "i am number #{ number }"
end
# arrays ex
# days_of_the_week = 'monday tuesday wedsnesday thursday friday saturda... | true |
a2d099cc478919124db91f397f1f6eeadfb8eb54 | Ruby | Sinrock/pair-programming-challenges-061520 | /02-ruby-alien-relationships/lib/models/Relationship.rb | UTF-8 | 185 | 3.078125 | 3 | [] | no_license | class Relationship
attr_accessor :aliens
@@all = []
def initialize(alien1, alien2)
@aliens = [alien1, alien2]
@@all << self
end
def self.all
@@all
end
end
| true |
4c21cc2978ce1a3cd60acd26a05c86c64b4cb0b6 | Ruby | aduterte/ruby-oo-practice-relationships-domains-dc-web-030920 | /app/models/guest.rb | UTF-8 | 548 | 3.296875 | 3 | [] | no_license | require 'pry'
class Guest
attr_reader :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def trips
Trip.all.select {|trips| trips.guest == self}
end
def trip_count
trips.count
# binding.pry
end
def self.all
@@... | true |
3d6631b538a4bc887a795092aa5b189a53d8754f | Ruby | luqmanarifin/cp | /Codeforces/377A.rb | UTF-8 | 648 | 2.796875 | 3 | [] | no_license | # export RUBY_THREAD_VM_STACK_SIZE = 200000000
$n, $m, $k = 0, 0, 0
$a = []
def valid?(i, j)
return 0 <= i && i < $n && 0 <= j && j < $m
end
def dfs(x, y)
if !valid?(x, y) || $a[x][y] != '.'
return
end
$a[x][y] = 'L'
dfs x + 1, y
dfs x - 1, y
dfs x, y + 1
dfs x, y - 1
return if $k == 0
$a[x][... | true |
7895fb54f6f3cf43db5788532ac36e1325d5f6fd | Ruby | leriksen/box_app | /app/models/ability.rb | UTF-8 | 1,629 | 2.640625 | 3 | [] | no_license | # roles mappings
class Ability
include CanCan::Ability
def initialize(user=nil)
user ||= User.new # guest user
# Note there are some protections in User model too, namely
# a customer role cannot be combined with anything else.
# This simplifies this table as we do not need to check if
#... | true |
0746617643529c7462865bcf34934886b2903afd | Ruby | krishnau2/icicle-phone-number-to-words | /spec/number_split_spec.rb | UTF-8 | 792 | 3.109375 | 3 | [] | no_license | require './lib/number_split'
describe "NumberSplit" do
it "Should give split combination for the lenght provided" do
combinations = NumberSplit.new(10).combinations
expected_result = [[3, 3, 4], [3, 4, 3], [4, 3, 3], [5, 5], [6, 4], [4, 6], [7, 3], [3, 7], [10]]
expect(combinations).to eq(expected_resul... | true |
f3605b3e3ac3fb496188ed65219fc93a579cd9ef | Ruby | GuillRo/rails-airbnb-clone | /app/controllers/bookings_controller.rb | UTF-8 | 1,557 | 2.53125 | 3 | [] | no_license | class BookingsController < ApplicationController
def index
@bookings = current_user.bookings
end
def new
@flat = Flat.find(params[:flat_id])
@booking = Booking.new
@message = params[:message]
end
def create
@booking = Booking.new(booking_params)
if check_correctdate?(@booking)
... | true |
9143e1cdc41365cd2c3ddd9829c71ed69c425471 | Ruby | malopeznieta/talentum | /CursoRuby/src/_02_metodos/metodos.rb | UTF-8 | 2,067 | 4.28125 | 4 | [] | no_license | #los metodos se crean con la palabra reservada def
def metodo
puts "Hola metodo"
end
metodo
metodo()
#Si damos a un metodo el mismo nombre "sobreescribimos"
def metodo
puts "Hola metodo 2"
end
metodo
def saludar(nombre)
puts "Hola #{nombre}!"
end
saludar "Sara"
saludar("Sara")
saludar ... | true |
8248ec67c1221bfe563c63cfb31cbba61b0d53b5 | Ruby | mkiselyow/store | /lib/tasks/update.rake | UTF-8 | 1,394 | 2.5625 | 3 | [] | no_license | require "bundler"
# require "gem_tasks"
require "curb"
require "oj"
task :default => :spec
BASE_URL = "https://api.vk.com/api.php?oauth=1&"
def vk_method(method:, params: {}, count: 1000, offset: 0)
q = params.map{|k,v| "#{k}=#{v.is_a?(Array) ? v.join(',') : v}"}.join('&')
url = "#{BASE_URL}method=#{method}&v=5.6... | true |
b2c5c03d9c23da09dfba239b0746050b9215a389 | Ruby | Muriel-Salvan/hybrid-platforms-conductor | /lib/hybrid_platforms_conductor/nodes_handler.rb | UTF-8 | 30,336 | 2.5625 | 3 | [
"BSD-3-Clause"
] | permissive | require 'hybrid_platforms_conductor/cmd_runner'
require 'hybrid_platforms_conductor/cmdb'
require 'hybrid_platforms_conductor/logger_helpers'
require 'hybrid_platforms_conductor/parallel_threads'
require 'hybrid_platforms_conductor/platform_handler'
module HybridPlatformsConductor
# API to get information on our in... | true |
a92de3d179502918145c10b8c75dc7dce3185739 | Ruby | jhubbardsf/BaseballCalculator | /lib/baseball.rb | UTF-8 | 7,659 | 3.265625 | 3 | [] | no_license | module Baseball
require 'CSV'
module_function
def batting_stats(path = nil)
if path
file = File.open(path)
content = file.read
content.strip!
end
@stats ||= CSV.parse(content, { headers: true, converters: :integer})
end
def master_stats(path = nil)
if path
file = Fil... | true |
f366538c87b7e4b7ede91862ea84dff4ae2d18d1 | Ruby | remyaub/tdd | /lib/multiple_3_and_5.rb | UTF-8 | 120 | 2.78125 | 3 | [] | no_license | def multiples
total = 0
if
(3...1000).each do |i|
total += i if (i%3 == 0 || i%5 == 0)
puts total
end
multiples
| true |
f74f2ce2a084f7b26776114ff29490384e9174ca | Ruby | JustinData/GA-WDI-Work | /w01/d04/Tom/phil_scope.rb | UTF-8 | 336 | 3.25 | 3 | [] | no_license | philip = {:gend => "m", :nat => "us", :style => "preppy"}
#method takes a person and returns how their workday went
#Just ONE THING is returned from a method. It could be a huge Hash or Array, but it's still only 1 thing
def ga_work(person)
philip = "nice guy, not so preppy"
return how_went
end
phils_day_went =... | true |
48466c2b9c0198d3c3fa9135989b2386dc621ee8 | Ruby | BrantDFaulkner/code_challenges | /tic_tac_toe/app/models/logic.rb | UTF-8 | 2,275 | 3.4375 | 3 | [] | no_license | require_relative "matrix"
class Logic
include Matrix
attr_accessor :marker
attr_reader :matrix
def initialize(matrix, marker)
@matrix = matrix
@marker = marker
end
def first_move
available_spaces.length == 9 ? available_spaces : []
end
def winning_moves(grid=matrix)
available_spaces... | true |
fa4632d9fa19b4f1a72fb37a71ff1eccb816b03d | Ruby | toppsdown/testexamples | /spec/fizz_buzz_doer_spec.rb | UTF-8 | 693 | 2.984375 | 3 | [] | no_license | require 'spec_helper'
describe FizzBuzzDoer do
describe 'when given a number' do
it 'returns list with multiples of 3 set to fizz,' \
'multiples of 5 set to buzz, and multiples of 15 set to fizzbuzz' do
input = 16
output = [
1,2,'fizz',4,'buzz','fizz',7,8,'fizz','buzz',
... | true |
4e05a58b593df040b1ba91f780e0fa38b687d830 | Ruby | rsmith88/gilded-rose-design-project | /lib/generic_item.rb | UTF-8 | 551 | 3.03125 | 3 | [] | no_license | require 'update_methods'
class GenericItem
include UpdateMethods
def initialize(items)
@generic_items = items.select { |i| is_generic?(i) }
end
def update_generic_items
update(@generic_items, -1, -2)
end
def is_generic?(item)
!(item.name == "Aged Brie" ||
item.name == "Aged Chedder" ||
... | true |
e25f5e5db7efda45d230e6ee7297a52656f0f85b | Ruby | nbarnes/popular_purchases | /app/models/purchase.rb | UTF-8 | 2,125 | 2.90625 | 3 | [] | no_license | class Purchase
def self.all_by_user(username, limit = nil)
purchases = nil
unless @@purchases_by_username.has_key? username
purchases = fetch_purchases_by_username(username)
end
purchases = @@purchases_by_username[username]
(purchases = purchases.take limit) if limit
return purchases
... | true |
6494ad8a33dace78464e79a6818155635c9b9101 | Ruby | ay310/cal | /feedback.rb | UTF-8 | 7,341 | 2.765625 | 3 | [] | no_license | #!/usr/bin/ruby
# coding: utf-8
require 'sqlite3'
require 'cgi'
require 'kconv'
print "Content-type: text/html\n\n"
d = Time.now
def to_min(time)
if time == "00:00"
return 0
else
arytime = time.split(':')
return arytime[0].to_i * 60 + arytime[1].to_i
end
end
def to_h(min)
hour = min.to_i / 60
min... | true |
a6904236866b5a752b7232401dddfd911875cbae | Ruby | 0000sir/Doc2PDF-Server | /lib/doc_2_pdf.rb | UTF-8 | 3,224 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'mimemagic/overlay'
module Doc2Pdf
DIR = Rails.root.join('storage')
MIME_EXT = {".doc"=>"application/msword",
".docx"=>"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".dotx"=>"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
... | true |
41cc27f274f6a7db1616e1482e75a2bf42132f32 | Ruby | morag92/understanding_programming | /functions_practice/ruby_functions_practice_solution.rb | UTF-8 | 1,070 | 4.125 | 4 | [] | no_license | def return_10()
return 10
end
def add(num_1, num_2)
return num_1 + num_2
end
def subtract(num_1, num_2)
return num_1 - num_2
end
def multiply(num_1, num_2)
return num_1 * num_2
end
def divide(num_1, num_2)
return num_1 / num_2
end
def length_of_string(str)
return str.length
end
def join_string(string_... | true |
7e9deef595b16b9a2187e0eeeb4692bc104026e4 | Ruby | lawsonhung/classes-and-instances-lab-ruby-dumbo-web-062419-redo | /lib/dog.rb | UTF-8 | 2,027 | 4.21875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # To run this file, cd into this current lib directory/folder. In terminal, run the following command:
# $ ruby dog.rb
# The `Dog` class is defined with the class keyword, followed by the class name and closed with an end.
# Class names begin with capital letters because they are stored in Ruby constants. They should ... | true |
724234fa3d670352659d1a1ba0e0974a91d51b2a | Ruby | skambo/Ruby | /QuestionTime!/planets_test.rb | UTF-8 | 1,106 | 2.65625 | 3 | [] | no_license | require 'minitest/autorun'
require_relative 'planets'
class TestPlanets < Minitest::Test
def test_mercury_maps_correctly_to_size
assert_equal(1, Planets.size("Mercury"))
end
def test_venus_maps_correctly_to_size
assert_equal(2, Planets.size("Venus"))
end
def test_earth_maps_correctly_to_size
a... | true |
e627a7fbca98236404d2ce0cdf7f3161e34fa90c | Ruby | remory08/ruby_curriculum_exercises | /Unit1/07/students_hash.rb | UTF-8 | 1,169 | 3.4375 | 3 | [] | no_license | students = [
{first_name: "Aaron",
last_name: "Gray",
email: "aaron@galvanize.com",
class: "Beginning snark"
},
{first_name: "Sylwester",
last_name: "Kelsey",
email: "sellie@gmail.com",
class: "Ruby Immersive"
},
{first_name: "Timothy",
last_name: "Rama",
email: "tim.rama@gmail... | true |
cda82e295fbe1126fbd342169ef31b11bd736af4 | Ruby | netmute/little_rpg | /lib/enemy.rb | UTF-8 | 284 | 2.84375 | 3 | [] | no_license | class Enemy < Creature
def initialize(name = 'enemy')
super
self.name = name
end
def attacked_by!(player)
newline
puts "* You attack a #{self}!"
Fight.new(player, self, :initiative).start
end
def worth_experience
(max_damage / 2) + level
end
end
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.