How to merge two arrays of hashes by the same pair of key and value ruby
<p>I'm new in ruby. I have two hashes:</p>

<pre><code>f = { "server"=&gt;[{ "hostname"=&gt;"a1", "ip"=&gt;"10" }, {"hostname"=&gt;"b1", "ip"=&gt;"10.1" }] }
g = { "admin" =&gt;[{ "name"=&gt;"adam", "mail"=&gt;"any", "hostname"=&gt;"a1" },
                 { "name"=&gt;"mike", "mail"=&gt;"id", "hostname"=&gt;"b1"}]}
</code></pre>

<p>and I want to get another hash like this:</p>

<pre><code>{ "data" =&gt; [{"hostname"=&gt;"a1", "ip"=&gt;"10", "name" =&gt;"adam", "mail"=&gt;"any"},
             {"hostname"=&gt;"b1", "ip"=&gt;"10.1", "name" =&gt;"mike", "mail"=&gt;"id"}]}
</code></pre>

<p>The pairs <code>"hostname"=&gt;"something"</code> always matches in hashes of both arrays. I have tried something like this:</p>

<pre><code>data = server.merge(admin)
</code></pre>

<p>but it isn't so easy and as you expect it doesn't work. Could you help me merge these hashes and explain for the future how you did it?</p>