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

A

Austin 7873

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!
 
R

Rimantas Liubertas

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'

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
 
A

Austin 7873

Rimantas said:
'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?
 
R

Rimantas Liubertas

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 :) '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.
 
A

Austin 7873

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. :)
 
E

Eric Hodel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top