From: Ruby-Lang@... Date: 2016-09-04T16:59:50+00:00 Subject: [ruby-core:77148] [Ruby trunk Feature#12317] Name space of a module Issue #12317 has been updated by J��rg W Mittag. I guess the core question is "what is a namespace?" For example, take this Ruby code: ~~~ruby foo = Class.new bar = Class.new baz = Module.new baz.const_set(:Foo, foo) baz.const_set(:Bar, bar) quux = Module.new quux.const_set(:Goobledigook, foo) quux.const_set(:Blahdiblah, bar) baz.send(:remove_const, :Bar) module One; module Two; end end One::Two::Three = quux::Goobledigook One::Two::Three.namespace #=> what should it return? quux::Goobledigook.namespace #=> what should it return? ~~~ Or really just the simple question: ~~~ruby module Foo; module Bar; end end Baz = Foo::Bar Foo::Bar.namespace #=> what should it return? Baz.namespace #=> what should it return? ~~~ ---------------------------------------- Feature #12317: Name space of a module https://bugs.ruby-lang.org/issues/12317#change-60363 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: ---------------------------------------- I want a method to return the name space of a module, something like: ~~~ruby class A; module B; module C end end end A::B::C.namespace => [A, A::B, A::B::C] ~~~ There is `nesting` method that is similar, but that only returns the lexical nesting information. There are also some known hacks for this, converting the module to the string representation using `to_s` or `name`, and then splitting it by `::`. But that easily breaks if the module is anonymous, or is a singleton module. I would like a more robust, core method. -- https://bugs.ruby-lang.org/ Unsubscribe: