From: mhm26@... (matt) Date: 2003-11-22T02:42:16+09:00 Subject: Re: break in yield/block matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1069395225.856100.31032.nullmailer@picachu.netlab.jp>... > Hi, > > In message "Re: break in yield/block" > on 03/11/20, matt writes: > > |I figured that was why break was terminating in #[] - but why not have > |yield act as a `method' in this sense? My guess is that in this > |respect, they should be the same. > > They cannot be same. I would surprise if calling Proc#[] terminates > meow(). But I prepared the way to make meow behave as you expect: I was actually desiring the other way - that break from yield act like break from Proc#[]. > def meow(doyield, &block) > puts "in meow #{doyield}" > if doyield > yield > else > block[] > end > puts "leaving meow" > rescue LocalJumpError > return > end > > b = Proc.new { > puts "in proc" > break > puts "leaving proc" > } > > meow(true, &b) > puts > meow(false, &b) > > Tip: do not use "proc" nor "lambda" when you want objectified Block. > > matz. Is there a reason that Proc#[] is different wrt this depending on whether or not proc/lambda was used, and are there any other differences? I still don't see why the break works the way it does (well, I can understand the reasoning) - but if I break inside a block, then I want that block to terminate, not the method. My current plans are to just do something like this method_invoke(*args) {|*block_args| callcc {|block_break| code - yadda yadda yadda block_break.call if want break / return from block other code... } } Any better ideas?