In article <IJXUe.3397$S26.923@tornado.texas.rr.com>,
···
itsme213 <itsme213@hotmail.com> wrote:
When requiring a gem with
require 'gemname'
I seem to get a consistent return of "false", even when the gem has been
loaded successfully. This does not match the spec of 'require'.
Is this a gem bug? Or is it supposed to behave this way?
Thanks.
I've noticed this too. Mostly you notice it in irb, of course. Before I
realized that it was giving me a false 'false' I spent a lot of time
trying to download the gem again and load it, etc.
Any ideas why reuire 'gem' returns false even when successful?
In article <IJXUe.3397$S26.923@tornado.texas.rr.com>,
>When requiring a gem with
> require 'gemname'
>
>I seem to get a consistent return of "false", even when the gem has been
>loaded successfully. This does not match the spec of 'require'.
You realize that require works with file names, not gem names ... right?
···
On Sunday 11 September 2005 03:46 pm, Phil Tomson wrote:
itsme213 <itsme213@hotmail.com> wrote:
--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
I also see this behavior when required files can't be loaded. Sparklines requires RMagick, but if RMagick isn't available (I moved it aside) then no LoadError is given.
In article <200509120111.49863.jim@weirichhouse.org>,
···
Jim Weirich <jim@weirichhouse.org> wrote:
On Sunday 11 September 2005 03:46 pm, Phil Tomson wrote:
In article <IJXUe.3397$S26.923@tornado.texas.rr.com>,
itsme213 <itsme213@hotmail.com> wrote:
>When requiring a gem with
> require 'gemname'
>
>I seem to get a consistent return of "false", even when the gem has been
>loaded successfully. This does not match the spec of 'require'.
You realize that require works with file names, not gem names ... right?
Right.
In cases where I've seen this, require returns false but I am able to use
the classes/modules/methods defined in the file that was required (even
though it returned false).
You realize that require works with file names, not gem names ... right?
Right. In cases where I've seen this, require returns false but I
am able to use the classes/modules/methods defined in the file
that was required (even though it returned false).
So where's the code for 'require' so we can work out how it works?
Right. In cases where I've seen this, require returns false but I am able to use the classes/modules/methods defined in the file that was required (even though it returned false).
Sounds like the gem autorequire'd the module for you. Try requiring just the gem (require_gem) and see if that is enough.
Thanks. I took a bit to figure out, but here's what is happening.
Gem goes to load active_record and cannot find it, so it recognizes that there
is an active_record file in a gem named 'activerecord'. It actives the gem
with autorequire enabled. It then attempts to require the active_record file
again, but since the gem was activated with autorequire, the file is already
loaded by the activation step. Since it is already load, require returns
false.
We can fix this by turning off autorequire during the gem activation. I am
tempted to do this, but want some testing time to make sure we don't break
something else.
I also see this behavior when required files can't be loaded.
Sparklines requires RMagick, but if RMagick isn't available (I moved
it aside) then no LoadError is given.
Hmmm ... surprisingly disabling autorequire fixes this behavior too. The
original exception must not propagate out of the activation step. This
confirms my long held belief that autorequire is evil.
(I've CC'ed the rubygems list to make sure everyone there sees this as well).
Thanks for the feedback.
···
On Monday 12 September 2005 02:18 pm, Eric Hodel wrote:
--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)