Feature #8453
closedImplement Struct.map
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.