Xavier Noria
11/20/2007 11:56:00 AM
On Nov 20, 2007, at 12:39 PM, Junkone wrote:
> hello
> can i verify if a library is loaded before doing a require 'library'.
> if so how.
> thanks in advance
require loads a library only once, it returns a boolean that indicates
whether it actually loaded the file[*].
The files loaded so far by require are stored in the array $", so you
could check that if you really need it[**].
-- fxn
[*] In Rails require is redefined and returns a different thing.
[**] Actual file names as passed or resolved by require are stored, so
strictly speaking you have _paths_ and they are not normalized,
expanded, whatever. Thus, the same "library" may have been loaded
twice if the paths to the .rb were different. See footnote on page 117
of the Pickaxe.