title: Ruby Hash transpose
body: <p>I have the following ruby hash:</p>
  
  <pre><code> h = { i1: { q1: 1, q2:2 }, i2: { q1: 3, q2: 4} }
  </code></pre>
  
  <p>and I want to transpose it as follows:</p>
  
  <pre><code>{ q1: { i1: 1, i2: 3 }, q2: { i1: 2, i2: 4 } }
  </code></pre>
  
  <p>Now, I came up with a function that does what I want,
  but I wonder if there is a more succinct/elegant way for the same thing?   </p>
  
  <p>My solution:</p>
  
  <pre><code> ht = Hash.new{ |h,k| h[k] = {} }
  
   h.each_pair do |k,ih| 
     ih.each_pair{ |ik, iv| ht[ik][k] = iv }
   end
  </code></pre>