From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-07-22T02:24:35+09:00 Subject: Re: Proposal: Array#to_h, to simplify hash generation On Tue, 22 Jul 2003 02:57:40 +0900, Brian Candler wrote: > On Tue, Jul 22, 2003 at 01:43:46AM +0900, Brian Candler wrote: >> The bit I don't like is Hash#<< taking an array of two elements, rather than >> having two arguments > > I forgot about using Method#arity. New version attached... Brian. > > class Array # ditto for Enumerable > def collect(dest=Array,*args) > res = dest.new(*args) Maybe its better to do the #new outside collect ? Like this: [1, 2, 3].collect(String.new("Test: ")) { |i| i.class } # "Test: FixnumFixnumFixnum" res = Hash.new def f(v) v*v; end [1, 2].map(res) {|i| [i, f(i)] } [3, 4].map(res) {|i| [i, f(i-2)] } p res # print the accumulated result # {1=>1, 2=>4, 3=>1, 4=>4} Accumulating is good :-) -- Simon Strandgaard