Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Kernel#__dir__

() -> ::String?
__dir__ → string

Returns the canonicalized absolute path of the directory of the file from which this method is called. It means symlinks in the path is resolved. If __FILE__ is nil, it returns nil. The return value equals to File.dirname(File.realpath(__FILE__)).

See also #Complex #eval #clone #exec also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0