On Monday 06 August 2007, Ronald Fischer wrote: > def f(&b) > ... > b.call > ... > end > > def g > ... > yield b > ... > end > > As far I understood the documentation for call and yield, both are > equivalent: > > f { ... } > g { ... } > > Is there a principal reason when to prefer call over yield (or vice > versa), or are these only syntactic variations of the same feature? > > Ronald There is a difference in object allocation. Ruby allocates 1 object for each function call, one more in the case of the &b form (it has to allocate the Proc). Then, yield costs only one object while Proc#call costs two. It can make a difference in case of large iterations, if you're concerned (like I am) about the GC eating your time. Sylvain