Suppose an application has a back office whose controllers are stored in constant on the fly.
Relative references are reported to be missing in the cref where they were hit, and qualified references are reported to be missing in their parent (see Resolution Algorithm for Relative Constants at the beginning of this guide for the definition of if the class or module in which C is missing is Object let ns = '' else let M = the class or module in which C is missing if M is anonymous let ns = '' else let ns = end end loop do # Look for a regular file.
In practice, this works quite well as long as the nesting matches all parent namespaces respectively and the constants that make the rule apply are known at that time. If by chance the top-level provides a solution by ensuring that the constant needed to trigger the heuristic is defined in the conflicting place.
When a module acts as a namespace, Rails does not require the application to defines a file for it, a directory matching the namespace is enough.
In particular, the nesting plays no role here, and modules are not special-cased, if neither they nor their ancestors have the constants, is not checked.
Rails autoloading does not emulate this algorithm, but its starting point is the name of the constant to be autoloaded, and the parent. Given a string with a constant path we define its to be the string that results from removing its rightmost segment.
Let's analyze an example to really understand what that means.
While common abuses of language like "the constant.
Our Rubyist instinct quickly sees some redundancy in there: If classes were defined in files matching their name, couldn't their loading be automated somehow?
We could save scanning the file for dependencies, which is brittle. While constants are trivial in most programming languages, they are a rich topic in Ruby.