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::A)
end
end
##############
Help Me^^
##############
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::A)
end
end
##############
##############
it seems that the interpreter search for a ‘A’ class nested inside B …
I
don’t know why…
Hi,
In message “Re: Why NameError ??”
on Mon, 25 Aug 2008 17:54:00 +0900, Kyung won Cheon
[email protected] 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::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.
On Mon, Aug 25, 2008 at 10:54 AM, Kyung won Cheon
[email protected] wrote:
constants are not included, only methods
HTH
Robert
–
http://ruby-smalltalk.blogspot.com/
There’s no one thing that’s true. It’s all true.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs