[Rubygems-developers] The deprecation of autorequire
luislavena at gmail.com
Wed Jan 14 20:29:54 EST 2009
On Wed, Jan 14, 2009 at 7:17 PM, Berger, Daniel <Daniel.Berger at qwest.com> wrote:
> 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
> This isn't a major deal. It's just a minor nuisance really, but I was
AFAIK autorequire has been deprecated.
A good reason will be that under certain circumstances you don't want
to load the whole library of a gem.
gem 'rspec', '~> 1.1.10' # allow me to have a code locked to a
specific mayor.minor safe versions
with autorequire, the above example would have included 'spec' which
is big and offer way more stuff that I wanted to integrate (I only
wanted the expectations).
As you mention, you need to call #gem to indicate you want the gem
version over the bundled one.
The same will apply to Rake, which is bundled with 1.9:
unless the stdlib cases, you can simply everything to just:
And will work, no need to indicate the gem activation at all.
Did I miss something?
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
More information about the Rubygems-developers