I’m using modules as namespaces in ruby. How would I go about autoloading…something like autoload :"App::ModuleA", 'app/module_a that doesn’t throw a “must be constant name” error?
I’m using modules as namespaces in ruby. How would I go about autoloading…something like
Share
You need to pass a symbol to
autoload(probably a typo in your question), and call it on the parent of the constant, like:Note that this works for nested levels too. Say that in
app/module_ayou have:When Ruby encounters
App::ModuleA::Inner, it will first attempt to accessModuleA, succeed by autoloading it, and only then attemptInner, which succeeds also because it now knows where to autoload it.