title: How to clone array of hashes and add key value using each loop
body: <p>I want to clone an array of hashes and then to clone it into more than one. </p>
  
  <pre><code>irb(main):001:0&gt; arr = [{a: "one", b: "two"}, {a: "uno", b: "due"}, {a: "en", b: "to"}]
  =&gt; [{:a=&gt;"one", :b=&gt;"two"}, {:a=&gt;"uno", :b=&gt;"due"}, {:a=&gt;"en", :b=&gt;"to"}]
  irb(main):002:0&gt; arr_1 = arr.clone
  =&gt; [{:a=&gt;"one", :b=&gt;"two"}, {:a=&gt;"uno", :b=&gt;"due"}, {:a=&gt;"en", :b=&gt;"to"}]
  irb(main):003:0&gt; arr_2 = arr.clone
  =&gt; [{:a=&gt;"one", :b=&gt;"two"}, {:a=&gt;"uno", :b=&gt;"due"}, {:a=&gt;"en", :b=&gt;"to"}]
  </code></pre>
  
  <p>Dynamically I want to add <code>id</code> into the hashes.</p>
  
  <pre><code>irb(main):004:0&gt; arr_1.each { |k| k[:id] = 1 }
  =&gt; [{:a=&gt;"one", :b=&gt;"two", :id=&gt;1}, {:a=&gt;"uno", :b=&gt;"due", :id=&gt;1}, {:a=&gt;"en", :b=&gt;"to", :id=&gt;1}]
  irb(main):005:0&gt; arr_2.each { |k| k[:id] = 2 }
  =&gt; [{:a=&gt;"one", :b=&gt;"two", :id=&gt;2}, {:a=&gt;"uno", :b=&gt;"due", :id=&gt;2}, {:a=&gt;"en", :b=&gt;"to", :id=&gt;2}]
  </code></pre>
  
  <p>But the result of <code>arr_1</code>'s <code>id</code> is affected by <code>arr_2</code> each loop operation which is become <code>2</code></p>
  
  <pre><code>irb(main):006:0&gt; arr_1
  =&gt; [{:a=&gt;"one", :b=&gt;"two", :id=&gt;2}, {:a=&gt;"uno", :b=&gt;"due", :id=&gt;2}, {:a=&gt;"en", :b=&gt;"to", :id=&gt;2}]
  </code></pre>
  
  <p>I have tried by using </p>
  
  <pre><code>arr_1 = arr
  arr_2 = arr
  </code></pre>
  
  <p>but the result keeps showing the same result.<br>
  How to make the <code>arr_1</code> hashes <code>:id = 1</code> and <code>arr_2</code> hashes <code>:id = 2</code> ? </p>