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 word_part(n) | |
case n | |
when 0 | |
"no more bottles" | |
when 1 | |
"1 bottle" | |
else | |
"#{n} bottles" | |
end | |
end | |
def numbered_pronoun(n) | |
if n == 1 | |
"it" | |
else | |
"one" | |
end | |
end | |
def line_one(n) | |
"#{word_part(n).capitalize} of beer on the wall, #{word_part(n)} of beer.\n" | |
end | |
def line_two(n) | |
if n == 0 | |
"Go to the store and buy some more, 99 bottles of beer on the wall.\n" | |
else | |
"Take #{numbered_pronoun(n)} down and pass it around, #{word_part(n - 1)} of beer on the wall.\n" | |
end | |
end | |
def verse(n) | |
line_one(n) + line_two(n) | |
end | |
def verses(a, b) | |
parts = [] | |
a.downto b do |i| | |
parts << verse(i) | |
end | |
parts.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