Inconsistent __FILE__ and Kernel#__dir__
Now, Ruby has
__FILE__ keyword and
Kernel#__dir__ method. One is of upper-case chars, and the other is of lower-case chars.
I make mistakes always when I want to get the directory name of the current file, to write
__DIR__ (of course, it doesn't exist).
That is because of inconsistency between
I understood the reason why
__dir__ is of lower-case chars (to show it's defined as a method, not keyword), but this inconsistency brings huge confusion to me.
So, in my opinion, Ruby should have one of these options below:
- method alias
Kernel#__DIR__(as a compromise, but are there any difference between keyword
Kernel#__file__(we don't take care of method overheads when we access file systems)
Updated by shevegen (Robert A. Heiler) 8 months ago
I have no personal preference here either way but I can also understand Satoshi's
explanation / confusion.
This may be good to suggest for an upcoming developer meeting. DIR might have
an advantage of being faster than a method and is probably closest to Satoshi's
described case. Kerne#file might be second best; Kernel#DIR would be a bit
strange, though. People might then wonder why an upcased method name would be
added and why there are not more upcased methods in ruby ... or why there are
then both upcased and lowercased methods in ruby that include __ as part of their
name :) so I think the other two suggestions would be better than the DIR
suggestion (if any of them could be approved that is).