From: Han Holl Date: 2005-09-17T04:25:35+09:00 Subject: Re: bug in require? ------=_Part_9125_14149565.1126898731686 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/16/05, Ara.T.Howard wrote: >=20 >=20 > harp:~ > cat ./require.rb > require 'rbconfig.rb' > module Kernel > alias_method '__require__', 'require' > def require lib > if((ext =3D lib[ %r/\.[^\.]+$/ ])) > __require__ lib > else > dlext, dlext2 =3D ::Config::CONFIG['DLEXT'], ::Config::CONFIG['DLEXT2'] > __require__ "#{ lib }.#{ dlext }" rescue > __require__ "#{ lib }.#{ dlext2 }" rescue > __require__ "#{ lib }.rb" > end > end > end >=20 >=20 >=20 Yes, that's one way of dealing with it. Another approach that I find attractive is autoload. I think in the case of= =20 the Digest namespace, one could write: module Digest autoload :MD5, 'digest/md5' end Autoloading also has the advantage of looser coupling, lazy loading and=20 auto-determining load order in case of (almost cyclic) dependencies. It should perform better than redundant requires as well, but I doubt this= =20 is noticeable. Cheers, Han Holl ------=_Part_9125_14149565.1126898731686--