From: Mathieu Bouchard Date: 2002-08-05T00:47:40+09:00 Subject: Re: Should this work? On Sun, 4 Aug 2002, Gavin Sinclair wrote: > Now, I love the "map" method, but sometimes its use is more verbose than it > could be. It "would be nice" if one could do the following things: > names = %w(john mary adam jacky) > names.map { capitalize } # -> ["John", "Mary", "Adam", "Jacky"] You can add something like that yourself: module Enumerable def map(a=nil,&b) r=[] each(&(if a then proc {|v| r << (v.send a) } else proc {|v| r << (b.call v) } end)) r end end names = %w(john mary adam jacky) names.map :capitalize #==> ["John", "Mary", "Adam", "Jacky"] Here's something else for you: class Many def initialize(*a) @a=a end def method_missing(*m,&b) @a.each {|e| e.send(*m,&b) } end end def M(*a) Many.new(*a) end M(a=[],b=[42]) << "hello" p a #==> ["hello"] p b #==> [42,"hello"] ________________________________________________________________ Mathieu Bouchard http://artengine.ca/matju