Module.nesting for anonymous modules?

Discussion in 'Ruby' started by James Coglan, Nov 15, 2008.

  1. James Coglan

    James Coglan Guest

    [Note: parts of this message were removed to make it a legal post.]

    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?
     
    James Coglan, Nov 15, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reporter
    Replies:
    3
    Views:
    489
    Mike Schilling
    May 12, 2007
  2. Brian Marick
    Replies:
    7
    Views:
    154
    George Marrows
    Apr 14, 2004
  3. gga
    Replies:
    3
    Views:
    170
    William Morgan
    Feb 19, 2005
  4. Trans
    Replies:
    10
    Views:
    318
    Sean O'Halpin
    Sep 16, 2005
  5. Replies:
    1
    Views:
    234
Loading...

Share This Page