Project

General

Profile

Actions

Feature #8453

closed

Implement Struct.map

Added by eLobato (Daniel Lobato Garcia) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:55169]

Description

http://ruby-doc.org/core-2.0/Struct.html does not contain any 'map' like method, I imagine given 'each' and 'select' are available it's probably not too hard to implement.

As always I'm 100% open to contribute so if you deem this necessary just let me know and I'll start writing a patch.

Updated by Eregon (Benoit Daloze) over 11 years ago

  • Status changed from Open to Closed

Struct instances (that is classes produced by Struct.new) include Enumerable.

Actually Struct itself includes Enumerable (written in the left column on the documentation page)
and Struct.new makes Struct an ancestor of the created class.

Struct.new(:a,:b).new(1,2).map { |i| i*2 } #=> [2, 4]

I wonder why #select is overridden though. Probably performance reasons.

Updated by Eregon (Benoit Daloze) over 11 years ago

Eregon (Benoit Daloze) wrote:

I wonder why #select is overridden though. Probably performance reasons.

Actually, it is an historical reason: #select used to have #values_at behavior when given integers.

Actions

Also available in: Atom PDF

Like0
Like0Like0