From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-07-22T01:23:07+09:00 Subject: Re: Proposal: Array#to_h, to simplify hash generation On Tue, 22 Jul 2003 00:59:50 +0900, Brian Candler wrote: > Can I suggest another name - "collect_hash" - since that's basically what it > is? 'collect_hash' sounds nice p [1, 2, 3].collect_hash { |i| i, "f(#{i})" } #=> {1=>"f(1)", 2=>"f(3)", 3=>"f(3)"} Other possible names (less great): * build_hash * make_hash * to_hash * map_hash * combine(_to_hash) May I suggest a Enum#build routine, working like this pseudo code [1, 2, 3].build(Hash) { |i| i, f(i) } #=> {1=>"f(1)", 2=>"f(3)", 3=>"f(3)"} [1, 2, 3].build(String) { |i| i.class } #=> "FixnumFixnumFixnum" [1, 2, 3].build(Array) { |i| Regex.new(i.to_s) } #=> [/1/, /2/, /3/] Is this madness, appending elements this way ? Especialy will this work for hash ? -- Simon Strandgaard