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
(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
– Jim W.