From: Christian Leskowsky Date: 2005-11-14T02:03:50+09:00 Subject: Re: Execute block in context of yielding method's module ------=_Part_7691_12077289.1131901426913 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks for the reply guys! This last one looks much better to my eyes, but I'm still having problems. I like the code I write to tell as much to the reader about what's going on as it possibly can-right there (without having to jump to other methods, in other classes, in other modules). I think I'd probably have a hard time figuring out what: C.new do |c| c.x =3D 1 end did, without having: class C attr_accessor :x def initialize yield self end end being directly above it (on the same screen somewhere). It might take a few more keystrokes to write: c =3D C.new c.x =3D 1 in general, but to me, it's much more readable. The other thing that bugs me (and it's probably just an unfortunate example), is that it looks like I'm passing out a reference to myself, before I'm completely initialized. ugh! Strange stuff... I think I'll just stay about as for away from it as I can :). -- - 'There was an owl lived in an oak. The more he heard, the less he spoke. The less he spoke, the more he heard.' Christian Leskowsky christian.leskowsky@gmail.com On 11/13/05, David A. Black wrote: > > Hi -- > > On Sun, 13 Nov 2005, Christian Leskowsky wrote: > > > Hey guys, > > > > I'm very new to ruby. > > > > This is some freaky shite! Could somebody give me a use case as to when > I'd > > want to do something like this? > > Somewhat rarely :-) I actually prefer to know what 'self' is when I > write a block. I'm uneasy with the idea that here: > > some_method { another_method } > > I can't tell by looking who's receiving the another_method message. > > A more common idiom is to provide the object so that you can see > exactly who's doing what: > > class C > attr_accessor :x > def initialize > yield self > end > end > > C.new do |c| > c.x =3D 1 > end > > and things like that. > > > David > > -- > David A. Black > dblack@wobblini.net > > ------=_Part_7691_12077289.1131901426913--