title: Converting a hash-inside-array to single key multiple value hash in ruby
body: <p>I am trying to load data from redis db. I have a api only rails app and trying to render the json data as per requirement. 
  Currently I am able to <code>get</code> the data from redis in the following format.</p>
  
  <pre><code>[
   {
    "id": 1,
    "name": "Stephenie Meyer",
    "created_at": "2018-04-17T07:40:50.417Z",
    "updated_at": "2018-04-17T07:40:50.417Z"
   },
   {
    "id": 2,
    "name": "V.C. Andrews",
    "created_at": "2018-04-17T07:40:50.613Z",
    "updated_at": "2018-04-17T07:40:50.613Z"
   },
   {
    "id": 3,
    "name": "Sophie Kinsella",
    "created_at": "2018-04-17T07:40:50.646Z",
    "updated_at": "2018-04-17T07:40:50.646Z"
   }
  ]
  </code></pre>
  
  <p>How can convert this in a way such that the key value pairs  of <code>name</code>,<code>created</code> and <code>updated</code> will be hash to a <code>id</code> key-value pair.</p>
  
  <p>Into this</p>
  
  <pre><code> {"id": 1,
      {
        "name": "Stephenie Meyer",
        "created_at": "2018-04-17T07:40:50.417Z",
        "updated_at": "2018-04-17T07:40:50.417Z"
      }
   }
  </code></pre>
  
  <p>helper method for getting redis data.</p>
  
  <pre><code>def fetch_authors
      authors = $redis.get('authors')
      if authors.nil?
        authors = Author.all.to_json
        $redis.set("authors", authors).to_json
        $redis.expire("authors", 5.hour.to_i)
      end
      JSON.load authors
  end
  </code></pre>
  
  <p>And displaying on index page using </p>
  
  <pre><code>def index
      @authors = fetch_authors
      render json: @authors
    end
  </code></pre>