I would worry about obstructing the GC.
-----Oprindelig meddelelse-----
···
Fra: Tom Sawyer [mailto:transami@transami.net]
Sendt: to 04-07-2002 19:20
Til: ruby-talk ML
Cc:
Emne: self_parent
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.
since it's only a reference, i would think there would be little
overhead to keeping this reference available automatically. in fact, i
imagine the information is already there, just without a way to get to
it. i think numerous programs could make use of such a feature.
what'ya think?
~transami
------------------------------------------------------------
"They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety."
-- Benjamin Franklin
------------------------------------------------------------