Project

General

Profile

Actions

Bug #13126

closed

__dir__ in eval returns nil

Added by metadeus (Artem Shein) about 7 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
[ruby-core:79067]

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 an eval?

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 least File.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__ in eval 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.

Actions #6

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Feedback to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0