Skip to content

Instantly share code, notes, and snippets.

@danvideo
Last active January 7, 2020 03:00
Show Gist options
  • Save danvideo/7244313 to your computer and use it in GitHub Desktop.
Save danvideo/7244313 to your computer and use it in GitHub Desktop.
X Bottles of Beer on the Wall
class BottlesOfBeer
def count_off
puts "How many bottles of beer have you got? "
numbers = gets.chomp.to_i
numbers.downto(1) do |number|
puts "#{number} bottles of beer on the wall, #{number} bottles of beer! Take one down, pass it around, #{number-1} bottles of beer on the wall!"
end
end
bottle = BottlesOfBeer.new
bottle.count_off
end
@chriskuruc
Copy link

Haha this is great! I forked it and made a few changes to get the last two verses correct: https://gist.github.com/chriskuruc/7244582

@danvideo
Copy link
Author

oh cool, didn't realize you commented/added (too bad gists don't send out notifications)

nice, good work chris - heh I was so tired I totally forgot about the end of the song

thanks

@danvideo
Copy link
Author

after trying this I saw a site that rates a bunch of "bottle" versions. I don't completely follow what the highly rated ruby one is doing, but you might want to take a look:
http://www.99-bottles-of-beer.net/language-ruby-1272.html

@daniellermcd
Copy link

Hey guys - I also forked and added stuff. I made a pluralize? method that figures out if bottle should be "bottle" or "bottles" so the string doesn't have to be written out again for 1 bottle of beer. https://gist.github.com/daniellermcd/7252130

@danvideo
Copy link
Author

👍

@octosteve
Copy link

Love it!

@danielleschechter
Copy link

I'm at work right now, so I'll post later. I added an 'elsif' so the '1 bottle of beer line' so now reads: "1 bottle of beer on the wall, 1 bottle of beer! Take one down, pass it around, No more bottles of beer on the wall". I also added if number.zero? on line 14.

@octosteve
Copy link

My try! https://gist.github.com/StevenNunez/7253815 The first one is more readable...

@danvideo
Copy link
Author

ha - great. don't have ruby on my office computer so trying to map it out in my head... definitely need to take a deeper look later

@octosteve
Copy link

The short one was a bit obtuse on purpose. The word you want to look for is lambda

@christianmendoza
Copy link

Late to the party but here's my attempt! https://gist.github.com/christianmendoza/7293928

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