Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Seb and Duncan's Solution to #spaconf2014
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
You can’t perform that action at this time.