Created
August 19, 2014 17:51
-
-
Save hackjoy/a5870cc7f4801227ad20 to your computer and use it in GitHub Desktop.
bottles_lib_7.rb
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 verse(num) | |
case num | |
when 0 | |
"No more bottles of beer on the wall, no more bottles of beer.\n" + | |
"Go to the store and buy some more, 99 bottles of beer on the wall.\n" | |
when 1 | |
"1 bottle of beer on the wall, 1 bottle of beer.\n" + | |
"Take it down and pass it around, no more bottles of beer on the wall.\n" | |
when 2 | |
"2 bottles of beer on the wall, 2 bottles of beer.\n" + | |
"Take one down and pass it around, 1 bottle of beer on the wall.\n" | |
when 89 | |
"89 bottles of beer on the wall, 89 bottles of beer.\n" + | |
"Take one down and pass it around, 88 bottles of beer on the wall.\n" | |
when 98 | |
"98 bottles of beer on the wall, 98 bottles of beer.\n" + | |
"Take one down and pass it around, 97 bottles of beer on the wall.\n" | |
when 99 | |
"99 bottles of beer on the wall, 99 bottles of beer.\n" + | |
"Take one down and pass it around, 98 bottles of beer on the wall.\n" | |
end | |
end | |
def verses(upper_bound, lower_bound) | |
upper_bound | |
.downto(lower_bound) | |
.collect {|verse_number| verse(verse_number)} | |
.join("\n") | |
end | |
def song | |
verses(99,0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment