I have absolutely no experience in Ruby, but am trying to debug an issue in FPM. Sometimes, when running FPM, I get the following stack trace:
output': undefined method `empty?' for nil:NilClass (NoMethodError)
I traced this error back to this line (rpm.rb, line 419):
if @epoch.nil? or @epoch.empty?
@logger.warn("no value for epoch is set, defaulting to nil")
return nil
end
This blog post says the following about the or
operator:
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
This leads me to believe that in the above code fragment, if epoch.nil?
evaluates to true, it will not attempt to check epoch.empty?
, but a simple codepad shows that to be wrong (http://codepad.org/qI7rLvBX)
str = nil
puts str.nil? or str.empty?
Output:
Line 2: undefined method `empty?' for nil:NilClass (NoMethodError)
true
if I change it the operator to ||
, then the short-circuiting works correctly - if epoch.nil?
evaluates to true, it does not attempt to evaluate epoch.empty?
.
Am I misunderstanding something about the or
operator? And is the way FPM is checking for nil or empty incorrect?