Reputation: 3264
I coded like this,
@claim = Item.find(:something)
unless @claim.nil?
if @claim >= a_condition
do_something
end
end
Even if @claim is a nil value,It is going inside the unless condition and giving the error "comparison of Fixnum with nil failed"
What is the wrong in my code.
Upvotes: 2
Views: 13315
Reputation: 370112
Using the code you posted, the inside of the unless
statement will definitely not execute if @claim
is nil. If you get the error message you posted on line 3 of that code, it must be because a_condition
is nil, not @claim
.
Upvotes: 3
Reputation: 663
@claim = Item.find(:something)
unless @claim.nil?
if @claim >= a_condition
do_something
end
end
Is a_condition
nil perhaps?
Upvotes: 3