Created
August 9, 2016 20:43
-
-
Save maxehmookau/dd5e9412cefddf70ba6ebf0abaa8e336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bottles | |
def song | |
verses(99, 0) | |
end | |
def verses(from, to) | |
from.downto(to).map { |i| verse(i) }.join("\n") | |
end | |
def verse(number) | |
"#{quantity(number).capitalize} #{container(number)} of beer on the wall, #{quantity(number)} #{container(number)} of beer. | |
#{action(number)}, #{quantity(succ(number))} #{container(number-1)} of beer on the wall. | |
" | |
end | |
def succ(number) | |
if number == 0 | |
'99' | |
else | |
quantity(number-1) | |
end | |
end | |
def action(number) | |
if number == 0 | |
"Go to the store and buy some more" | |
else | |
"Take #{pronoun(number)} down and pass it around" | |
end | |
end | |
def container(number) | |
if number == 1 | |
'bottle' | |
else | |
'bottles' | |
end | |
end | |
def quantity(number) | |
if number == 0 | |
'no more' | |
else | |
number.to_s | |
end | |
end | |
def pronoun(number) | |
if number == 1 | |
'it' | |
else | |
'one' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment