From: Robert Klemme Date: 2004-03-11T01:39:37+09:00 Subject: Re: require is excluding too much "Simon Strandgaard" schrieb im Newsbeitrag news:pan.2004.03.10.14.13.43.358057@adslhome.dk... > On Wed, 10 Mar 2004 15:23:08 +0100, shasckaw wrote: > > Simon Strandgaard wrote: > >> Is this a bug? > >> Shouldn't 'require' load both modules in this case? > >> If not, what is the motivation for doing so? > >> > >> Just curious :-) > >> > >> -- > >> Simon Strandgaard > > [snip] > >> require 'mod' > >> $:.unshift('dir') > >> require 'mod' > >> server> ruby a.rb > >> hello1 > >> server> ls > >> a.rb dir/ mod.rb > >> server> > >> > >> I would have expected it to output both 'hello1' and 'hello2'. > > > > Hello Simon! > > > > When requiring a module twice, it is probable that ruby just use its > > name to check if it has to reload it or not, forgetting to also check if I don't think that "forget" is the appropriate term. One of the files named 'mod.rb' wins and gets loaded. If location would matter, all mod.rb's would have to be loaded, don't they? > > it is in a different directory or not. > > It seems so. Moreover IMHO this is the only approach to go. Doing "require 'foo'" announces that a "foo.rb" (or shared lib) has to be loaded from any directory in $:. I guess the first occurrence wins. If there is another foo.rb that is silently ignored. If at a later point in time either $: changes or there is a new foo.rb in an earlier location in $: Additionally it's not usual that $: changes or that there are more files with the same relative path in an installation's lib directories. *If* you create a situation like you did, it is IMHO more appropriate to use "load" since you know where to get the file from anyway. In short, I don't regard this an error. Sorry if I haven't been clear enough. (Out of words error) Kind regards robert