Require_gem versus gem

Trying to figure out why require_gem works and gem doesn’t. using
just gem, I get uninitialized constant ActiveRecord (NameError). Use
require_gem and it works, but tells me that require_gem is obsolete.

require ‘rubygems’
gem ‘activerecord’

def connect(environment)
conf = YAML::load(File.open(File.dirname(FILE) +
‘/config/database.yml’))
ActiveRecord::Base.establish_connection(conf[environment])
end

connect(‘development’)

Chris

On Sat, Mar 03, 2007 at 08:55:40PM -0800, snacktime wrote:

end

connect(‘development’)

require_gem was a wrapper around require that accepted an optional
second
argument to specify a version constraint.

the new gem method is not a wrapper around require. it simply registers
a
version constraint on the named gem. when you subsequently call require,
that
version constraint is verified.

so if you just want to require activerecord and you don’t care what
vesrion,
just do require ‘activerecord’. otherwise, use the gem method first to
specify which versions.

of course, you still have to require ‘rubygems’ first if you want to
require
a gem, whether you want to specify a specific version constraint or not.

marcel

Marcel Molina Jr. [email protected]

Ah ok that makes sense, thanks for the explanation!

Chris