Skip to content

Instantly share code, notes, and snippets.

@olivierlacan
Created July 22, 2016 07:40
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 olivierlacan/1463243e44a8e3fe67ab30e3549f8aa1 to your computer and use it in GitHub Desktop.
Save olivierlacan/1463243e44a8e3fe67ab30e3549f8aa1 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

@olivierlacan
Copy link
Author

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

@rdp
Copy link

rdp commented Aug 16, 2017

How good is this book would you say?

@joshmn
Copy link

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