Is there a less accurate way to compare three integer values in Ruby?
For example, in Python, the following return True:
x = 2
y = 3
z = 4
x < y < z
With the same variable bindings in Ruby, the following returns both values:
x < y && y < z
x.send(:<, y) && y.send(:<, z)
but this:
x < y < z
returns NoMethodError:
NoMethodError: undefined method `<' for true:TrueClass
I assume that this is due to the fact that the first comparison x < yis evaluated as true, and the error arises from the received TrueClass.instance < z? Is there any way in Ruby to compare three integer values without using & &?
Thank.
source
share