rubysyntaxlanguage-implementation

Why is __FILE__ uppercase and __dir__ lowercase?


In Ruby 2.0.0-p0, the __dir__ variable was introduced for easy access to the directory of the file currently being executed.

Why is __dir__ lowercase when __FILE__ is uppercase?


Solution

  • I think that is because __FILE__ is a parse-time constant whereas __dir__ is a function and returns File.dirname(File.realpath(__FILE__))

    For more details, see This discussion