title: How do I remove specific 'nil' values from a ruby hash?
body: <p>Consider the following hash:</p>
  
  <pre><code>H = {"a" =&gt; 100, "b" =&gt; 200, "c" =&gt; nil, "d" =&gt; nil}
  </code></pre>
  
  <p>I want to preserve the <code>nil</code> value with <code>"c"</code>, and remove the <code>nil</code> value with <code>"d"</code>. How can I do that?</p>
  
  <p>Applying <code>compact</code> will remove all <code>nil</code> values (i.e., with keys <code>"c"</code> and <code>"d"</code>).</p>
  
  <p>Question <a href="https://stackoverflow.com/questions/3450641/removing-all-empty-elements-from-a-hash-yaml">Removing all empty elements from a hash / YAML?</a> addresses this issue, but I thought there could have been a function equivalent to <code>.compact</code>.</p>