RubyGems 0.9.1 calling a gem with gem '<gem>'

After upgrading to RubyGems 0.9.1, I’m seeing the following error:

irb(main):001:0> require ‘rubygems’
=> true
irb(main):002:0> gem ‘uuid’
=> true
irb(main):003:0> UUID.new
NameError: uninitialized constant UUID
from (irb):3
irb(main):004:0>

This problem doesn’t happen if I use:

require ‘uuid’

or

require_gem ‘uuid’

I’m also seeing similar problems calling other gems such as:
gem ‘reliable msg’

I’ve run gem pristine -all
I’ve tried reinstalling 0.9.1
I’ve deleted both root and my user source_cache

without any luck.

thanks in advance!

This problem doesn’t happen if I use:
require ‘uuid’

Well, you should use require, not gem. I.e.:
require ‘rubygems’
require ‘my_gem’

See http://rubygems.org/read/chapter/3#page70 (section 3.4).
‘gem’ does something different than you think.

Regards,
Rimantas

Rimantas L. wrote:

‘gem’ does something different than you think.

I was using: gem ‘uuid’

because I had been using: require_gem ‘uuid’
but ran in to the deprecated warning that many people have already
discussed:

Warning: require_gem is obsolete. Use gem instead.

Maybe I’m misinterpreting the “Use gem instead” part?

I was using: gem ‘uuid’

because I had been using: require_gem ‘uuid’
but ran in to the deprecated warning that many people have already
discussed:

Warning: require_gem is obsolete. Use gem instead.

Maybe I’m misinterpreting the “Use gem instead” part?

It depends :slight_smile: ‘gem’ tells your program that you are going to use some
gem, but it does not
require it, so you still have to use ‘require’.
Let’s say you have two versions of ‘my_gem’, 0.1 and 0.2. rubygems
will use the latest by default, but in case you need the first version
you can do the following:

require ‘rubygems’
gem ‘my_gem’, ‘=0.1’
require ‘my_gem’

I think you’ve got bitten by the autorequire feature wich no longer
works. require_gem used to specify the gem and require it, ‘gem’ only
add the gem to load path, you still have to require it.

I think you’ve got bitten by the autorequire feature wich no longer
works. require_gem used to specify the gem and require it, ‘gem’ only
add the gem to load path, you still have to require it.

Thanks Rimantas, you’ve been super helpfull. looks like autorequire in
require_gem was throwing me for a loop. :slight_smile:

On Jan 26, 2007, at 14:48, Austin 7873 wrote:

After upgrading to RubyGems 0.9.1, I’m seeing the following error:

irb(main):001:0> require ‘rubygems’
=> true
irb(main):002:0> gem ‘uuid’
=> true
irb(main):003:0> UUID.new
NameError: uninitialized constant UUID
from (irb):3
irb(main):004:0>

This is expected, you haven’t required ‘uuid’ yet.

This problem doesn’t happen if I use:

require ‘uuid’

#gem only adds a gem’s paths to the load path. You still need to
require the library you’re interested in.

or

require_gem ‘uuid’

#require_gem triggers the deprecated auto-require feature (deprecated
along with #require_gem in 0.9.0). RubyGems custom require is smart,
so auto-require is no longer necessary.

You really only need to use #gem when you need a specific version of
a gem loaded.

Usually:

require ‘rubygems’
require ‘uuid’

is all you need.


Eric H. - [email protected] - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!