From: William James Date: 2009-02-12T16:08:46+09:00 Subject: Re: Array#to_hash Trans wrote: > Would any problems arise from extending Array with this? > > # Convert an array into an indexed hash. > # > # [:a,:b,:c].to_hash #=> {0=>:a,1=>:b,2=>:c} > # > def to_hash > h = {} > each_with_index do |v, i| > h[i] = v > end > h > end > > Thanks, > T. a = [:a,:b,:c] ==>[:a, :b, :c] h = a.to_hash ==>{0=>:a, 1=>:b, 2=>:c} a[2] ==>:c h[2] ==>:c Wow! That *is* a big improvement!