Last active
August 29, 2015 14:03
-
-
Save iGEL/729af3bc4f879d636b1c to your computer and use it in GitHub Desktop.
From classes, you can reference toplevel constants even with a namespace! It'll just issue warnings. From modules, you get a NameError
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C = 1 | |
CA = 1 | |
CB = 1 | |
class A | |
CA = 2 | |
class B | |
CB = 3 | |
def c | |
A::B::C | |
end | |
def self.c | |
A::B::C | |
end | |
def ca | |
A::B::CA | |
end | |
def cb | |
A::B::CB | |
end | |
end | |
end | |
b = A::B.new | |
b.c | |
# warning: toplevel constant C referenced by A::B::C | |
# => 1 | |
b.ca | |
# warning: toplevel constant CA referenced by A::B::CA | |
# => 1 | |
# ^ Not 2! | |
b.cb | |
# => 3 | |
A::B.c | |
# warning: toplevel constant C referenced by A::B::C | |
# => 1 | |
module D | |
module E | |
def self.c | |
D::E::C | |
end | |
end | |
end | |
D::E.c | |
# NameError: uninitialized constant D::E::C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment