title: Ruby: How to check whether a string isn't blank?
body: <p>In my app I want to prevent a variable from being blank — e.g., a user’s name should be something other than spaces and other whitespace. It will work like this:</p>
  
  <pre class="lang-rb prettyprint-override"><code>foobar = gets.strip
  arr = []
  if # the string in the variable 'foobar' isn't blank
      arr.push(foobar)
  end
  </code></pre>
  
  <p>Rails adds <code>blank?</code> method to class <code>String</code>, so that <code>"".blank?</code>, <code>"    ".blank?</code>, and <code>nil.blank?</code> are all <code>true</code>. Ruby has similar <code>empty?</code> method, but it differs from <code>blank?</code>, as we can see in the example below (this won’t work in plain <code>irb</code>):</p>
  
  <pre class="lang-rb prettyprint-override"><code>&gt;&gt; "      ".empty?
  =&gt; false
  &gt;&gt; "      ".blank?
  =&gt; true
  </code></pre>
  
  <p>We see that a string of spaces is not empty, but it is blank.</p>
  
  <p>Your solutions?</p>
  
  <p>P.S. I gonna do this in pure Ruby, not in Rails.</p>