From: William James Date: 2009-02-12T09:38:44+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. Always remember: "We don't need no stinkin' loops!" a=[:a,:b,:c] ==>[:a, :b, :c] Hash[ *(0...a.size).zip(a).flatten ] ==>{0=>:a, 1=>:b, 2=>:c}