Constant lookup in Ruby can happen lexically or through the ancestry tree of the receiver(a class or module). You can identify which lookup rules are being applied by the context you're in or by the syntax being used to define a class or module.
A class body that is defined as class A::B::C; …; end
will lookup
constants through the ancestry tree when a constant is evaluated in
its class body. Anytime you see A::B::C
being used as syntax to
define a class or lookup the value of a constant the ancestry tree
is being used for the lookup.