Created
July 2, 2014 10:19
-
-
Save sebrose/d5e62e1fbed99ed6d5e2 to your computer and use it in GitHub Desktop.
Seb and Duncan's Solution to #spaconf2014
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(start, finish) | |
(finish..start).map {|count| verse count}.reverse.join("\n") | |
end | |
def verse(count) | |
<<-VERSE | |
#{bottle_phrase(count).capitalize} of beer on the wall, #{bottle_phrase count} of beer. | |
#{last_line count} | |
VERSE | |
end | |
def thing(count) | |
if count == 1 then "it" else "one" end | |
end | |
def bottle_phrase(count) | |
if count == 0 then | |
"no more bottles" | |
else | |
"#{count} bottle#{count>1?'s':''}" | |
end | |
end | |
def last_line(count) | |
if count == 0 then | |
"Go to the store and buy some more, 99 bottles of beer on the wall." | |
else | |
"Take #{thing count} down and pass it around, #{bottle_phrase count-1 } of beer on the wall." | |
end | |
end | |
end | |
class PackBottles < Bottles | |
def bottle_phrase count | |
if (count == 6) then | |
"1 six-pack" | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment