Skip to content

Instantly share code, notes, and snippets.

@glennpratt
Last active August 29, 2015 13:57
Show Gist options
  • Save glennpratt/9552816 to your computer and use it in GitHub Desktop.
Save glennpratt/9552816 to your computer and use it in GitHub Desktop.
module A
THING = 1
module B
def self.thing
puts THING
end
end
end
module X
THING = 2
end
module X::Y
def self.thing
puts THING
end
end
puts A::B.thing #=> 1
puts X::Y.thing #=> const.rb:16:in `thing': uninitialized constant X::Y::THING (NameError)
module A
THING = 1
module B
def self.thing
puts THING
end
end
module C
def self.bar
puts B.thing
end
end
end
module X
THING = 2
end
module X::Y
def self.thing
puts THING
end
end
module X::Z
def self.bar
puts Y.thing
end
end
puts A::C.bar #=> 1
puts X::Z.bar #=> const.rb:27:in `bar': uninitialized constant X::Z::Y (NameError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment