Bug #13126
closed__dir__ in eval returns nil
Description
$ ruby -e 'eval "p File.dirname(__FILE__); p __dir__"'
"."
nil
Updated by shyouhei (Shyouhei Urabe) about 7 years ago
- Status changed from Open to Feedback
Can you show us your expectation? Should what be the value for __dir__
inside of an eval
?
Updated by metadeus (Artem Shein) about 7 years ago
Shyouhei Urabe wrote:
Can you show us your expectation? Should what be the value for
__dir__
inside of aneval
?
It should be the same as File.dirname(__FILE__)
or at least File.dirname(File.realpath(__FILE__))
(like your documentation say).
Updated by nobu (Nobuyoshi Nakada) about 7 years ago
Artem Shein wrote:
It should be the same as
File.dirname(__FILE__)
or at leastFile.dirname(File.realpath(__FILE__))
(like your documentation say).
When the third argument is not given, __FILE__
in eval
is "(eval)"
.
Do you mean that __dir__
should be "."
?
Updated by metadeus (Artem Shein) about 7 years ago
Nobuyoshi Nakada wrote:
When the third argument is not given,
__FILE__
ineval
is"(eval)"
.
Do you mean that__dir__
should be"."
?
No, I mean that documentation is saying:
"The return value equals to File.dirname(File.realpath(__FILE__))
." here: http://ruby-doc.org/core-2.3.0/Kernel.html#method-i-__dir__
I've replaced the "File.dirname(File.realpath(__FILE__))
" in my source code with "__dir__
" and got different result. I don't care about the exact value, but I expect it to be the same.
Updated by nobu (Nobuyoshi Nakada) about 7 years ago
Artem Shein wrote:
I've replaced the "
File.dirname(File.realpath(__FILE__))
" in my source code with "__dir__
" and got different result. I don't care about the exact value, but I expect it to be the same.
The former also does not work in eval
as expected unless a real path name is given.
Please elaborate on the concrete code.
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Status changed from Feedback to Closed