Last active
January 16, 2020 21:12
-
-
Save pcreux/fd17c85e153cc962534844719bfe1d96 to your computer and use it in GitHub Desktop.
99bottles in 15 minutes. Feeling a bit dizzy now... 🍻 `git clone --depth=1 --branch=exercise https://github.com/sandimetz/99bottles.git`
This file contains 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 verse(current) | |
<<-VERSE | |
#{bottles(current).capitalize} of beer on the wall, #{bottles(current)} of beer. | |
#{take_one_down(current)}, #{bottles((current - 1) % 100)} of beer on the wall. | |
VERSE | |
end | |
def verses(start, finish) | |
(finish..start).to_a.reverse.map { |number| verse(number) }.join("\n") | |
end | |
def song | |
verses(99, 0) | |
end | |
def bottles(number) | |
case number | |
when 0 | |
"no more bottles" | |
when 1 | |
"1 bottle" | |
else | |
"#{number} bottles" | |
end | |
end | |
def take_one_down(number) | |
case number | |
when 0 | |
"Go to the store and buy some more" | |
when 1 | |
"Take it down and pass it around" | |
else | |
"Take one down and pass it around" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment