From: franco Date: 2007-09-18T10:35:04+09:00 Subject: Re: Is there a select and map for hashes instead of arrays? # use two vars in an map/select block (or use the index if one var) array = {:a => 1, :b =>2}.select {|k,v| k == :b} # => [[:b, 2]] # use inject to make a hash from a list, this is a great technique hash = array.inject({}) {|h,e| h.merge({e[0] => e[1]}) } # => {:b=>2} -franco On Sep 17, 6:05 pm, Jeff wrote: > Hash#select and Hash#map return arrays. In some cases I want to get > hashes back instead. > > I can take the returned arrays and transform them back into hashes, > but it would be nice to avoid the extra step. > > Plus, it just surprised me that #select and #map aren't overridden for > Hash to return new Hashes instead of arrays. > > Am I missing something? > > Jeff