---- Original message from Trans  on 8/16/2005 2:36 PM:

>I'm trying to write a little method called Module#modspace, which will
>return the module/class a module/class is defined in. I.e.
>
>  Module X
>    Module Y
>      Module Z
>      end
>    end
>  end
>
>  X::Y::Z.modspace #=> X::Y
>
>
>So I thought, Module.nesting would help do the trick. But I discovered
>the Module.nesting returns the nesting according where it is called in
>the code, nothing more. It is like __LINE__ or __FILE__ in this
>respect. So it seems to me that it would be more appropriate to define
>#nesting in Kernel, not as a class method of Module.
>
>
>  
>
This is mostlikely not the best way to do it, but here is a way to get 
at the information.

class Module
    def lineage
        eval self.ancestors.to_s.sub( /::[^:]$/, "" )
    end
    def modspace
        lineage
    end
end

module X
    module Y
        module Z
        end
    end
end

a = X::Y::Z

p a.modspace
p a.modspace.class