From: Gennady Bystritksy Date: 2005-01-07T00:47:27+09:00 Subject: Re: Return from a block? E S wrote: > Jamis Buck wrote: > >> On 08:17 Thu 06 Jan , Carlos wrote: >> >>> [Howard Lewis Ship , 2005-01-06 00.11 CET] >>> >>>> Is there a way to return control from the block to the method? >>> >>> >>> next >>> >>> Good luck. >> >> >> >> To elaborate a little more: >> >> a = proc { |i| next i+1 } >> p a.call(5) >> >> Hope that helps. I can understand why 'return' behaves like it does, >> but there are times I wish there was a more intuitive keyword for >> returning a value from a block. 'next' just feels wrong to me. :( > > > For just returning control, throw...catch should work, for returning > a value, Kernel.callcc? But Mr. Buck's solution is certainly shorter. throw...catch can be used for returning a value as well, by the way. A second parameter to "throw" is used as a return value from "catch". Gennady. > > E > >