Feature #8016

Alias __FILE__ and __LINE__ as methods

Added by Tom Wardrop about 1 year ago. Updated about 1 year ago.

[ruby-core:53134]
Status:Assigned
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:core
Target version:next minor

Description

=begin
All of the previous issues discussing the new (({Kernel#dir})) method (#1961, #3346, #7975), never came to any conclusion regarding the naming inconsistency between the likes of (({dir})) and (({method})), and the keywords (({FILE})) and (({LINE})).

Should we not add (({file})) and (({line})) as methods also, 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 sake 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. This would just be a nice bonus that takes advantage of the fact that (({dir})) is a method rather than a keyword.
=end

History

#1 Updated by Yui NARUSE about 1 year ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto
  • Target version set to next minor

Also available in: Atom PDF