From: Jano Svitok Date: 2007-08-06T20:53:57+09:00 Subject: Re: yield or call? On 8/6/07, Sylvain Joyeux wrote: > 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 > >