【问题标题】:`require': cannot load such file`require': 不能加载这样的文件
【发布时间】:2012-12-27 20:07:55
【问题描述】:

所以我意识到这是一个过度提问的问题,但我似乎无法找出答案。我已经参考了这些问题和答案:

ruby - require & cannot load such file Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?

基本上,我正在编写一个 gem,当我尝试在主模块中要求另一个带有类的文件时,它会抛出此错误 ``require': cannot load such file` 当我提供完整路径和文件扩展名时,它可以工作.我读过你应该使用 require './dir/filename' 。这也不起作用。

应该注意的是,我安装了单用户 rvm,which ruby 产生 /Users/davidhahn/.rvm/rubies/ruby-1.9.3-p286/bin/ruby

【问题讨论】:

    标签: ruby rvm require


    【解决方案1】:

    在 1.9 中,我建议对库中的文件使用 require_relative,因为它始终使用当前文件的相对路径,而不是加载路径。在 lib)在加载路径中,并且不同的库不会更改您的顺序。

    【讨论】:

      猜你喜欢
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 2015-03-25
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多