Module.nesting and module_eval

Discussion in 'Ruby' started by Brian Mitchell, Apr 1, 2005.

  1. I was wondering why Module.nesting is not consitent when called from
    module_eval:

    class Object
    def Object.inherited(sub)
    p sub.module_eval { Module.nesting } # [Object]
    p sub.module_eval("Module.nesting") # [A::B, Object]
    end
    end

    module A
    class B
    p Module.nesting # [A::B, A] OK
    end
    p Module.nesting # [A] OK
    end

    The evals inside of Object.inherited don't return the same thing. I
    think I understand why, classes are objects that can be shared across
    bindings but how would I go about fixing this without touching any of
    "module A ... end"?

    Thanks.

    Brian.
    Brian Mitchell, Apr 1, 2005
    #1
    1. Advertising

  2. Hi,

    In message "Re: Module.nesting and module_eval"
    on Sat, 2 Apr 2005 06:46:26 +0900, Brian Mitchell <> writes:

    |I was wondering why Module.nesting is not consitent when called from
    |module_eval:

    Module.nesting uses compile time information if it's available. The
    nesting information is not available from within eval and its family
    with string, so it tries its best (i.e. [A::B, Object]).

    matz.
    Yukihiro Matsumoto, Apr 2, 2005
    #2
    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. Florian G. Pflug

    module_eval, scope, __FILE__ and __LINE__

    Florian G. Pflug, Feb 17, 2004, in forum: Ruby
    Replies:
    0
    Views:
    128
    Florian G. Pflug
    Feb 17, 2004
  2. gga
    Replies:
    3
    Views:
    157
    William Morgan
    Feb 19, 2005
  3. Trans
    Replies:
    10
    Views:
    299
    Sean O'Halpin
    Sep 16, 2005
  4. Xavier Noria
    Replies:
    2
    Views:
    109
    Xavier Noria
    Nov 16, 2007
  5. Greg Weeks
    Replies:
    3
    Views:
    188
    Greg Weeks
    Nov 19, 2007
Loading...

Share This Page