문제

Using RVM on OSX, I'm trying to use ruby gems. However, a

require 'rubygems'

returns false in IRB and Rails console. Going through similar questions here, I figured it might have to do with the Gem path vs Gem env.

MAC-AC028761:Ruby ac028761$ irb
1.9.3-p429 :001 > require 'rubygems'
 => false
1.9.3-p429 :002 > Gem.path
 => ["/Users/ac028761/.rvm/gems/ruby-1.9.3-p429", "/Users/ac028761/.rvm/gems/ruby-1.9.3-p429@global"]
1.9.3-p429 :003 > exit
MAC-AC028761:Ruby ac028761$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.9.3 (2013-05-15 patchlevel 429) [x86_64-darwin12.3.0]
  - INSTALLATION DIRECTORY: /Users/ac028761/.rvm/gems/ruby-1.9.3-p429
  - RUBY EXECUTABLE: /Users/ac028761/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/ac028761/.rvm/gems/ruby-1.9.3-p429/bin
  - RUBYGEMS PLATFORMS:
        - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /Users/ac028761/.rvm/gems/ruby-1.9.3-p429
     - /Users/ac028761/.rvm/gems/ruby-1.9.3-p429@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Both the 'Gem.path' and the GEM PATHS on 'gem env' are the same, so that's not the issue. Can't figure out how to fix this.

도움이 되었습니까?

해결책

Since Ruby 1.9 rubygems is automatically required by the interpreter when it starts, so there is no need to require it again.

$ irb
irb> $LOADED_FEATURES.grep /rubygems.rb/
# => ["/usr/lib/ruby/1.9.1/rubygems.rb"]
irb> defined?(Gem)
# => "constant"

다른 팁

require may return false if the file that you are trying to require is already required.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top