Skip to content

Instantly share code, notes, and snippets.

@assembler
Last active December 7, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assembler/fecc36db60350f26c0a9d8ace90d1089 to your computer and use it in GitHub Desktop.
Save assembler/fecc36db60350f26c0a9d8ace90d1089 to your computer and use it in GitHub Desktop.
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