[Rubygems-developers] Deprecation of autorequire

Austin Ziegler halostatue at gmail.com
Wed Oct 18 10:12:25 EDT 2006

On 10/18/06, Nic Williams <drnicwilliams at gmail.com> wrote:
> So now I'm unsure of how rubygems + require work together.

RubyGems tells Ruby where to find the libraries for a gem. It is
possible, although I don't know what the new command will be called
(gem_activate was bandied around), to activate a specific gem version.
This simply means that if you want version 3.2.1 of a particular gem,
you would do something like:

    gem_activate 'myproject', '=3.2.1'

The same way you do with require_gem. The only difference is that
gem_activate will not autorequire anything.

> If I have a gem called "project_one", and a file "lib/project_one.rb",
> and my external code does "require 'project_one'" I expect that the
> gem's project_one.rb file will be loaded, which probably then loads
> other files in the lib/ folder structure. But I don't know why, and I
> don't know what happens if the gem is called "project_one" and there
> isn't a "lib/project_one.rb" file, instead a "lib/code.rb" file that
> needs to be required instead.

No, what will actually happen is that Ruby will search the load path for
project_one.{rb,so,rbw,bundle,jar} and probably a couple of other
extensions. When it finds the first one, it will load it. If Ruby can't
find that, RubyGems will step into the picture and look through its
manifests for a matching file. It will activate the most recent version
of the first gem it finds with this file, add its path to $LOAD_PATH,
and then require the file.

> Is there docco around to explain this?
> Also, in the gems-instead-of-plugins case, if I shouldn't use autorequire
> (or if there are lots of gems that haven't set it) is it a safe bet to
> assume that there will be a "lib/<gem_name>.rb" file that should be
> loaded/required?

Not in the least. PDF::Writer is a great example of this. The gem name
is pdf-writer. The project is PDF::Writer. The file included is
'pdf/writer'. I will *not* be adding a 'pdf-writer.rb' to PDF::Writer
now or in the future.

Basically, you're going to need to enforce convention for Rails
gem-based plugins. I recommend saying that if you want Rails to treat a
gem as if it were a plugin, you must have:


That way, if I wanted to have a PDF::Writer Rails plugin, I would have:


This would load 'pdf/writer'.

Austin Ziegler * halostatue at gmail.com * http://www.halostatue.ca/
               * austin at halostatue.ca * http://www.halostatue.ca/feed/
               * austin at zieglers.ca

More information about the Rubygems-developers mailing list