Pixel <pixel_ / mandrakesoft.com> writes:

> a question that makes me wonder, is what the difference between the 2 following:
> 
> 
> def f(a, b, c, *l)
>    ...
>    ... yield(...) ...
>    ...
> end
> 
> def f(a, b, c, *l, &f)
>    ...
>    ... f.call(...) ...
>    ...
> end

I asked an identical question a while back. I got the following answer 
from Clemens


     AFAIK --if I have understood matz right-- there is only a
     performance penalty by using your second example. That is, as a
     block has to converted into a Proc instance *and*then* passed
     over to the method. A further penalty has to be added for every
     call, as yield'ing a block is faster than call'ing a Proc
     instance!

And then a followup from matz

     I forgot to mention one big difference.  You can't swap self with
     instance_eval() as in [ruby-talk:01010] by using yield.  &block
     is the only way to pass blocks around directly.

     You can use {|x| yield x} trick for most of the cases, but not
     for the instance_eval() case.


Regards


Dave