D
David Masover
I've just discovered Ruby's autoload feature. It looks to imply something like
this:
autoload :Foo, 'foo'
Bar.autoload :Baz, 'bar/baz'
This implies that to have namespace'd modules autoloaded properly, I would end
up with a structure like this:
autoload :Foo, 'foo'
(and, in foo.rb)
module Foo
autoload :Bar, 'foo/bar'
end
What if I want to abstract away such a system? In other words, what if I want
a light, portable version of Rails-style autoloading? In a perfect world, I
would be able to do something like this:
autoload :Foo do
require 'foo'
Foo.autoload :Bar ...
end
In that simplest form, it would at least centralize all my loading stuff in
one place. In a more meta form, I could run through some search paths I'm
likely to use (in my own app, for instance), and generate an autoload scheme
based on that.
Does this sound like a good idea? Or should I be hacking it together with
const_missing, instead?
this:
autoload :Foo, 'foo'
Bar.autoload :Baz, 'bar/baz'
This implies that to have namespace'd modules autoloaded properly, I would end
up with a structure like this:
autoload :Foo, 'foo'
(and, in foo.rb)
module Foo
autoload :Bar, 'foo/bar'
end
What if I want to abstract away such a system? In other words, what if I want
a light, portable version of Rails-style autoloading? In a perfect world, I
would be able to do something like this:
autoload :Foo do
require 'foo'
Foo.autoload :Bar ...
end
In that simplest form, it would at least centralize all my loading stuff in
one place. In a more meta form, I could run through some search paths I'm
likely to use (in my own app, for instance), and generate an autoload scheme
based on that.
Does this sound like a good idea? Or should I be hacking it together with
const_missing, instead?