Created
August 9, 2016 20:26
-
-
Save maxehmookau/927354c36632cfb239d747490f531ab3 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) | |
case number | |
when 2 | |
"2 bottles of beer on the wall, 2 bottles of beer. | |
Take one down and pass it around, 1 bottle of beer on the wall. | |
" | |
when 1 | |
"1 bottle of beer on the wall, 1 bottle of beer. | |
Take it down and pass it around, no more bottles of beer on the wall. | |
" | |
when 0 | |
"No more bottles of beer on the wall, no more bottles of beer. | |
Go to the store and buy some more, 99 bottles of beer on the wall. | |
" | |
else | |
"#{number} bottles of beer on the wall, #{number} bottles of beer. | |
Take one down and pass it around, #{number-1} bottles of beer on the wall. | |
" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment