Why NameError?

module M1
  class A
  end
end

module M2
  class A
  end
  p A # M2::A
  class B
    p A # M2::A
  end
end

module M3
  include M1
  p A # M1::A
  class B
    p A # NameError (M3::b::A)
  end
end

···

##############
# Help Me^^
##############
--
Posted via http://www.ruby-forum.com/.

it seems that the interpreter search for a 'A' class nested inside B ... I
don't know why..

···

On Mon, Aug 25, 2008 at 8:54 AM, Kyung won Cheon <kdream95@gmerce.co.kr>wrote:

module M1
class A
end
end

module M2
class A
end
p A # M2::A
class B
   p A # M2::A
end
end

module M3
include M1
p A # M1::A
class B
   p A # NameError (M3::b::A)
end
end

##############
# Help Me^^
##############
--
Posted via http://www.ruby-forum.com/\.

--
Go outside! The graphics are amazing!

Hi,

···

In message "Re: Why NameError ??" on Mon, 25 Aug 2008 17:54:00 +0900, Kyung won Cheon <kdream95@gmerce.co.kr> writes:

module M1
class A
end
end

module M2
class A
end
p A # M2::A
class B
   p A # M2::A
end
end

module M3
include M1
p A # M1::A
class B
   p A # NameError (M3::b::A)
end
end

Constant look-up goes self -> surrounding -> super (until Object).
So, from M3, look-up goes M3 -> M1 (A defined here). From M3::B,
B -> M3 -> Object (no A found).

              matz.

constants are not included, only methods
HTH
Robert

···

On Mon, Aug 25, 2008 at 10:54 AM, Kyung won Cheon <kdream95@gmerce.co.kr> wrote:

--
http://ruby-smalltalk.blogspot.com/

There's no one thing that's true. It's all true.
--
Ernest Hemingway