Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My first ever 99 Bottles of OOP exercism torture run in 30 minutes and 34 seconds because I'm a dirty cheater. Just look at this ugly little thing. Go get Sandi and Katrina's book if you don't know what this is about: 99bottlesbook.com
class Bottles
def verse(number)
<<-STRING
#{pluralize_bottle(number, true)} of beer on the wall, #{pluralize_bottle(number)} of beer.
#{ending(number)}
STRING
end
def verses(first, second)
range = (second..first).to_a.reverse
range.map do |r|
verse(r)
end.join("\n")
end
def song
verses(99,0)
end
def pluralize_bottle(count, capital = false)
if count >= 2
"#{count} bottles"
elsif count == 1
"#{count} bottle"
else
"#{capital ? "N" : "n"}o more bottles"
end
end
def article(count)
if count > 1
"one"
else
"it"
end
end
def ending(count)
if count == 0
"Go to the store and buy some more, 99 bottles of beer on the wall."
else
"Take #{article(count)} down and pass it around, #{pluralize_bottle(count - 1)} of beer on the wall."
end
end
end
@olivierlacan

This comment has been minimized.

Copy link
Owner Author

@olivierlacan olivierlacan commented Jul 22, 2016

I'd like to note I did this damn thing at 3 AM, because I'm an idiot.

@olivierlacan

This comment has been minimized.

Copy link
Owner Author

@olivierlacan olivierlacan commented Jul 22, 2016

Keeping further progress in https://github.com/olivierlacan/99bottles

@rdp

This comment has been minimized.

Copy link

@rdp rdp commented Aug 16, 2017

How good is this book would you say?

@joshmn

This comment has been minimized.

Copy link

@joshmn joshmn commented Aug 17, 2017

@rdp it's great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment