On Sun, Mar 2, 2014 at 8:11 PM, Xavier Noria <[email protected]> wrote:
> I believe the culprit here is Delegator. > > Delegator owns const_missing, it is all or nothing (reproduced from > memory): > 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): > That's a good point. I might attempt to contribute a patch to Ruby. > 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. > That also makes sense. > 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. > Yeah. I suppose if someone knows enough to look for that subclass, they could as well use require_dependency. > 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". > You're probably right. > 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. > Hopefully the blog post with keywords like SimpleDelegator, Rails, autoloading, "uninitialized constant" will be helpful if someone runs into this gotcha. Thanks a lot for sharing your thoughts on this! > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ruby on Rails: Core" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/rubyonrails-core/PjGUK72BmFA/unsubscribe > . > To unsubscribe from this group and all its topics, 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. > -- 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.
