In message "[ruby-talk:01008] Blocks, Procs, and iterators"
on 99/12/30, Dave Thomas <Dave / thomases.com> writes:
|Is there a difference between
|
| def fred
| yield 1
| yield 2
| end
|
|and
|
| def fred(&block)
| block.call(1)
| block.call(2)
| end
Almost same. The differences are
(1) &block create a Proc object, yield does not; thus yield version
is bit faster.
(2) With &block, you can check the number of parameters (variables
surrounded by | |) in block with Proc#arity method. There's no
such way for a unobjectified block.
(3) It's much easier to pass a block to another method with &block.
Hope this helps.
matz.