"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