Forum: Ruby Module.nesting for anonymous modules?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James C. (Guest)
on 2008-11-15 12:20
(Received via mailing list)
Hi list,

I'm trying to get a reference to the module that a method is defined in,
problem being that the module is generated dynamically so is not part of
the
AST.

foo = Module.new do
  def m
    Module.nesting
  end
end
=> #<Module:0x28879c4>

c = Class.new { include foo }
=> #<Class:0x287164c>

c.new.m
=> []

Is there any way for a method defined like this to get a reference to
its
containing module?
This topic is locked and can not be replied to.