是require File.expand_path(...,__FILE__)的最佳实践吗? [英] Is require File.expand_path(..., __FILE__) the best practice?

查看:390
本文介绍了是require File.expand_path(...,__FILE__)的最佳实践吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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