Last active
December 7, 2016 09:49
-
-
Save assembler/fecc36db60350f26c0a9d8ace90d1089 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(from_bottle_count, to_bottle_count) | |
from_bottle_count | |
.downto(to_bottle_count) | |
.map { |c| verse(c) } | |
.join("\n") | |
end | |
def verse(bottle_count) | |
line1 = "#{pluralize(bottle_count).capitalize} of beer on the wall, #{pluralize bottle_count} of beer." | |
line2 = case bottle_count | |
when 0 then "Go to the store and buy some more, 99 bottles of beer on the wall." | |
when 1 then "Take it down and pass it around, no more bottles of beer on the wall." | |
else "Take one down and pass it around, #{pluralize bottle_count - 1} of beer on the wall." | |
end | |
"#{line1}\n#{line2}\n" | |
end | |
private | |
def pluralize(bottle_count) | |
case bottle_count | |
when 0 then "no more bottles" | |
when 1 then "1 bottle" | |
else "#{bottle_count} bottles" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment