Project

General

Profile

Actions

Bug #7975

closed

Why __dir__, not __DIR__

Added by yimutang (Joey Zhou) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.0
Backport:
[ruby-core:52970]

Description

There's a FILE in Ruby 1.x, no file
Why dir in Ruby 2.0 is downcase?

It's not consistent.


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #3346: __DIR__ revistedClosedyhara (Yutaka HARA)05/26/2010Actions

Updated by zzak (zzak _) almost 12 years ago

  • Status changed from Open to Rejected

see #3346

Updated by yhara (Yutaka HARA) almost 12 years ago

That is becuase dir is a method, whereas FILE is not.

$ ruby -ve 'p Kernel.methods'
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]
[:sprintf, :format, :Integer, :Float, :String, :Array, :Hash, :warn, :raise, :fail,
:global_variables, :method, :callee, :dir, :eval, .....

dir is prefered to avoid adding a new keyword (see #1961.)

Updated by wardrop (Tom Wardrop) almost 12 years ago

=begin
We did not come to any sort of resolution to the naming inconsistency between dir/method and FILE/LINE in any of those mentioned issues.

Should we not add file and line as methods, and perhaps deprecate the keywords FILE and LINE. 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 dir and FILE 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.

This needs to be addressed in my opinion, either through deprecation of FILE and LINE, or by keeping those keywords and simply creating Kernel method equivalents for the sack of a consistant API.

While on the topic, someone also suggested in one of those previous issues, to give dir an optional join argument, so you could do something like this:

(({dir('somefile.txt') # => /Users/admin/somefile.txt}))

I'd predict that at least 90% of use cases for dir 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.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0