Hi --

On Mon, 6 Dec 2004, Florian Gross wrote:

> Robert Klemme wrote:
> 
> >> Thoughts?  When do you use the 'yield' statement in code?
> > More generally when you don't need direct access to the block given and 
> > when you don't need to forward it to another method call.  I think yield 
> > is faster than the block form also.
> 
> But note that you can also forward blocks without using the &block syntax:
> 
> irb(main):022:0> def five_times
> irb(main):023:1>   5.times { |index| yield index }
> irb(main):024:1> end
> => nil
> irb(main):025:0> five_times { |i| puts "Hello ##{i}" }
> Hello #0
> Hello #1
> Hello #2
> Hello #3
> Hello #4
> 
> I'd expect this to be slower than the &block syntax, but I have not 
> benchmarked it. Maybe the &block syntax is also less clutter to look at 
> and thus easier to understand.

Wouldn't the &block form be more clutter?  Well, not that it's so
much clutter in either case, but I think it would be slightly wordier
(def five_time(&block) etc.)


David

-- 
David A. Black
dblack / wobblini.net