Skip to content

Instantly share code, notes, and snippets.

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

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