title: how to fetch values in hash array ruby
body: <p>i have written small ruby code to get publish stats, code is following</p>
  
  <pre><code>begin
    response = conn.get("api/queues")
    statistics = JSON.parse(response.body)
  
    statistics.each do |qDetails|
      payload = "#{qDetails["name"]}"
      if payload != "aliveness-test"
        puts "#{qDetails["message_stats"]["publish"]}"          
      end             
    end      
  rescue Faraday::Error::ConnectionFailed =&gt; e
    puts "Connection failed"
  end
  </code></pre>
  
  <p>but i get this error in return </p>
  
  <pre><code>undefined method `[]' for nil:NilClass (NoMethodError)
  </code></pre>
  
  <p>message_stats json would be like this </p>
  
  <pre><code>{"deliver_get_details"=&gt;{"rate"=&gt;0.0}, "deliver_get"=&gt;1357, "ack_details"=&gt;{"rate"=&gt;0.0}, "ack"=&gt;1357, "redeliver_details"=&gt;{"rate"=&gt;0.0}, "redeliver"=&gt;0, "deliver_no_ack_details"=&gt;{"rate"=&gt;0.0}, "deliver_no_ack"=&gt;0, "deliver_details"=&gt;{"rate"=&gt;0.0}, "deliver"=&gt;1357, "get_no_ack_details"=&gt;{"rate"=&gt;0.0}, "get_no_ack"=&gt;0, "get_details"=&gt;{"rate"=&gt;0.0}, "get"=&gt;0, "publish_details"=&gt;{"rate"=&gt;0.0}, "publish"=&gt;1400}
  </code></pre>
  
  <p>what's the issue?</p>