From: "trans. (T. Onoma)" Date: 2004-11-21T09:28:59+09:00 Subject: Re: Inner Class Relationship On Saturday 20 November 2004 06:10 pm, James Edward Gray II wrote: | On Nov 20, 2004, at 5:01 PM, trans. (T. Onoma) wrote: | > If I understand correctly, try passing self of parent to the the inner | > object | > when it's created. | > | > class Inner | > def initialize( parent ) | > @parent = parent | > end | > end | > | > class Outer | > def initialize | > Inner.new(self) | > end | > end | > | > With any luck, in the future we will have a "caller" method that can | > refer to | > the parent object from Inner#initialize, i.e. without having to | > specifically | > pass self. (Personally I've always thought #object_parent should be | > built-in | > anyway.) | | I don't know what it is about me and not being able to properly convey | what I mean the first time. :D | | What you posted, is more or less what I'm doing. My desire was to find | a way around using a PUBLIC method in the outer class. It's really a | message that only the inner class should be able to send. Making a guess, you're four objects down a hierarchy chain and want to reach up a few levels? That been my experience, but have never found a better solution. You still have to have some _reference_ to that outer object --that's the problem. You might try something like this if you can determine reasonable keys. class Outer def initialize @@gimme[:akey] = self end def self.gimme(key) @@gimme[key] end end Also you could do what what you're doing now but inversely. Something like: class Outer o = Inner.new (class << o; self; end).send(:define_method, :parent){ self } end T.