What would be the most the concise way to express the following in Ruby:
Is x more, less or equal to the value y?
What would be the most the concise way to express the following in Ruby:
Is x more, less or equal to the value y?
Do as below using spaceship operator(<=>) :
Returns 0 if obj and other are the same object or obj
==other, otherwisenil.The
<=>is used by various methods to compare objects, for exampleEnumerable#sort,Enumerable#maxetc.Your implementation of
<=>should return one of the following values:-1, 0, 1ornil.-1meansselfis smaller than other. 0 means self is equal to other.1meansselfis bigger than other.Nilmeans the two values could not be compared.
x <=> y