Hi,
In message "block , yield and proc?"
on 02/08/06, "Shashank Date" <ADATE / kc.rr.com> writes:
|I am experimenting with code using blocks, yield and proc in Ruby (1.7.2
|mswin32) and discovered three different ways of expressing the same idea:
First, you have to learn several tips:
(a) block parameter |v| means takes everything in a single variable,
which is better described as |*v|.
(b) "call" requires exact number of required argument, whereas
"yield" fills nil for fewer arguments and ignores too much
arguments.
|Q1: Why does the following code :
This is caused by (b).
|Q2: What exactly is the semantic difference between using a bloc parameter
|(with &) and a yield?
This is answered almost by (b). In addition, a block argument
(&block) creates one more object.
|Q3: And what about using Proc?
No difference, except for appearance.
matz.