Issue #3346 has been updated by Eregon (Benoit Daloze).


mame (Yusuke Endoh) wrote:
> Thomas Sawyer and Yutaka Hara,
> 
> Matz determined Kernel#__dir__ (as a method).
> 
> Yhara-san, do you have a patch?

Will __dir__ always be an absolute path, or just File.dirname(__FILE__)?

File.dirname(__FILE__) is relative (often ".") when __FILE__ is $0.
It would mean the path needs to be expanded if it is relative (using File.expand_path), to keep the right location if the current working directory changes.
----------------------------------------
Feature #3346: __DIR__ revisted
https://bugs.ruby-lang.org/issues/3346#change-28627

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: yhara (Yutaka HARA)
Category: core
Target version: 2.0.0


=begin
 I'd like to know why __DIR__ was rejected? I use File.dirname(__FILE__) all the time, and I frequently see others do so as well. #relative_require is helpful but it covers only one specific use case --and probably not the most common one. I am often using File.dirname(__FILE__) in build scripts, when I am loading examples for tests, and when I load output templates or other pluggable modules that reside relative to my code. For something so common, having to clutter my code with a 22 character sequence, when an perfectly obvious 7 character sequence would do semms very uncharacteristic of Ruby, which is usually quite concise. Indeed, it is not uncommon to see code that defines a constant such as DIR = File.dirname(__FILE__) when it will be used more than once because it quickly becomes an eye-sore. For these reasons I hope you will reconsider the earlier rejection.
=end



-- 
http://bugs.ruby-lang.org/