title: Ruby Merge Two Hashes With Selective Overwrite
body: <p>I have two different hashes with same keys:</p>
  
  <pre><code>a = {"word"=&gt;"phileas", "character"=&gt;1, "location"=&gt;0, "adjective"=&gt;0, "noun"=&gt;1}
  b = {"word"=&gt;"phileas", "character"=&gt;0, "location"=&gt;1, "adjective"=&gt;1, "noun"=&gt;0}
  </code></pre>
  
  <p>And I want to merge these two hashes into following format:</p>
  
  <pre><code>a = {"word"=&gt;"phileas", "character"=&gt;1, "location"=&gt;1, "adjective"=&gt;1, "noun"=&gt;1}
  </code></pre>
  
  <p>I tried this code:</p>
  
  <pre><code>a.update(b){|key,oldval,newval| !oldval.is_a?(String)  ? oldval | newval :  oldval+newval}
  </code></pre>
  
  <p>But it gave me the following:</p>
  
  <pre><code>{"word"=&gt;"phileasphileas", "character"=&gt;0, "location"=&gt;1, "adjective"=&gt;1, "noun"=&gt;0}
  </code></pre>
  
  <p>The problem is I cannot create a condition on String value. When it merges, it merges the String value as well. I want String value remain and merge the rest. If the other values are bigger than 0, I want that value to remain. You can think these values as boolean or flag.</p>