title: Converting an empty string to nil in place?
body: <p>I'm looking for a way to convert an empty string to <code>nil</code> in place using Ruby.  If I end up with a string that is empty spaces I can do</p>
  <pre><code> &quot;    &quot;.strip!
  </code></pre>
  <p>This will give me the empty string <code>&quot;&quot;</code>.</p>
  <p>What I would like to be able to do is something like this.</p>
  <pre><code>&quot;    &quot;.strip!.to_nil!
  </code></pre>
  <p>This will get an in place replacement of the empty string with <code>nil</code>.  <code>to_nil!</code> would change the string to <code>nil</code> directly if it is <code>.empty?</code> otherwise if the string is not empty it would not change.</p>
  <p>The key here is that I want it to happen directly rather than through an assignment such as</p>
  <pre><code>f = nil if f.strip!.empty?
  </code></pre>