99 Bottles of Beer in Ruby
Open up your JIRB (or IRB for that matter) and run this:
$i=99
def b()"#{$i>0?$i: 'No'} bottle#{'s'if$i!=1} of beer"end$i.times{w=" on the wall";puts b()+w+", #{b}.
Take one down, pass it around,
#{$i-=1;b+w}.
"}
If you're a developer coming from the Java language, the above example represents unprecedented compactness (compared to the code needed to perform the same task in Java).
Mmmmmmnnhhh - the syntax. I like it!
Actually I don't remember where I found the above example a month ago or so. If you're the original author, I hope you'll forgive me ;)
It's easy to install Ruby/JRuby. But if you don't wan't to waste that 5 minutes of your life, you can run ruby code directly from within this site - clever!:
http://tryruby.hobix.com/
UPDATE: Found this site, showing examples of the above in 1103 different languages and variations - nice place to spend some hours ;):
http://99-bottles-of-beer.net/
technorati tags:ruby, bottles of beer on the wall, jruby, jirb, irb, try ruby
No comments:
Post a Comment
Please comment! I look forward into hearing your comments/oppinions.