Last active
August 31, 2016 08:29
-
-
Save nodunayo/1426261cebf55e48d84ed189baacc234 to your computer and use it in GitHub Desktop.
A race to green for the 99 Bottles Kata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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