Created
November 29, 2016 00:08
-
-
Save djspinmonkey/adf7462e0144e210618ac62128c4bb5c to your computer and use it in GitHub Desktop.
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 song | |
verses(99, 0) | |
end | |
def verses(first, last) | |
first.downto(last).map { |n| verse(n) }.join("\n") | |
end | |
def verse(n) | |
"#{bottles(n, :capitalize)} of beer on the wall, #{bottles(n)} of beer.\n" + | |
case n | |
when 0; then "Go to the store and buy some more, 99 bottles of beer on the wall.\n" | |
when 1; then "Take it down and pass it around, no more bottles of beer on the wall.\n" | |
else "Take one down and pass it around, #{bottles(n-1)} of beer on the wall.\n" | |
end | |
end | |
def bottles(n, capitalize = false) | |
case(n) | |
when 0; then (capitalize ? "No more bottles" : "no more bottles") | |
when 1; then "1 bottle" | |
else "#{n} bottles" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment