`-': nil can't be coerced into Fixnum (TypeError)

前端 未结 1 948
执念已碎
执念已碎 2020-12-19 06:43

In my program Im getting an error which says ./ruby_camping.rb:91:in `-\': nil can\'t be coerced into Fixnum (TypeError). What I would like to do is to checkout a guest that

相关标签:
1条回答
  • 2020-12-19 07:44

    To get a more detailed answer, you would have to indicate which line was line 91 in your program. However to point you in the right direction, if you're seeing nil can't be coerced into Fixnum then it means something on the right hand side of a - is nil. e.g.

    irb(main):001:0> 5 - nil
    TypeError: nil can't be coerced into Fixnum
            from (irb):1:in `-'
            from (irb):1
    

    From your code the only possible example of this I can see is guestStayedDays = departureDate - guest.arrived so I would check the value of guest.arrived.

    If something on the left hand side of a - were nil e.g. departureDate or plot then you would get undefined method '-' for nil:NilClass instead.

    0 讨论(0)
提交回复
热议问题