Failure in using RubyGems seems to be a common problem in
#ruby-lang and the documentation is clearly lacking1. Let’s go through how you are supposed to load a gem called
foobar. First of all, the
rubygems library has to be loaded. This can be done in three ways:
-rubygemsto the Ruby interpreter.
require "rubygems"in the application2.
All three ways are equivalent. Loading the
rubygems library does two important things:
requireso that it starts looking inside gems if the file isn’t found in the load path. If the library is found in a gem, the load path is changed and the library is loaded.
require_gemmethod that looks for a gem with the given name, alters the load path and loads whatever files the packager has specified to be loaded. This way is deprecated, but very useful when you need to load a certain version. (Like this:
1 Yes, I or somebody else should do something about it.
2 Not recommended, since not everybody likes or uses RubyGems.