On 8/30/06, John Lam <drjflam / gmail.com> 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/