为什么 Ruby 1.9.2 删除了“."?来自 LOAD_PATH,还有什么选择? [英] Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?

查看:33
本文介绍了为什么 Ruby 1.9.2 删除了“."?来自 LOAD_PATH,还有什么选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby 1.9.2 的最新变更集不再使当前目录 . 成为您的 LOAD_PATH 的一部分.我有大量的 Rakefile 假设 .LOAD_PATH 的一部分,所以这破坏了它们(他们报告说没有这样的文件要加载"所有需要基于项目路径的语句).这样做有什么特别的理由吗?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆