title: Duplicate hash into independent hash (shallow copy)
body: <p>What is the best way to duplicate a hash in Ruby, and have it independent from the original? For example:</p>
  
  <pre><code>a = { foo1: "bar1" }
  b = a # or b = a.clone / b = a.dup for that matter
  b[:foo2] = "bar2"
  </code></pre>
  
  <p>This results in:</p>
  
  <pre><code>{:foo1=&gt;"bar1", :foo2=&gt;"bar2"} # a
  {:foo1=&gt;"bar1", :foo2=&gt;"bar2"} # b
  </code></pre>
  
  <p>Where I would like it to be</p>
  
  <pre><code>{:foo1=&gt;"bar1"}                # a
  {:foo1=&gt;"bar1", :foo2=&gt;"bar2"} # b
  </code></pre>
  
  <p>Now I know about <code>b = Marshal.load(Marshal.dump(a))</code> but that seems like a little overkill, and I was wondering if there is a better way, because I can't really find it.</p>