I don't know why!!

  • Thread starter Kyung won Cheon
  • Start date
K

Kyung won Cheon

-- 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 ???
###################
 
T

TPReal

-- 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 ???
###################

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top