From: dblack@... Date: 2007-09-11T04:54:22+09:00 Subject: Re: Newbie question: Small blocks Hi -- On Tue, 11 Sep 2007, Felix Windt wrote: >> -----Original Message----- >> From: Dante Regis [mailto:dante.regis@gmail.com] >> Sent: Monday, September 10, 2007 12:23 PM >> To: ruby-talk ML >> Subject: Newbie question: Small blocks >> >> Hello folks, >> >> sorry for this newbie question, but I saw somewhere that >> there is a way to >> make a small block without using pipes " | ". >> >> It was something like [0, 1, 2].each { } , with some char >> inside the >> brackets, like &, but I can't remember it. anyone knows how to use it? >> >> Thanks >> Dante >> > > [1,2].each do |elem| > elem.do_something > end > > Is equivalent to: > > [1,2].each do {|elem| elem.do_something} You don't want the 'do' on the braces version though. (And yes, I've done it occasionally :-) David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)