From: ara.t.howard@... Date: 2006-10-21T13:41:26+09:00 Subject: Re: break from block On Sat, 21 Oct 2006, Farrel Lifson wrote: > On 20/10/06, Robert Klemme wrote: >> On 20.10.2006 16:37, Farrel Lifson wrote: >> > I'm just trying to optimise some code and I was wondering if doing >> > block = lambda{|i| #processing; if i > 5; break} >> > n.times &block >> > would be any faster than doing it directly. >> >> I do not know a single case where the lambda variant is faster than the >> direct block variant. AFAIK that's because of the conversion that >> occurs. The advantage of the lambda variant is rather that you can >> store the block away and reuse it multiple times. >> >> Regards >> >> robert > >> From my informal benchmarking there's a very slight constant speedup > of about 1s for my program. what version are you running? your original code works fine here: harp:~ > cat a.rb block = lambda{|i| p i; i > 5 ? break : nil} 42.times &block harp:~ > ruby a.rb 0 1 2 3 4 5 6 harp:~ > ruby --version ruby 1.8.4 (2005-12-01) [i686-linux] harp:~ > uname -srm Linux 2.4.21-47.EL i686 harp:~ > cat /etc/redhat-release Red Hat Enterprise Linux WS release 3 (Taroon Update 8) can you show an actual error? -a -- my religion is very simple. my religion is kindness. -- the dalai lama