是require File.expand_path(...,__FILE__)的最佳实践吗? [英] Is require File.expand_path(..., __FILE__) the best practice?
问题描述
require File.expand_path(..., __FILE__)
是在项目中要求其他文件的最佳方法吗?
Is require File.expand_path(..., __FILE__)
the best way to require other files within a project?
推荐答案
在Ruby 1.9.2 + require_relative
中可能是更正确的方法.
In Ruby 1.9.2 + require_relative
is probably the more correct way to do it.
require
已更改为不包含您的'.'
目录.添加require_relative
可以为与您的调用脚本的路径相关的模块提供本地文件解决方案.
require
was changed to not include your '.'
directory for security reasons. require_relative
was added to provide a local-file solution for modules relative to your calling script's path.
您可以在StackOverflow上在此处搜索,尤其是在"
You can search here on StackOverflow, particularly in "What is require_relative in Ruby?", and the internets and find usage tricks and the why-for messages explaining how it came about.
这篇关于是require File.expand_path(...,__FILE__)的最佳实践吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!