From: MenTaLguY Date: 2005-12-11T04:40:33+09:00 Subject: Re: next, retry, break? --=-OrUO+WqDf/45IioBJ4lX Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, 2005-12-10 at 14:34 +0900, Yukihiro Matsumoto wrote: > | retry: unwinds the stack to the call > | site of the "closest" yielding > | method, calling it again with > | the same arguments > | > | break: unwinds the stack to the call > | site of the "closest" yielding > | method, using the given value > | (or nil) as the method's result > | > |Is that right? >=20 > Right, if the term "closest" means what I thought. I think the word I wanted was "innermost"..? > |If so, what if I want retry or break to unwind further (e.g. because I > |am implementing one iterator in terms of another)? >=20 > I'm not sure what you want. "retry" and "break" jumps out of the > method immediately, so that you can do nothing. But you can use > "ensure" if you really need iteration termination process. I just tried this and it works fine: class Spleen def initialize @arr =3D [1, 2, 3] end def each(&blk) @arr.each(&blk) self end end s =3D Spleen.new k =3D s.each { break 42 } p k #=3D> 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? Otherwise, it seems like it is unwinding to the method call to which the block is originally attached, rather than only to the innermost yielding one. Thank you for your patience, -mental --=-OrUO+WqDf/45IioBJ4lX Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBDmy9ecUNIGiXCc4MRAmMTAKC4i2SvJM2fj25rLwuqagXkuPVSRACgp7gG jQ00BV+g3+tvImfIR45FG4c= =zfiu -----END PGP SIGNATURE----- --=-OrUO+WqDf/45IioBJ4lX--