https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-02-27T10:31:55ZRuby Issue Tracking SystemRuby master - Bug #7975: Why __dir__, not __DIR__https://redmine.ruby-lang.org/issues/7975?journal_id=371242013-02-27T10:31:55Zzzak (zzak _)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>see <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: __DIR__ revisted (Closed)" href="https://redmine.ruby-lang.org/issues/3346">#3346</a></p> Ruby master - Bug #7975: Why __dir__, not __DIR__https://redmine.ruby-lang.org/issues/7975?journal_id=371282013-02-27T10:48:44Zyhara (Yutaka HARA)
<ul></ul><p>That is becuase <strong>dir</strong> is a method, whereas <strong>FILE</strong> is not.</p>
<p>$ ruby -ve 'p Kernel.methods'<br>
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]<br>
[:sprintf, :format, :Integer, :Float, :String, :Array, :Hash, :warn, :raise, :fail,<br>
:global_variables, :<strong>method</strong>, :<strong>callee</strong>, :<strong>dir</strong>, :eval, .....</p>
<p><strong>dir</strong> is prefered to avoid adding a new keyword (see <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Kernel#__dir__ (Closed)" href="https://redmine.ruby-lang.org/issues/1961">#1961</a>.)</p> Ruby master - Bug #7975: Why __dir__, not __DIR__https://redmine.ruby-lang.org/issues/7975?journal_id=371462013-02-27T20:19:34Zwardrop (Tom Wardrop)tom@tomwardrop.com
<ul></ul><p>=begin<br>
We did not come to any sort of resolution to the naming inconsistency between <strong>dir</strong>/<strong>method</strong> and <strong>FILE</strong>/<strong>LINE</strong> in any of those mentioned issues.</p>
<p>Should we not add <strong>file</strong> and <strong>line</strong> as methods, and perhaps deprecate the keywords <strong>FILE</strong> and <strong>LINE</strong>. This would keep it consistant with all the other double-underscore methods. To most developers who perhaps do not know Ruby as intricately as most of the people on this issue tracker, the inconsistency between <strong>dir</strong> and <strong>FILE</strong> is not just confusing by name, but the fact that one is a method and one isn't, is doubly confusing. Definitely not principle of least surprise.</p>
<p>This needs to be addressed in my opinion, either through deprecation of <strong>FILE</strong> and <strong>LINE</strong>, or by keeping those keywords and simply creating Kernel method equivalents for the sack of a consistant API.</p>
<p>While on the topic, someone also suggested in one of those previous issues, to give <strong>dir</strong> an optional join argument, so you could do something like this:</p>
<p>(({<strong>dir</strong>('somefile.txt') # => /Users/admin/somefile.txt}))</p>
<p>I'd predict that at least 90% of use cases for <strong>dir</strong> will involve joining it to another path or filename. I can't see any harm in adding this. The naming inconstancies are my main concern however.<br>
=end</p>