Project

General

Profile

Actions

Feature #12145

open

Aliashood between `size` and `length` is not consistent

Added by sawa (Tsuyoshi Sawada) over 8 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:74168]

Description

When size and length have the same implementation, depending on the class, they are either independently defined methods, or the former is an alias of the latter. Particularly for Array:

[].method(:size).original_name # => :length
[].method(:length).original_name # => :length

but for Hash, String, and Symbol:

{}.method(:size).original_name # => :size
{}.method(:length).original_name # => :length
"".method(:size).original_name # => :size
"".method(:length).original_name # => :length
:"".method(:size).original_name # => :size
:"".method(:length).original_name # => :length

This might be a big issue, but since there is a standard Ruby method original_name, which returns different results, whether this being one way or another should matter. And I see no reason why they should behave differently. They should be unified in one way. Perhaps Hash, String, and Symbol should be made in the same way as with Array.

Updated by sawa (Tsuyoshi Sawada) over 8 years ago

Similarly, Enumerable#inject and Enumerable#reduce and Enumerable#map and Enumerable#collect should be aliased (Although they are not particularly inconsistent, so the motivation for them is not as strong as size and length. But it is indeed strange that in RDoc, inject example appears under reduce and vice versa, etc.).

Actions #2

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Tracker changed from Bug to Feature
  • Backport deleted (2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0