What would you call a method that did this:
Foo::Bar::Baz.some_method #=> Foo::Bar
What would you call a method that did this:
Foo::Bar::Baz.some_method #=> Foo::Bar
I'll vote for parent_namespace.
On Fri, Aug 27, 2010 at 12:02 PM, Intransition <transfire@gmail.com> wrote:
What would you call a method that did this:
Foo::Bar::Baz.some_method #=> Foo::Bar
Module#enclosing_module ??
--
Posted via http://www.ruby-forum.com/.
(+1)
On Fri, Aug 27, 2010 at 11:38 PM, Brian Candler <b.candler@pobox.com> wrote:
Module#enclosing_module ??
--
The best way to predict the future is to invent it.
-- Alan Kay
I prefer #enclosing_module since the "namespace" is a Module.
But how would you implement that? (Except using the name of course)
On 27 August 2010 18:11, Andrew Wagner <wagner.andrew@gmail.com> wrote:
I'll vote for parent_namespace.
On 27 August 2010 23:38, Brian Candler <b.candler@pobox.com> wrote:
Module#enclosing_module ??
Foo::Bar could be class. Does that make a difference?
On Aug 27, 5:38 pm, Brian Candler <b.cand...@pobox.com> wrote:
Module#enclosing_module ??
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.
On Aug 28, 10:56 am, Benoit Daloze <erego...@gmail.com> wrote:
On 27 August 2010 18:11, Andrew Wagner <wagner.and...@gmail.com> wrote:
> I'll vote for parent_namespace.
On 27 August 2010 23:38, Brian Candler <b.cand...@pobox.com> 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)
Module#enclosing_module ??
Foo::Bar could be class. Does that make a difference?
But a class is a module, right? Although more exactly one could argue
that an instance of a class is a module. Well for me that was good
enough an approximation.
As a side note I never use class_eval, but always module_eval.
However if some do not see a class as a (kind of a) module the name
would be chosen badly indeed.
Cheers
R.
On Sat, Aug 28, 2010 at 4:59 PM, Intransition <transfire@gmail.com> wrote:
On Aug 27, 5:38 pm, Brian Candler <b.cand...@pobox.com> wrote:
--
The best way to predict the future is to invent it.
-- Alan Kay
Your right it is, and that should suffice, though I recall matz once
talking about the possibility of Module not being a subclass of Class
in Ruby 2.
Just the same, perhaps we can simplify it to just #enclosure ?
On Aug 28, 11:10 am, Robert Dober <robert.do...@gmail.com> wrote:
On Sat, Aug 28, 2010 at 4:59 PM, Intransition <transf...@gmail.com> wrote:
> On Aug 27, 5:38 pm, Brian Candler <b.cand...@pobox.com> wrote:
>> Module#enclosing_module ??> Foo::Bar could be class. Does that make a difference?
But a class is a module, right? Although more exactly one could argue
that an instance of a class is a module. Well for me that was good
enough an approximation.
As a side note I never use class_eval, but always module_eval.
However if some do not see a class as a (kind of a) module the name
would be chosen badly indeed.