为什么Ruby 1.9.2删除“".从LOAD_PATH,还有什么选择? [英] Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?
问题描述
Ruby 1.9.2的最新更改集不再使当前目录.
成为LOAD_PATH
的一部分.我有大量的Rakefile,它们假定.
是LOAD_PATH
的一部分,所以这使它们中断了(它们报告说,对于所有基于项目路径的require语句,没有要加载的文件").有这样做的特殊理由吗?
The latest changesets to Ruby 1.9.2 no longer make the current directory .
part of your LOAD_PATH
. I have a non-trivial number of Rakefiles that assume that .
is part of the LOAD_PATH
, so this broke them (they reported "no such file to load" for all require statements that based off the project path). Was there a particular justification for doing this?
至于修复,在任何地方添加$: << "."
都可以,但是似乎难以置信,我不想这样做.使我的Rakefiles 1.9.2+兼容的首选方法是什么?
As for a fix, adding $: << "."
everywhere works, but seems incredibly hacky and I don't want to do that. What's the preferred way to make my Rakefiles 1.9.2+ compatible?
推荐答案
被认为是安全"风险.
您可以使用绝对路径绕过它
You can get around it by using absolute paths
File.expand_path(__FILE__) et al
或做
require './filename' (ironically).
或使用
require_relative 'filename'
或添加包含"目录
ruby -I . ...
或相同,使用irb;
or the same, using irb;
$irb -I .
这篇关于为什么Ruby 1.9.2删除“".从LOAD_PATH,还有什么选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!