Skip to content

Instantly share code, notes, and snippets.

@djspinmonkey
Created November 29, 2016 00:08
Show Gist options
  • Save djspinmonkey/adf7462e0144e210618ac62128c4bb5c to your computer and use it in GitHub Desktop.
Save djspinmonkey/adf7462e0144e210618ac62128c4bb5c to your computer and use it in GitHub Desktop.
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