__FILE__
suggest change__FILE__ is the path of the current file, in the form that was used to load it. It is not always absolute, and it is not recomputed from the working directory.
Assume this file: /home/stackoverflow/script.rb
puts __FILE__
ruby script.rb from /home/stackoverflow prints script.rb. ruby stackoverflow/script.rb from /home prints stackoverflow/script.rb. An absolute path on the command line prints that absolute path.
Before Ruby 2.0 there is no __dir__. __FILE__ is the file path; __dir__ is the directory that contains it.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents