__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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents