How does constant lookup and scoping work in Ruby?
Last updated
Ruby checks lexical scope first (
Module.nesting: the enclosing module/class blocks as written), then the ancestor chain, then top-levelObject.class A::Band nestedmodule A; class Bcreate different nesting, so constant lookup can differ.Explicit
Foo::BARskips lexical scope and searches onlyFooand its ancestors.