From: Brian Candler Date: 2005-07-12T18:33:45+09:00 Subject: Re: accessing index inside map On Tue, Jul 12, 2005 at 10:04:02AM +0100, Brian Candler wrote: > module Enumerable > def altmap(meth=:each) > res = [] > send(meth) { |*args| res << yield(*args) } > res > end > end P.S. I note that some Enumerable methods already take arguments: detect/find, grep, inject could have meth=:each as a later argument for backwards-compatibility. The only awkward ones are to_set and zip. Even then, they could be made backwards-compatible by checking if the first argument is a Symbol and using it as a method name in that case. I don't really see the usefulness of the foo.to_set(klass,*args) syntax anyway, given that it just calls klass.new(foo,*args). However, I can see uses for h.to_set(:each_key) h.to_set(:each_value) Regards, Brian.