[Rubygems-developers] The deprecation of autorequire

Berger, Daniel Daniel.Berger at qwest.com
Wed Jan 14 16:36:12 EST 2009

> -----Original Message-----
> From: rubygems-developers-bounces at rubyforge.org 
> [mailto:rubygems-developers-bounces at rubyforge.org] On Behalf 
> Of Berger, Daniel
> Sent: Wednesday, January 14, 2009 2:18 PM
> To: rubygems-developers at rubyforge.org
> Subject: [Rubygems-developers] The deprecation of autorequire
> Hi,
> I'm curious as to why Gem#gem doesn't autorequire the library:
> require 'rubygems'
> gem 'ptools'
> require 'ptools' # Must I do this?
> p File.which('ruby')
> If I leave out the 'require' on line 3 it doesn't work.
> I checked rubygems.rb and the $LOAD_PATH definitely includes 
> the path where the gems are stored, but as far as I can tell 
> the Gem.activate method does _not_ automatically call require 
> (or gem_original_require) on the gem specified.
> Why not?
> I realize in most cases you can just use reqular 'require', 
> but that doesn't work in all cases. For example, if I want to 
> use Test::Unit 2.x instead of the one that ships with the 
> stdlib, I must use the above approach.
> This isn't a major deal. It's just a minor nuisance really, 
> but I was curious.

Here's a couple of approaches we could take:

The first one does a simple require if the autorequire spec is defined:

--- rubygems.orig       Wed Jan 14 13:52:14 2009
+++ rubygems.rb Wed Jan 14 14:32:42 2009
@@ -202,6 +202,8 @@

+    require spec.autorequire if spec.autorequire
     return true

The second one attempts to require the gem, but handles a load failure
by issuing a warning and moving on:

--- rubygems.orig       Wed Jan 14 13:52:14 2009
+++ rubygems.rb Wed Jan 14 14:30:22 2009
@@ -202,6 +202,12 @@

+    begin
+      require spec.autorequire if spec.autorequire
+    rescue LoadError
+      warn "autorequire for #{gem.name} failed - ignoring"
+    end
     return true

What do you think?



This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.

More information about the Rubygems-developers mailing list