Constants are viewed first in the lexically covering module (s), and then up the inheritance chain.
module Foo module Bar module Baz class Qux def self.qux_method Baz.baz_method end end def self.baz_method end end end end
This will work because the Baz constant will be first examined in the lexically closing Qux module (class), where it will not be found. The search continues in the lexically closing Baz module, where it is also not found. Therefore, it will look in the lexically closing Bar module, where it will be found and the search will be stopped.
Note: you write in your title:
Ruby, parent / child module access methods
It is not right. These modules are neither parents nor siblings. There is no inheritance. In fact, there is no connection between the modules. There is only a relationship between constants and modules: constants belong to modules.
Module declarations are lexically nested, but the modules themselves are not.
source share