Hi all! When using Rubygems, is there any *relevant* difference between using require and require_gem (aside from the versioning possibilities)? According to the docs require searches the standard library first. Is this true for require_gem too, or does that method only search the gem repository? Is is faster? Example: require 'rubygems' # Is any of the two methods below "better" in any way? require 'sqlite3' # Or require_gem 'sqlite3-ruby' Kindly /Lars
on 2005-12-02 09:15
on 2005-12-02 16:29
lasso wrote: > Hi all! > > When using Rubygems, is there any *relevant* difference between using > require and require_gem (aside from the versioning possibilities)? > According to the docs require searches the standard library first. Is > this true for require_gem too, or does that method only search the gem > repository? Is is faster? There is a fundamental difference between require and require_gem: (1) require specifies a file name and loads that file into your ruby session. (2) require_gem specifies a gem name and puts the files in that gem on the search path so that later requires will be able to find the gems file (we call this process "gem activation"). Sometimes require_gem will auto-require the "main" file of a gem (if the author if the gem specified an main file). RubyGems is smart enough that it can generally figure out what gem needs to be activated via normal require statements, so the require_gem is almost never needed. In fact, I would recommend only using the require_gem statement if you need a particular version a gem package (by default, RubyGems will select the latest version for you). I'll repeat: Never use "require_gem" without a version specification. Prefer to use a plain "require" instead. Future versions of RubyGems will rename "require_gem" (probably to "activate_gem") and have it drop the auto-require step. This should lessen the confusion between the normal require and RubyGems activation process. -- Jim W.
on 2005-12-02 16:31
On 12/2/05, Lars O. <email@example.com> wrote: > require 'sqlite3' > > # Or > > require_gem 'sqlite3-ruby' Yes. require_gem, at least for some gems, and *definitely* for future versions of PDF::Writer and other packages that I write will only require the gem. It will not autorequire the core functionality as it does now. -austin