I am using the following code to check if a variable is not nil and not zero
if(discount != nil && discount != 0) ... end
Is the
You can take advantage of the NilClass provided #to_i method, which will return zero for nil values:
NilClass
#to_i
nil
unless discount.to_i.zero? # Code here end
If discount can be fractional numbers, you can use #to_f instead, to prevent the number from being rounded to zero.
discount
#to_f