[Rubygems-developers] The deprecation of autorequire

Jim Weirich jim.weirich at gmail.com
Thu Jan 15 00:08:37 EST 2009

On Jan 14, 2009, at 8:35 PM, Daniel Berger wrote:

> No, for that example you're correct.
> I just thought that, as more of the stdlib is bundled separately as  
> a gem it may become more of a hassle to have to do 'gem' +  
> 'require'. I thought it would still be useful for those authors, but  
> it seems to cause more confusion than it's worth.
> It can always be revisited/revived again at a later day if necessary.

The rule of thumb is:

Always use a 'require' command.  Ideally, each file requiring the  
functionality should independently do the require (or require a file  
that does all the common requires). A result of this is that require  
commands are often spread throughout the program.

Only use a 'gem' command if you want something other than the latest  
installed version of a gem.  You application should arrange to invoke  
the gem command early in the program, after 'rubygems' has been  
required, but before any other requires have run.

Autorequire could cause subtle bugs where files get auto-required and  
loaded before a subsequent 'gem' command has a chance to specify what  
version of a gem should be used.

It was because of these (very real, but subtle) problems that  
autorequire was deprecated.[1]

-- Jim Weirich
-- jim.weirich at gmail.com

[1] Autorequire also had the harmless but annoying feature that it  
could cause require to return false even when the file was actually  
loaded.  Nobody EVER checks the return value of require in a program,  
but the return value is displayed in irb, causing a number of people  
to panic (thinking that their file wasn't loaded).

More information about the Rubygems-developers mailing list