[Rubygems-developers] Gem Names not correlated to require name

Austin Ziegler halostatue at gmail.com
Tue Sep 30 21:53:50 EDT 2008

On Tue, Sep 30, 2008 at 9:03 PM, Jim Freeze <rubygems at freeze.org> wrote:
> So, I did not realize that require_gem was such a loaded word.  And
> somehow is sucked in autorequire. Who mentioned that?

You did, but you didn't realize it.

#require_gem *was* a method that would work like this:

  require_gem 'pdf-writer', '= 1.1.8'

Looks a lot like the #gem method, right? Well, it is almost exactly
like the #gem method, except that it did one other thing: it looked at
the autorequire field in the gem spec, and then loaded whatever file
(or files?) were in there.

This was removed just prior to the 1.0 release because it was realized
that autorequire was a mistake. What you're asking for is the return
of autorequire. It also means that certain programs are now forever
going to be stuck with RubyGems, even if that's not how they're

If I install ParseTree (for example) with "apt-get ruby-parsetree",
should I expect the ParseTree gem to be installed? Well, ideally, yes.
But the Debian maintainers, in their infinite wisdom, don't like
RubyGems and don't use it so far as I can tell. So, if I've got a
script that runs on multiple platforms, including a Debian system, I
have to make my program look something like this in a #bunny_foo_foo

    bunny_foo_foo 'ParseTree'
  rescue <something>
    require 'ParseTree'

Which is just what you're already complaining about. Note that I put
"<something>" in there; I'm not quite sure what you'd have to rescue.
It might be NoMethodError (because if you don't have RubyGems
installed, you don't have #bunny_foo_foo); it might be LoadError; it
might be Gem::ActivationError (which, if you don't have RubyGems

> This whole conversation started because I've been bombarded with
> complaints that rubygems is broken because there is no way to know
> what to require after installing a gem. In fact, these 'unnamed
> individuals' have identified the problem as two separate problems, 1)
> the naming of the gem and 2) the naming/path of the file to require.

This is a real problem, but it's the same problem that exists on any
packaging system. You want the package names to be sensible, but a
package may offer more than just one thing to load. Consider Facets.
While I don't particularly like this library, it's an excellent
example of the problem: it's a mega-library that contains a lot of
different useful functionality that you don't always want to load all
of it all of the time.

Does Trans force people to install 25 gems to allow an autorequire
mechanism to work on a fine-grained enough level (which means you now
have to remember 25 different gem names...), or does he go with one
gem that people choose "require 'facet/feature1'" and "require
'facet/feature2'" instead? And, if they want, he could offer a
lib/facets.rb that includes all 25 features.

> I really don't see a way around #1. I mean, how can you possibly know
> that the chunky_bacon gem is used for python comment parsing.

> But, the second issue is potentially solvable, but it will require an
> addition of an optional file (or possibly hook code) to a gem.
> So, a standard scenario would be this:
>  sudo gem install bora_bora
> Then, in the ruby code we would have
>  bunny_foo_foo 'bora_bora'

> Is that too abstract?

It's not that it's too abstract: it's the wrong behaviour.

> Today, gem developers can solve this problem in
> the following manner:
>  sudo gem install bora_bora
>  ....
>  require 'rubygems'
>  require 'bora_bora'  # look, no surprise here.
> where the bora_bora gem has included the file lib/bora_bora.rb with the contents
>  require 'my/crazy/path/that/you/cant/guess'
> But, we can refactor these two lines into a single line
>  require_gem 'bora_bora'
> I mean
>  bunny_foo_foo 'bora_bora'  # optional version follows
> So, here the file lib/bora_bora does not have to exist. It could
> possibly be lib/bootstrap.rb. This file will then require the correct
> files. You know, the mysterious ones that I've been getting complaints
> on.
> Also, notice there is no suggestion of autorequire here. This simply
> replaces the "require 'secret/path'".

It's still autorequire, even if bunny_foo_foo looks for lib/bootstrap.rb.

Why? If I have five gems with lib/bootstrap.rb, what happens when I do:

   require 'bootstrap'

One of them will be activated, but it may not be the one you expect.

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