From: Farrel Lifson Date: 2006-10-20T23:23:11+09:00 Subject: Re: break from block On 20/10/06, Michael Studman wrote: > I'm not sure it's the Ruby way (I'm too new to Ruby to judge) but how > about: > > block = lambda{|i| i > 5 ? throw(:enough) : nil} > n = 10 > > catch(:enough) do > n.times &block > end > > > > I've just run into the following problem. Doing this: > > block = lambda{|i| i > 5 ? break : nil} > > n.times &block > > raises a LocalJumpError, I assume because break is not valid from > > within a Proc object. Is there any way to get around this? > > > > Farrel > > > > I tried that but it's a performance killer (nearly 3 times as slow in my informal testing), which I'm trying to optimise for atm. Farrel