On Jun 16, 2011, at 04:29 , Piotr Szotkowski wrote:

> I understand that for require to work relative to the given __FILE__=92s=

> directory one needs to either $LOAD_PATH << File.dirname(__FILE__) or
> use require_relative (with the latter being preferred, I presume).
>=20
> Is there such an alternative for Kernel#autoload
> =96 and if not, should there be one?
>=20
> I=92m thinking about lib/foo.rb containing
>=20
> module Foo
>  autoload :Bar, 'foo/bar.rb'
>  autoload :Baz, 'foo/baz.rb'
>  autoload :Qux, 'foo/qux.rb'
> end
>=20
> (which doesn=92t work without $LOAD_PATH munging),

I wouldn't call having 'lib' in your LOAD_PATH as munging. I'd call that =
business as usual. Rubygems supports that as a default. All the usual =
rake tasks and test tools support that as a default. It just seems sane =
to me... Much more sane than File.dirname(__FILE__) does or =
require_relative.

(btw, you don't need the ".rb" part--that's just ugly)

> as
> opposed to the (currently working) lib/foo.rb with
>=20
> require_relative 'foo/bar.rb'
> require_relative 'foo/baz.rb'
> require_relative 'foo/qux.rb'

again, ".rb" not needed.