Hello --

On Fri, 5 Jul 2002, Tom Sawyer wrote:

> i was wondering what others thought of the idea of having a built in
> reference to the creation-parent for every object? much like the built
> in self reference which points to the object, self_parent would point to
> the object in which self was created. for example:
>
> class S
>   def initialize
>     self_parent.hello
>   end
> end
>
> class P
>   def initialize
>     @s = S.new
>   end
>   def hello
>     p "hello world"
>   end
> end
>
> p = P.new   -->   hello world
>
> in my experience, i have encounter numerous places where i'd like access
> to the parent object, in these cases i've had to pass the parent's self
> to the child on instatiation. i.e. @s = S.new(self), and store that
> within an instance variable of the child.

My first reaction, which I'll go ahead and express although I'm kind
of just thinking out loud (as it were), is that I don't think of this
as a parent-child relationship... though I'm not sure what the right
term would be.  (previous_value_of_self?  It is kind of like creating
a stack of self's.)  Anyway, "self_parent" would look weird because
then you'd probably sometimes call it as self.self_parent :-)  In
general, I think it could lead to encapsulation-breaking things, like
classes prying into instances of their own subclasses.  (Not that
that's currently impossible.)

I'd be interested in seeing an example of the kind of situation where
you've wanted to have this, if you've got a small-ish size case.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav