Feature #10880 closed
Subclassing Array from Enumerator
Added by sawa (Tsuyoshi Sawada) about 10 years ago.
Updated over 5 years ago.
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)
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?
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.
I use with_index and with_object frequently.
Any reason why you wouldn't simply use each_with_index
and each_with_object
?
Marc-Andre Lafortune wrote:
I use with_index and with_object frequently.
Any reason why you wouldn't simply use each_with_index
and each_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.
I should use each_with_index
and each_with_object
as marcandre suggests. I withdraw this. Please close this issue.
Status changed from Open to Rejected
Also available in: Atom
PDF
Like 0
Like 0 Like 0 Like 0 Like 0 Like 0 Like 0