Skip to content

__dir__ does not return canonicalized absolute path #4689

@jakago

Description

@jakago

blah.rb

p __dir__
p File.dirname(File.realpath(__FILE__))

Environment

jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [darwin-x86_64]

Darwin mac-mini.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Jan 9 23:07:29 PST 2017; root:xnu-3248.60.11.2.1~1/RELEASE_X86_64 x86_64

Expected Behavior

% ruby -v
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin15]
% ruby blah.rb
"/Users/xxxxxx/Desktop/__dir__test"
"/Users/xxxxxx/Desktop/__dir__test"

Actual Behavior

% jruby -v
jruby 9.1.12.0 (2.3.3) 2017-06-15 33c6439 Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [darwin-x86_64]
% jruby blah.rb
"."
"/Users/xxxxxx/Desktop/__dir__test"

Reference

http://ruby-doc.org/core-2.3.3/Kernel.html#method-i-__dir__

 __dir__

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions