Ruby Language Special Constants in Ruby __FILE__


Is the relative path to the file from the current execution directory
Assume we have this directory structure: /home/stackoverflow/script.rb
script.rb contains:

puts __FILE__

If you are inside /home/stackoverflow and execute the script like ruby script.rb then __FILE__ will output script.rb If you are inside /home then it will output stackoverflow/script.rb

Very useful to get the path of the script in versions prior to 2.0 where __dir__ doesn't exist.

Note __FILE__ is not equal to __dir__