From: Intransition Date: 2010-08-29T00:05:29+09:00 Subject: Re: Name that method! On Aug 28, 10:56 am, Benoit Daloze wrote: > On 27 August 2010 18:11, Andrew Wagner wrote: > > > I'll vote for parent_namespace. > > On 27 August 2010 23:38, Brian Candler wrote: > > > Module#enclosing_module ?? > > I prefer #enclosing_module since the "namespace" is a Module. > > But how would you implement that? (Except using the name of course) Facets has a Kernel method #constant: def constant(const) const = const.to_s.dup base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class ) const.split(/::/).inject(base){ |mod, name| mod.const_get(name) } end So something like: class Module def enclosing_module constant(name.split('::')[0...-1].join('::') end end I am all ears for improvements to the implementation.