Feature #10880
closedSubclassing Array from Enumerator
Description
It often happens that I want to use a method from the Enumerator
class on an array, and so I frequently use Array#to_enum
. Since Array
and Enumerator
share the same parent Enumerable
, they should be very close. I think it would be convenient if Array
inherits from Enumerator
. (Perhaps the same thing can be said for Hash
too)
Updated by marcandre (Marc-Andre Lafortune) about 10 years ago
they should be very close
They are very close:
Enumerator.instance_methods - Array.instance_methods
# => [:with_index, :with_object, :next_values, :peek_values, :next, :peek, :feed, :rewind]
Which method(s) in there do you claim to use frequently?
Updated by sawa (Tsuyoshi Sawada) about 10 years ago
Marc-Andre Lafortune wrote:
Enumerator.instance_methods - Array.instance_methods # => [:with_index, :with_object, :next_values, :peek_values, :next, :peek, :feed, :rewind]
Which method(s) in there do you claim to use frequently?
I use with_index
and with_object
frequently.
Updated by marcandre (Marc-Andre Lafortune) about 10 years ago
I use with_index and with_object frequently.
Any reason why you wouldn't simply use each_with_index
and each_with_object
?
Updated by sawa (Tsuyoshi Sawada) about 10 years ago
Marc-Andre Lafortune wrote:
I use with_index and with_object frequently.
Any reason why you wouldn't simply use
each_with_index
andeach_with_object
?
I want to provide an optional starting number (most often 1
) to the former.
But you are making me realize that my motivation for the proposal is getting weaker.
Updated by sawa (Tsuyoshi Sawada) over 5 years ago
I should use each_with_index
and each_with_object
as marcandre suggests. I withdraw this. Please close this issue.
Updated by Eregon (Benoit Daloze) over 5 years ago
- Status changed from Open to Rejected