I believe the culprit here is Delegator.
Delegator owns const_missing, it is all or nothing (reproduced from memory):
class Delegator < BasicObject
def self.const_missing(cname)
::Object.const_get(cname)
end
end
but it should not in my view: after trying its heuristic it should delegate
to super if defined in case there are more heuristics above. Something like
this (off the top of my head):
class Delegator
def self.const_missing(cname)
if ::Object.const_defined?(cname)
::Object.const_get(cname)
else
super if defined?(super)
end
end
end
The key question to address this today is: Which is the public API of
AS::Dependencies? Can I include ModuleConstMissing in the singleton class
of my class? Can I call load_missing_constant?
The answer is no, those belong to the implementation of AS::Dependencies.
The public interface is pretty small, autoload_paths, require_dependency,
and some other stuff, not much. Dependencies.rb is mostly about its
contract.
So as of today, I'd say the best solution is the one based on
require_depedency. That is using public interface, and looks clean in your
source code compared to overriding const_missing. If the code was mine I
would add a comment to explain the call.
Perhaps AS could provide a subclass of SimpleDelegator that does basically
what I wrote above. But that's in a way duplicating (and thus depending) on
the implementation of const_missing in Delegator today, is monkey patching
in disguise in my opinion. Not really convinced.
This is a corner-case though. For this problem to happen we need a class
that inherits from SimpleDelegator and in addition acts as a namespace. Not
sure if it deserves reopening a class of stdlib to "fix it".
All taken into account, I believe this should be considered a gotcha of the
combination SimpleDelegator + namespace + autoloading. And perhaps
Delegator could be patched in future versions of Ruby.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.