Skip to content

Instantly share code, notes, and snippets.

@nodunayo
Last active August 31, 2016 08:29
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 nodunayo/1426261cebf55e48d84ed189baacc234 to your computer and use it in GitHub Desktop.
Save nodunayo/1426261cebf55e48d84ed189baacc234 to your computer and use it in GitHub Desktop.
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