Skip to content

Instantly share code, notes, and snippets.

@assembler assembler/99bottles.rb
Last active Dec 7, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.