Partition array to hash in ruby
I would go with the chunk method:

cars.chunk { |c| c[:speed]&gt;320 ? :above_320 : :the_rest }.to_h


Though it's important to underline that chunk doesn't work if the array is not ordered (by speed in this case). In that case we need to prepend it with sort_by:

cars.sort_by {|car| car[:speed]}.chunk { |c| c[:speed]&gt;320 ? :above_320 : :the_rest }.to_h


(Moreover, if we want to order the hash keys, like in the example, we need to call sort after chunk):

cars.sort_by {|car| car[:speed]}.chunk { |c| c[:speed]&gt;320 ? :above_320 : :the_rest }.sort.to_h