On Mon, Sep 18, 2006 at 02:42:57AM +0900, Logan Capaldo wrote:
> On Mon, Sep 18, 2006 at 02:31:30AM +0900, Josef Wolf wrote:
> > On Mon, Sep 18, 2006 at 01:50:36AM +0900, Logan Capaldo wrote:
> > > On Sun, Sep 17, 2006 at 08:01:17PM +0900, Josef Wolf wrote:
> > > > I have not tried his example because I assumed the library could not be
> > > > loaded.  I was confused by the fact that "require 'readline'" returns
> > > > "false".  Isn't require supposed to return "true" if successful?
> > > The return value of require is borderline meaningless. If require
> > > returns false, that just means that the file has already been require'd.
> > Are you sure with this?  I get false even on the _first_ require.
> Are you sure it's the first require? ;) For instance, I load readline in
> my irbrc so I get the fancy line editing.

Hmm, I don't have an irbrc.  I've just checked: only irb returns false, so
probably irb loads it even if no irbrc exists.

> Try: RUBYOPT="" ruby -e 'p require("readline")'
> 
> Or alternatively before doing require 'readline', do
> $LOADED_FEATURES.grep(/readline/)

   $ RUBYOPT="" ruby -e 'p require("readline")'
   true
   $ ruby -e 'p $LOADED_FEATURES.grep(/readline/)'
   []
   $

> > > If it can't require the file for whatever reason it will raise and
> > > exception, not return false.
> > 
> > Maybe this should be mentioned in the documentation?  Currently, it says:
> > 
> >      Ruby tries to load the library named _string_, returning +true+ if
> >      successful.  [ ... ]
> > 
> Well yeah if it's already require'd it didn't sucessful load it (since
> its already been loaded ;) ).

I find such behavior somewhat irritating.  IMHO, "load not successful" is
semantically aequivalent to "library not available".  It is not documented
that require will raise an exception.  So the return value is the only
(official) way to find out whether the library is available.