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

Discussion in 'Ruby' started by Austin 7873, Jan 26, 2007.

  1. Austin 7873

    Austin 7873 Guest

    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-forum.com/.
    Austin 7873, Jan 26, 2007
    #1
    1. Advertising

  2. > 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
    --
    http://rimantas.com/
    Rimantas Liubertas, Jan 26, 2007
    #2
    1. Advertising

  3. Austin 7873

    Austin 7873 Guest

    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-forum.com/.
    Austin 7873, Jan 26, 2007
    #3
  4. > 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://rimantas.com/
    Rimantas Liubertas, Jan 26, 2007
    #4
  5. Austin 7873

    Austin 7873 Guest

    > 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-forum.com/.
    Austin 7873, Jan 27, 2007
    #5
  6. Austin 7873

    Eric Hodel Guest

    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 - - http://blog.segment7.net

    I LIT YOUR GEM ON FIRE!
    Eric Hodel, Jan 27, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page