From: Piotr Szotkowski Date: 2011-06-17T01:50:57+09:00 Subject: Re: Kernel#autoload vs require_relative --uXxzq0nDebZQVNAZ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Ryan Davis: > On Jun 16, 2011, at 04:29 , Piotr Szotkowski wrote: >> I understand that for require to work relative to the given __FILE__=E2= =80=99s >> directory one needs to either $LOAD_PATH << File.dirname(__FILE__) or >> use require_relative (with the latter being preferred, I presume). >> Is there such an alternative for Kernel#autoload >> =E2=80=93 and if not, should there be one? >> I=E2=80=99m thinking about lib/foo.rb containing >> module Foo >> autoload :Bar, 'foo/bar' >> autoload :Baz, 'foo/baz' >> autoload :Qux, 'foo/qux' >> end >> (which doesn=E2=80=99t work without $LOAD_PATH munging), > I wouldn't call having 'lib' in your LOAD_PATH as munging. Ok (and I understand your arguments). > It just seems sane to me... Much more sane than > File.dirname(__FILE__) does or require_relative. Hm, I do prefer using require_relative over require + $LOAD_PATH changes; it looks cleaner to me and doesn=E2=80=99t touch shared globals, but I guess that=E2=80=99s more of a personal preference. What I was trying to ask is whether there couldn=E2=80=99t be a Kernel#autoload_relative call or a =E2=80=98relative: true=E2=80=99 optional parameter to Kernel#autoload to make it symmetric with the require/require_relative combination. I understand your answer would be =E2=80=98there=E2=80=99s no need=E2=80=99. :) > (btw, you don't need the ".rb" part--that's just ugly) Fully agreed; fixed in the quotation above (I shouldn=E2=80=99t post before my morning coffee). =E2=80=94 Piotr Szotkowski --=20 I consider chromatic to be Larry Wall=E2=80=99s Thomas Huxley. [Jarkko Hietaniemi, hates-software] --uXxzq0nDebZQVNAZ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk36NGUACgkQi/mCfdEo8Uo8vACgiQmYXJeA1LfnoAJshEOpwJgU C0sAn1bJeLZSZOPLAmE9zFnb6kdgm3bp =IMw4 -----END PGP SIGNATURE----- --uXxzq0nDebZQVNAZ--