From: Rick DeNatale Date: 2006-08-31T03:09:39+09:00 Subject: Re: Obtaining a reference to an enclosing class of a nested class On 8/30/06, John Lam wrote: > Here is a nested class definition: > > class A > class B > end > end > > Now, if I have a reference to class B from somewhere: > > def get_reference > A::B > end > > reference_b = get_reference > > How can I get a reference to the enclosing class A? Well in this case, since we know(?) it's a Class or Module: reference_b.name => "A::B" So you can get A's name by string manipulation. > I can't do this by symbol lookup since class A (and B for that matter) > are anonymous. Am I going to have to explicitly create a > back-reference to the enclosing class at the time that I create class > B? Do you really mean that they are anonymous, or that you don't directly know the name? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/