The Methodphitamine

August 15, 2007

Jay Phillips:

I call it The Methodphitamine. That’s Method ph it amine, a drug for Ruby addicts to code faster.

This allows you to shorten

User.find(:all).map{|x| x.contacts.map{|y| y.last_name.capitalize }}

to

User.find(:all).map &its.contacts.map(&its.last_name.capitalize)

Despite the stupid name, this is definitely a cool hack. I’m not entirely I’d ever actually use this, but I still find it great to find out the language supports stuff like this :-)

About

This page contains a single entry from Stefan Tilkov's Random Stuff posted on August 15, 2007 7:42 AM. The previous post in this blog was Retire the Tenets?. The next post in this blog is Apache Camel routing rules: a DSL?. Many more can be found on the main index page or by looking through the archives.

Comments