Created
July 22, 2016 07:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Keeping further progress in https://github.com/olivierlacan/99bottles
How good is this book would you say?
@rdp it's great.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to note I did this damn thing at 3 AM, because I'm an idiot.