Ruby-require抛出错误

时间:2013-02-02 18:16:40

标签: ruby rubygems

我正在尝试加载rubywrite并运行其中一个示例,但这会给我带来以下错误: -

/usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rubywrite/exceptions (LoadError)
    from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/ankit/Downloads/Studies/PLI/Assignment2/RubyWrite/lib/rubywrite.rb:1:in `<top (required)>'
    from pcc.rb:4:in `require_relative'
    from pcc.rb:4:in `<main>'

我不确定需要做什么。我的Ruby版本是:

- ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

我的宝石环境是: -

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/bin/ruby1.9.1
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.9.1
     - /home/ankit/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

2 个答案:

答案 0 :(得分:1)

默认情况下,当前目录不包含在库包含路径中。

您可以使用-I选项在Ruby命令行中显式添加它:

ruby -I. the_file.rb

答案 1 :(得分:0)

使用'require_relative'并指定要包含的文件的完整路径。问题是'require'只查看Ruby库路径中的文件。另见:What is the difference between require_relative and require in Ruby?