comparison of Fixnum with nil failed

12,736

Solution 1

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

Solution 2

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

Is a_condition nil perhaps?

Solution 3

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.

Share:
12,736
shajin
Author by

shajin

Genius In Wrong Way :D

Updated on June 05, 2022

Comments

  • shajin
    shajin almost 2 years

    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.

    • shajin
      shajin almost 13 years
      Sorry 4 that bad question..a newbie.. :) :)
  • sawa
    sawa almost 13 years
    What is your code for? I don't see any difference from the one in the question.