Project

General

Profile

Actions

Feature #10880

closed

Subclassing Array from Enumerator

Added by sawa (Tsuyoshi Sawada) about 9 years ago. Updated over 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:68214]

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 9 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 9 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 9 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 9 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 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.

Updated by sawa (Tsuyoshi Sawada) over 4 years ago

I should use each_with_index and each_with_object as marcandre suggests. I withdraw this. Please close this issue.

Actions #6

Updated by Eregon (Benoit Daloze) over 4 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0