开发者

comparison of Fixnum with nil failed

开发者 https://www.devze.com 2023-03-13 08:01 出处:网络
I coded like this, @claim = Item.find(:something) unless @claim.nil? if @claim >= a_condition do_something

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 wr开发者_运维问答ong in my code.


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


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

Is a_condition nil perhaps?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消