[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

RubyGems 0.9.1 calling a gem with gem ''

Austin 7873

1/26/2007 10:48:00 PM

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!

--
Posted via http://www.ruby-....

5 Answers

Rimantas Liubertas

1/26/2007 11:09:00 PM

0

> 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/chapte... (section 3.4).
'gem' does something different than you think.


Regards,
Rimantas
--
http://rim...

Austin 7873

1/26/2007 11:28:00 PM

0

Rimantas Liubertas 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?

--
Posted via http://www.ruby-....

Rimantas Liubertas

1/26/2007 11:43:00 PM

0

> 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.


--
Regards,
Rimantas
--
http://rim...

Austin 7873

1/27/2007 12:11:00 AM

0

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

--
Posted via http://www.ruby-....

Eric Hodel

1/27/2007 10:05:00 PM

0

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 Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!