From: Sam Stephenson Date: 2005-01-07T05:08:10+09:00 Subject: Re: Return from a block? On Fri, 7 Jan 2005 00:38:59 +0900, E S wrote: > > For just returning control, throw...catch should work, for returning > a value, Kernel.callcc? But Mr. Buck's solution is certainly shorter. Another way to do it is to rescue LocalJumpError. | def yield_with_return_value(*args) | yield *args | rescue LocalJumpError => e | e.exit_value | end | | def foo(&block) | yield_with_return_value &block | end irb(main):001:0> foo {return "hello"; "this is not returned"} => "hello" irb(main):002:0> foo {"bar"} => "bar" Sam