I don't know why!!

Discussion in 'Ruby' started by Kyung won Cheon, Aug 8, 2008.

  1. -- test1.rb --

    module M
    module MM
    class C
    end

    class D < MM::C
    end

    class E < MM::C; puts self; end
    end
    end

    # => M::MM::E

    -- test2.rb --

    module M
    module MM
    class C
    end

    class D < MM::C
    end

    #class E < MM::C; puts self; end
    end
    end

    M::MM.module_eval("class E < MM::C; puts self; end")

    # => uninitialized constant M::MM::MM (NameError)

    -- test3.rb --

    module M
    module MM
    class C
    end

    class D < MM::C
    end

    #class E < MM::C; puts self; end
    end
    end

    M::MM.module_eval("class E < C; puts self; end")

    # => M::MM::E

    ###################
    # test2.rb ???
    ###################
     
    Kyung won Cheon, Aug 8, 2008
    #1
    1. Advertisements

  2. Kyung won Cheon

    TPReal Guest

    Well, it's simple, if you say MM::C inside an M::MM's module_eval,
    then it means M::MM::MM::C, and this is undefined. When you say Temp
    \dir from inside C:\Temp, then it means C:\Temp\Temp\dir.
     
    TPReal, Aug 9, 2008
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.