ruby: irb gives NameError attempting to use mechanize gem (ubuntu)

拜拜、爱过 提交于 2019-12-24 09:37:18

问题


On my ubuntu box, irb (ruby) gives a NameError when I try to use the mechanize gem:

$ irb
irb(main):001:0> require 'mechanize'
=> true
irb(main):002:0> Mechanize.new
NameError: uninitialized constant Mechanize
    from (irb):2
    from :0

gem env shows this:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /var/lib/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :gempath => ["/var/lib/gems/1.8", "/usr/lib/ruby/gems/1.8"]
  - REMOTE SOURCES:
     - http://rubygems.org/

gem list shows it's installed:

$ gem list mech
*** LOCAL GEMS ***
mechanize (1.0.0)

it's in both paths in the filesystem:

$ ls -1 /var/lib/gems/1.8/gems/ |grep mech
mechanize-1.0.0

$ ls -1 /usr/lib/ruby/gems/1.8/gems |grep mech
mechanize-1.0.0

RubyGems is up to date:

$ gem update --system
Updating RubyGems
Nothing to update

# gem list rubygems
*** LOCAL GEMS ***
rubygems-update (1.3.7)

I have an up-to-date ruby:

ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]

Here's what ubuntu gems packages I have (note that I installed rubygems-update and ran update_rubygems):

# dpkg -l rubygems*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name               Version            Description
+++-==================-==================-====================================================
ii  rubygems           1.3.5-1ubuntu2     package management framework for Ruby libraries/appl
ii  rubygems-doc       1.3.5-1ubuntu2     package management framework for Ruby libraries/appl
ii  rubygems1.8        1.3.5-1ubuntu2     package management framework for Ruby libraries/appl

回答1:


try to create the class using

WWW::Mechanize.new


来源:https://stackoverflow.com/questions/3421468/ruby-irb-gives-nameerror-attempting-to-use-mechanize-gem-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!