Hi,
this is a resurrection attempt of Michal Rokos class_added RCR
[ruby-talk:38044] in the modified form of a const_added - see for
example Matz response in [ruby-talk:38713]
I’m not going to implement every possible hook. So when somebody
comes with more concrete usage, I will consider this again. It would
be const_added, not class_added.
Implementing this RCR would make it easier to accommodate Tom’s
inner class style programming. For example, by manipulating by
OuterClass#const_added of a Class
class OuterClass
class AnInnerClass
# deeper …
end
# more inner classes
end
would ensure that calling OuterClass::AnInnerClass.new would
automatically generate an instance variable @parent_instance
variable of type OuterClass.
/Christoph
PS. The RCR comes with a natural twin - #const_removed …
Hello –
Hi,
this is a resurrection attempt of Michal Rokos class_added RCR
[ruby-talk:38044] in the modified form of a const_added - see for
example Matz response in [ruby-talk:38713]
I’m not going to implement every possible hook. So when somebody
comes with more concrete usage, I will consider this again. It would
be const_added, not class_added.
Implementing this RCR would make it easier to accommodate Tom’s
inner class style programming. For example, by manipulating by
OuterClass#const_added of a Class
class OuterClass
class AnInnerClass
# deeper …
end
# more inner classes
end
would ensure that calling OuterClass::AnInnerClass.new would
automatically generate an instance variable @parent_instance
variable of type OuterClass.
I’m can’t quite follow this. Wouldn’t const_added get called when a
constant is added to OuterClass?
class OuterClass
def const_added(name,value) # or something
…
end
NEW_CONSTANT = 1 # const_added called here
end
If so, how would this interact with inner classes?
David
···
On Thu, 11 Jul 2002, Christoph wrote:
–
David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav
i can almost see it:
class OuterClass
def OuterClass.const_added(id)
# how to use id
# to add an instance variable
# to this identified object
# of type OuterClass?
…
end
class InnerClass
…
end
def initialize
ic = InnerClass.new # this will triger const_added ?
end
end
yea, i’m a bit confused too.
~transami
···
On Wed, 2002-07-10 at 14:32, David Alan Black wrote:
class OuterClass
def const_added(name,value) # or something
…
end
NEW_CONSTANT = 1 # const_added called here
end
If so, how would this interact with inner classes?
“David Alan Black” wrote
…
class OuterClass
class AnInnerClass
# deeper …
end
# more inner classes
end
would ensure that calling OuterClass::AnInnerClass.new would
automatically generate an instance variable @parent_instance
variable of type OuterClass.
I’m can’t quite follow this. Wouldn’t const_added get called when a
constant is added to OuterClass?
yes
class OuterClass
def const_added(name,value) # or something
…
end
NEW_CONSTANT = 1 # const_added called here
end
If so, how would this interact with inner classes?
depends on how OuterClass#const_added was modified.
Hopefully the following example for using a const_added
scheme, sheets a bit more light on my (probably confused;-)
thinking …
class << OuterClass
def const_added(name,value)
# ignore this if ``value’’ is not a Class
if value.is_a? Class
def value.allocate
res = super
res.instance_eval { @parent_self = Outerclass.new }
return res
end
end
# modify const_added of class value …
# and so on
end
end
/Christoph