Skip to content

Instantly share code, notes, and snippets.

@ajesler
Created July 6, 2019 04:10
Show Gist options
  • Save ajesler/1c9571917bf738afaa796107ce8dee46 to your computer and use it in GitHub Desktop.
Save ajesler/1c9571917bf738afaa796107ce8dee46 to your computer and use it in GitHub Desktop.
class Bottles
def song
verses(99, 0)
end
def verses(from, to)
(to..from).to_a.reverse.map { |n| verse(n) }.join("\n")
end
def verse(number)
if number == 0
return <<~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
end
starting = number
remaining = number - 1
<<~VERSE
#{how_many(starting)} of beer on the wall, #{how_many(starting)} of beer.
Take #{take(remaining)} down and pass it around, #{how_many(remaining)} of beer on the wall.
VERSE
end
def wall_count(number)
end
def instruction(remaining)
end
def take(starting)
starting >= 1 ? "one" : "it"
end
def how_many(number)
case number
when 0
"no more bottles"
when 1
"1 bottle"
else
"#{number} bottles"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment