为什么 __FILE__ 大写而 __dir__ 小写? [英] Why is __FILE__ uppercase and __dir__ lowercase?
本文介绍了为什么 __FILE__ 大写而 __dir__ 小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Ruby 2.0.0-p0 中,引入了 __dir__
变量以方便访问当前正在执行的文件的目录.
In Ruby 2.0.0-p0, the __dir__
variable was introduced for easy access to the directory of the file currently being executed.
为什么 __dir__
是小写的,而 __FILE__
是大写的?
Why is __dir__
lowercase when __FILE__
is uppercase?
推荐答案
我认为这是因为 __FILE__
是一个解析时间常量而 __dir__
是一个函数并返回File.dirname(File.realpath(__FILE__))
I think that is because __FILE__
is a parse-time constant whereas __dir__
is a function and returns File.dirname(File.realpath(__FILE__))
有关详细信息,请参阅此讨论
这篇关于为什么 __FILE__ 大写而 __dir__ 小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文