Dependencies implement autoloading as const_missing override.
Sometimes, this creates interesting (to debug) problems. For example:
1. I define module Accounting, in app/models/accounting.rb, which
contains Accounting::Transaction class in
2. I write a spec for Accounting::Transaction, which with "module Accounting".
3. Somewhere in that (or another) spec I call Accounting.foo
Result: if the stars are positioned just so, "module Accounting" may
be already defined by executing the spec for Accounting::Transaction,
therefore app/models/accounting.rb is never loaded. And them I am
staring at some weird error message that talks of Accounting.foo being
not defined (what?! it is defined - I can see that in
app/models/accounting.rb!). Depending on the circumstances, the actual
error can be even more cryptic.
I think, many have gone down this road often enough to feel irritated
On the other hand, calling Kernel.autoload 'Accounting',
'accounting.rb' would load accounting.rb on first mention of
Accounting, whether as a constant reference or opened by "module
I would like to experiment with calling Kernel.autoload on every .rb
file in Dependencies.load_paths during init (either instead of, or on
top of const_missing override). Has anybody tried that already? Is
there are any reason why this wouldn't work?