Get namespaces

Hi

Is there a method to get all namespaces (like Math::, which don't have to be loaded necessarily)

Opti

Hi

Is there a method to get all namespaces (like Math::, which don't have
to be loaded necessarily)

Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Perhaps something like:

Object.constants.map{|c| eval c.to_s }.select{|o| o.is_a?(Module) && !
o.is_a?(Class) }

Would be a start.

-Rob

···

On Fri, Nov 4, 2016 at 10:52 AM Die Optimisten <inform@die-optimisten.net> wrote:

which don't have to be loaded necessarily

What do you mean there? And what is the program supposed to have loaded at
that point?

···

On Fri, Nov 4, 2016 at 3:52 PM, Die Optimisten <inform@die-optimisten.net> wrote:

I think that requirement is impossible to fulfill since with
autoloading and other features you cannot know what files can be
loaded potentially to determine all possible namespaces.

You can determine all currently known namespaces though:

puts ObjectSpace.each_object(Module).to_a
puts ObjectSpace.each_object(Module).sort_by {|x| x.name || ""}

Kind regards

robert

···

On Fri, Nov 4, 2016 at 4:15 PM, Xavier Noria <fxn@hashref.com> wrote:

On Fri, Nov 4, 2016 at 3:52 PM, Die Optimisten <inform@die-optimisten.net> > wrote:

which don't have to be loaded necessarily

What do you mean there? And what is the program supposed to have loaded at
that point?

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Thank you Robert!
What Modul is 'fatal ' (lowercase??)

Opti

Hi
How can I select the main-class, if I have more Modules using the same name for a class?

e.g.:
String

Neither "abc".A::b::String.to_s nor
         "abc".Main::String.to_s is working!

Thank you
Opti

···

A::b::String

Maybe I have missed some emails... how do you know the OP is talking about
autoloading?

With the original email, I don't really know which is the situation.

···

On Friday, 4 November 2016, Robert Klemme <shortcutter@googlemail.com> wrote:

On Fri, Nov 4, 2016 at 4:15 PM, Xavier Noria <fxn@hashref.com > <javascript:;>> wrote:
> On Fri, Nov 4, 2016 at 3:52 PM, Die Optimisten < > inform@die-optimisten.net <javascript:;>> > > wrote:
>
>> which don't have to be loaded necessarily
>
> What do you mean there? And what is the program supposed to have loaded
at
> that point?

I think that requirement is impossible to fulfill since with
autoloading and other features you cannot know what files can be
loaded potentially to determine all possible namespaces.

--
Sent from Gmail Mobile

>
>> which don't have to be loaded necessarily
>
> What do you mean there? And what is the program supposed to have loaded
> at that point?

I think that requirement is impossible to fulfill since with
autoloading and other features you cannot know what files can be
loaded potentially to determine all possible namespaces.

Maybe I have missed some emails... how do you know the OP is talking about
autoloading?

He was not explicitly. But please look at his sentence I quoted from
the initial question. He is obviously asking for a general mechanism
to obtain all namespaces and explicitly states that he wants also
namespaces which have not been loaded. Autoloading is one mechanism
which might lead to files loaded at an arbitrary point of time.
require is another one and eval yet another one.

With the original email, I don't really know which is the situation.

There are arbitrary ways that classes and modules can come into
existence at an arbitrary point in time. You could also mention eval.
Thing is, it is fairly easy to get the _currently known_ set of
classes and modules but there is no way to look into the future
because of Ruby's dynamic nature.

Kind regards

robert

···

On Sat, Nov 5, 2016 at 12:32 AM, Xavier Noria <fxn@hashref.com> wrote:

On Friday, 4 November 2016, Robert Klemme <shortcutter@googlemail.com> > wrote:

On Fri, Nov 4, 2016 at 4:15 PM, Xavier Noria <fxn@hashref.com> wrote:
> On Fri, Nov 4, 2016 at 3:52 PM, Die Optimisten >> > <inform@die-optimisten.net> >> > wrote:

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/