From: Yukihiro Matsumoto Date: 2005-12-11T09:03:28+09:00 Subject: Re: next, retry, break? Hi, In message "Re: next, retry, break?" on Sun, 11 Dec 2005 04:40:33 +0900, MenTaLguY writes: |> Right, if the term "closest" means what I thought. | |I think the word I wanted was "innermost"..? Then, I think you were wrong. |I just tried this and it works fine: | | class Spleen | def initialize | @arr = [1, 2, 3] | end | def each(&blk) | @arr.each(&blk) | self | end | end | | s = Spleen.new | k = s.each { break 42 } | p k #=> 42 | |I'm happy now, except (given my understanding of 'break' behavior above) |I don't understand why it works. Does the call to Array#each with &blk |count as the innermost yield? Or does it cause the yield in Array#each |to be accounted to Spleen#each? "break" breaks the lexically closest one, in this case Spleen.each, not Array#each called within Spleen#s. matz.