shajin
shajin

Reputation: 3264

comparison of Fixnum with nil failed

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

Answers (3)

sepp2k
sepp2k

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

Joshua Scott
Joshua Scott

Reputation: 663

@claim = Item.find(:something)
unless @claim.nil?
  if @claim >= a_condition
    do_something 
  end
end

Is a_condition nil perhaps?

Upvotes: 3

cam
cam

Reputation: 14222

a_condition is probably the nil value that you are failing on.

Upvotes: 8

Related Questions