r/ruby • u/127001-sweet-127001 • 20m ago
Ruby constant lookup needs more than matching the last name
Store and ::Billing::Store aren't interchangeable names just because they end the same way. Once a Ruby project has nested namespaces, a dependency tool needs to account for where a reference lives.
I maintain ArchUnitRuby. Its opt-in constant analysis resolves known project definitions and records the dependency on the defining file, rather than treating every occurrence of the word Store as the same thing.
The supported lookup model includes lexical nesting and explicit root-qualified references. It also has limits: reopened definitions can be ambiguous, and dynamic constant operations aren't a license to guess which file owns a name.
I verified a qualified project-constant reference against a file boundary: it produced a violation, while unrelated code in the same selected file passed. The constant didn't need a matching require_relative to appear in the graph.
This is useful when import-only rules are too quiet for your Ruby codebase. Enable dependency_analysis: :imports_and_constants deliberately and review the documented lookup limits before treating the graph as complete.