What does __FILE__ mean in Ruby?

前端 未结 4 1191
攒了一身酷
攒了一身酷 2020-11-28 00:43

I see this all the time in Ruby:

require File.dirname(__FILE__) + \"/../../config/environment\"  

What does __FILE__ mean?

4条回答
  •  渐次进展
    2020-11-28 01:38

    __FILE__ is the filename with extension of the file containing the code being executed.

    In foo.rb, __FILE__ would be "foo.rb".

    If foo.rb were in the dir /home/josh then File.dirname(__FILE__) would return /home/josh.

提交回复
热议问题