Skip to content

Instantly share code, notes, and snippets.

@nodunayo
Last active Aug 31, 2016
Embed
What would you like to do?
A race to green for the 99 Bottles Kata
class Bottles
def verse(number)
if number == 2
<<-VERSE
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.
VERSE
elsif number == 1
<<-VERSE
1 bottle of beer on the wall, 1 bottle of beer.
Take it down and pass it around, no more bottles of beer on the wall.
VERSE
elsif number == 0
<<-VERSE
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
VERSE
else
<<-VERSE
#{number} bottles of beer on the wall, #{number} bottles of beer.
Take one down and pass it around, #{number - 1} bottles of beer on the wall.
VERSE
end
end
def verses(from_verse, to_verse)
verses = ""
(to_verse..from_verse).each do |verse_number|
verses.insert(0,"#{verse(verse_number)}\n")
end
verses
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment