Mark Volkmann wrote:
> On 3/6/06, Austin Ziegler <halostatue / gmail.com> wrote:
> 
>> >  spec.autorequire = 'init.rb'
>>
>> The #autorequire is deprecated at this point and is not recommended in
>> any way. RubyGems still supports it, but I believe that the next version
>> will be spouting some warnings at people who use autorequire in building
>> their gems. Since you're using a secondary call to do the load, you can
>> mandate that lib/init.rb is the file to load and have your loader do the
>> require yourself.
> 
> Maybe I misunderstood this, but I thought "require_gem {gem-name}"
> used the autorequire attribute to know which file from the gem to
> load. Is that correct? If so, what will happen to require_gem when
> autorequire goes away?

The preferred way of requiring files is to use a plain require.  Unless 
something tricky is going on, this will work with both gem and non-gem 
installed software (assuming you load rubygems beforehand if you are 
using gem installs).

The require_gem is really only needed if you want a particular version 
of gem installed, in which case you just *add* the require_gem statement 
in a nice, centrally controlled location in your code (because you don't 
want to spread version dependencies throughout your code base), and do 
the normal requires.

This is probably with an example:

If you want you use the foo file in the foobar gem, just do whereever 
needed in your code base:

   require 'foo'

(you may need to require rubygems if your system doesn't make that 
automatic).

If you want to make sure you use version 3.1.4 of the gem foobar, then 
in one central location put:

   require_gem 'foobar', '= 3.1.4'

And whereever you need the foo file, write:

   require 'foo'

Require_gem is a mix of two concepts, the specifying of the *gem* 
version, and the requiring of a specific (autorequire) file.  This 
conceptual confusion has caused several subtle bugs in the gems software 
over time.

The autorequire feature is a holdever from the days when regular 
requires didn't work in rubygems.  It avoided the need to do a 
require_gem *and* a regular require.  Since the regular require is all 
that is needed today, autorequire is a holdover from the past.

I haven't looked at Zed's issues in detail yet, so I can't comment on 
his use in the pluggin system.

--
-- Jim Weirich

-- 
Posted via http://www.ruby-forum.com/.