From: Robert Feldt Date: 2001-10-26T20:16:15+09:00 Subject: [ruby-talk:23424] RCR #50 Simplifying the use of map by adding optional parameter Hi, Below is a new RCR. If you feel anything about it please go to http://www.rubygarden.com/article.php?sid=127 and vote. Regards, Robert RCR #50 ------- Change map to take an optional parameter which is a Symbol which is sent to each element (as a message). Example: [1,2].map(:succ) #=> [2,3] I know that you can do it with [1,2].map {|e| e.succ} but its more than a "shortcut". IMHO its more in line with how map is used in functional programming languages. I'm not sure what should happen if one both gives a parameter and a block. Either skip the parameter or apply it first? Probably the latter since you would otherwise not specify the parameter. So here's the new semantics I'm asking for (I'm not sure about the extra args but added them anyway): class Array def rcr50_map(symbol = nil, *args, &block) if symbol.kind_of?(Symbol) a = self.map {|e| e.send(symbol, *args)} else a = self end a.map(&block) end end Oh, it should really be Enumerable#map but this is just an example!?