title: Iterate nested hash that contains hash and/or Array
body: <p>I have a hash, I am trying to extract the keys and values for it. The hash has a nested hash and/or array of hashes.</p>
  
  <p>After checking this site and few samples I got the key and values. But having difficulty in extracting if its a array of hashes.</p>
  
  <p>Example:</p>
  
  <pre><code>{
    :key1 =&gt; 'value1',
    :key2 =&gt; 'value2',
    :key3 =&gt; {
      :key4 =&gt; [{:key4_1 =&gt; 'value4_1', :key4_2 =&gt; 'value4_2'}],
      :key5 =&gt; 'value5'
    },
    :key6 =&gt; {
      :key7 =&gt; [1,2,3],
      :key8 =&gt; {
        :key9 =&gt; 'value9'
      }
    }
  }
  </code></pre>
  
  <p>So far I have below code from <a href="https://stackoverflow.com/questions/9279768/how-do-i-loop-over-a-hash-of-hashes-in-ruby">how do i loop over a hash of hashes in ruby</a> and <a href="https://stackoverflow.com/questions/8748475/iterate-over-an-deeply-nested-level-of-hashes-in-ruby?rq=1">Iterate over an deeply nested level of hashes in Ruby</a></p>
  
  <pre><code>def ihash(h)
    h.each_pair do |k,v|
      if v.is_a?(Hash) || v.is_a?(Array)
        puts "key: #{k} recursing..."
        ihash(v)
      else
        # MODIFY HERE! Look for what you want to find in the hash here
        puts "key: #{k} value: #{v}"
      end
    end
  end
  </code></pre>
  
  <p>But it fails at <code>v.is_hash?(Array)</code> or <code>v.is_a?(Array)</code>.</p>
  
  <p>Am I missing something?</p>