title: How to transform array of hashes to hash object with keys from values?
body: <p>How to create hash object with keys created from values and grouped by them?</p>
  
  <pre><code>cars = [{
    id: 1,
    properties: {
      name: "audi",
      type: "petrol"
    },
  },{
    id: 1,
    properties: {
      name: "ford",
      type: "petrol"
    }
  },{
    id: 1,
    properties: {
      name: "tesla",
      type: "electric"
    }
  }]
  </code></pre>
  
  <p>Desired effect:</p>
  
  <pre><code>{
    petrol: [{name: "audi"}, {name: "ford"}],
    electric: [{name: "tesla"}]
  }
  </code></pre>
  
  <p>My current function gives desired effect but it is too long, How can I get the same effect with shorter code?</p>
  
  <pre><code>cars.map { |c| Hash[c[:properties][:type], c[:properties][:name]] }.group_by{|h| h.keys.first}.each_value{|a| a.map!{|h| h.values.first}}
  </code></pre>