Skip to content

Instantly share code, notes, and snippets.

@savfischer
Created August 9, 2018 14:23
Show Gist options
  • Save savfischer/1b93001824e98759605b14e89da019b0 to your computer and use it in GitHub Desktop.
Save savfischer/1b93001824e98759605b14e89da019b0 to your computer and use it in GitHub Desktop.
class Bottles
def song
verses(99, 0)
end
def verses(start_verse, end_verse)
lyrics = ''
start_verse.downto(end_verse) do |verse_num|
lyrics += verse(verse_num)
if verse_num != end_verse
lyrics += "\n"
end
end
lyrics
end
def verse(bananas)
case bananas
when 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
when 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
when 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
else
<<-VERSE
#{bananas} bottles of beer on the wall, #{bananas} bottles of beer.
Take one down and pass it around, #{bananas - 1} bottles of beer on the wall.
VERSE
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment