From: David Masover Date: 2008-08-17T14:39:41+09:00 Subject: Re: More autoload... On Saturday 16 August 2008 21:40:32 Trans wrote: > > On Aug 16, 4:28 pm, David Masover wrote: > > Or am I really going to have to create a temporary file for each and every > > source file I might possibly ever want to use? Actually, I have figured out something that works reasonably well, for now. Given a path that can be safely autoloaded, it will check for files in there that look like they could be modules. It also provides a mixin, which, when included, checks through its existing paths for possible nested modules and adds them. I suspect it's twice as long as it needs to be, though, and certainly less elegant to write. If anyone's interested, I can clean it up and release it. It's roughly equivalent to the same functionality in ActiveSupport, except that it's much shorter (dependencies.rb is around 500 lines, and I'm well under 100), and requires different kinds of babysitting. That is: With ActiveSupport, if foo.rb is not loaded, the following: class Foo; end will cause foo.rb to _never_ be autoloaded, because const_missing isn't checked on assigning things to a constant. However, in my version, to support foo/bar.rb, I have to do at least: module Foo include AutoLoad end I can put it in foo.rb, or anywhere that's loaded by the time I need Foo::Bar, but it is required. > The things to do is of course to fix the Ruby source to A) use a > callback for autoload and B) to use the normal Kernel.require call. > Then submit a patch and pray the higher ups care enough to check it > in. I'd add a C) Have const_missing actually called in enough places to make it possible to implement vanilla autoload on top of const_missing. Having autoload be more flexible in the action it performs would be helpful, but it'd be even more helpful for it to be flexible in the constants it applies to. > Now the question is are you a C coder ;) Yes and no. I have written one-line kernel patches, which did things I'm ashamed to admit. I've cracked open abandoned projects, to try to make them, for example, compile on 64-bit. I've read the source of poorly-documented parts of PowerDNS to figure out what it was doing. To be a programmer on any Unix is to have to be at least somewhat aware of what C is and what it can do, even if you never use it. But I have never done any significant development in C. Even if I had, it would (I assume) still take some time to learn the Ruby codebase and conventions. So, someone else needs to do this :(