0

I have a simple bit of code running inside a rails model.

num = 3
result = num == 0 or num == 2 or num == 3

The result in the above statement should be evaluated to true. But for some reason rails evaluate this to be false when the method is called from the a rails view.

Just to confirm that it is an issue with rails when used with a view, I used the rails console to evaluate the exact same code. the rails console correctly evaluated that statement to true.

Rails Version: 5.1.7
Ruby Version: 2.6.5-p114

Thanks

mu is too short
  • 426,620
  • 70
  • 833
  • 800
demhareesan
  • 49
  • 1
  • 8
  • 4
    The `or` operator has a lower precedence - see https://stackoverflow.com/questions/2083112/difference-between-or-and-in-ruby – red_menace Oct 30 '20 at 20:47
  • 2
    It is generally a good idea to pretend that Ruby doesn't have `and`, `or`, and `not` operators, their precedence tends to cause a lot of confusion and problems. Use `&&`, `||`, and `!` instead and there will be less confusion. – mu is too short Oct 30 '20 at 20:54

0 Answers0