From: "Mauricio Fernández" Date: 2004-11-20T21:48:28+09:00 Subject: Re: several questions on using gems On Sat, Nov 20, 2004 at 07:57:37PM +0900, David Garamond wrote: > 1. If I write a Ruby library (including a gem package) for others, what > is the suggested way of require-ing other library? The gem version first > (like in Pickaxe II): > > begin > require 'rubygems' > require_gem 'foolib' > rescue LoadError > require 'foolib' > end > > Or the non-gem version first (like in Rake): > > begin > require 'foolib' > rescue LoadError > require 'rubygems' > require_gem 'foolib' > end > > And what's the rationale for each? require_gem 'foolib' doesn't make much sense anymore: now RubyGems incorporates the 'require hack', so just require 'rubygems' # you might want to rescue LoadError here require 'foolib' should do. There is little gain in doing an "unqualified" require_gem (i.e. without version information), and it won't work if the relevant library wasn't installed with RubyGems... You can also leave the require 'rubygems' out and set RUBYOPT=rubygems. Note that once you have required 'rubygems', all subsequent require 'foo' will use the libraries managed by RubyGems preferentially. There is no easy way to reverse that, short of redefining require to use the original method. > 3. When rubygems has been included with every Ruby installation, what > will be the standard way of requiring libraries? I hope it will be just: > > require_gem 'foolib' # or perhaps require, whichever > > What I wouldn't like is having to think to choose between 'require' or > 'require_gem' each time I want to load a library. Or write some kind of > wrapper. So I'm guessing (again) that there will be some magic stuffs in > 'require' and 'require_gem' to seamlessly choose the right stuffs? That wrapper is already there. You can just use require 'foolib' in most cases. -- Hassle-free packages for Ruby? RPA is available from http://www.rubyarchive.org/