Skip to content

Instantly share code, notes, and snippets.

@pcreux
Last active January 16, 2020 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pcreux/fd17c85e153cc962534844719bfe1d96 to your computer and use it in GitHub Desktop.
Save pcreux/fd17c85e153cc962534844719bfe1d96 to your computer and use it in GitHub Desktop.
99bottles in 15 minutes. Feeling a bit dizzy now... 🍻 `git clone --depth=1 --branch=exercise https://github.com/sandimetz/99bottles.git`
class Bottles
def verse(current)
<<-VERSE
#{bottles(current).capitalize} of beer on the wall, #{bottles(current)} of beer.
#{take_one_down(current)}, #{bottles((current - 1) % 100)} of beer on the wall.
VERSE
end
def verses(start, finish)
(finish..start).to_a.reverse.map { |number| verse(number) }.join("\n")
end
def song
verses(99, 0)
end
def bottles(number)
case number
when 0
"no more bottles"
when 1
"1 bottle"
else
"#{number} bottles"
end
end
def take_one_down(number)
case number
when 0
"Go to the store and buy some more"
when 1
"Take it down and pass it around"
else
"Take one down and pass it around"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment