Search code examples
ruby

Checking if a variable is not nil and not zero in ruby


I am using the following code to check if a variable is not nil and not zero

if(discount != nil && discount != 0) 
  ...
end

Is there a better way to do this?


Solution

  • unless discount.nil? || discount == 0
      # ...
    end