On Feb 17, 2005, at 12:14 PM, jc wrote:

> How can I do the equivalent of the following?
>
> class Foo
>   class Bar; end
> end
> Foo::Bar.module # => Foo

class Class
   def path
     result = []
     self.name.split(/::/).inject(Object) do |c, n|
       result << c.const_get(n)
       result.last
     end
     return result
   end
end

class Foo
   class Bar
   end
end

p Foo::Bar.path
# => [Foo, Foo::Bar]

I have a hard time understanding why I needed to write that. 
Module.nesting looks close, but doesn't quite cut it (and is a pain 
since you have to call it within a module scope).