Hi --

On Wed, 10 Jan 2007, Jeremy McAnally wrote:

>> 2.b.vi. If a your method has a block parameter, try to use yield rather
>> than accepting it as a variable and calling call on it.
>> --> What is the reasoning behind this?  I'm not trying to criticize (yet
>> ;-), but it seems like The Ruby Way is not doing this.  For example, $_
>> = "hollywood"; scan(/o/); isn't preferred over "hollywood".scan(/o/).
>
> My personal reasoning is that you end up with less confusion as to
> what's going on when simply looking at the code.  You know that yield
> yeilds, but an object may have a call method.  Secondly, when calling
> the method, it's cleaner when calling.  You get:
>
> mymethod { puts "Go go gadget method!" }
>
> as opposed to...
>
> mymethod(lambda {  puts "Go go gadget lambda!" })

It sounds like you guys are talking about two different things.  (I'm
not sure how Daniel's example relates to the yield/call matter.)
Also, Jeremy, I thought what you were talking about was this:

   def meth
     yield
   end

vs.

   def meth(&block)
     block.call
   end

In neither case do you need to create a lambda explicitly; the method
calling syntax would be exactly the same:

   meth { puts "whatever" }


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)