title: Checking if variable is nil or empty in a single line using or operator
body: <p>I have absolutely no experience in Ruby, but am trying to debug an issue in <a href="https://github.com/jordansissel/fpm" rel="nofollow">FPM</a>. Sometimes, when running FPM, I get the following stack trace:</p>
  
  <pre><code>output': undefined method `empty?' for nil:NilClass (NoMethodError)
  </code></pre>
  
  <p>I traced this error back to this line (<a href="https://github.com/jordansissel/fpm/blob/master/lib/fpm/package/rpm.rb#L419" rel="nofollow">rpm.rb, line 419</a>):</p>
  
  <pre><code>if @epoch.nil? or @epoch.empty?
     @logger.warn("no value for epoch is set, defaulting to nil")
     return nil
  end
  </code></pre>
  
  <p><a href="http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/" rel="nofollow">This blog post</a> says the following about the <code>or</code> operator:</p>
  
  <blockquote>
    <p>The best way to think about the chains constructed with or is as
    series of fallbacks: try this, if that fails try this, and so on</p>
  </blockquote>
  
  <p>This leads me to believe that in the above code fragment, if <code>epoch.nil?</code> evaluates to true, it will not attempt to check <code>epoch.empty?</code>, but a simple codepad shows that to be wrong (<a href="http://codepad.org/qI7rLvBX" rel="nofollow">http://codepad.org/qI7rLvBX</a>)</p>
  
  <pre><code>str = nil
  puts str.nil? or str.empty?
  
  Output:
  Line 2: undefined method `empty?' for nil:NilClass (NoMethodError)
  true
  </code></pre>
  
  <p>if I change it the operator to <code>||</code>, then the short-circuiting works correctly - if <code>epoch.nil?</code> evaluates to true, it does not attempt to evaluate <code>epoch.empty?</code>.</p>
  
  <p>Am I misunderstanding something about the <code>or</code> operator? And is the way FPM is checking for nil or empty incorrect?</p>