Comparable module uses the <=> operator on the class that includes it. : Comparison Operators « Language Basics « Ruby






Comparable module uses the <=> operator on the class that includes it.


<=> returns -1 if the supplied parameter is higher than the object's value, 
            0 if they are equal, or 
            1 if the object's value is higher than the parameter.

puts 1 <=> 2
puts 1 <=> 1
puts 2 <=> 1

 








Related examples in the same category

1.A Full List of Number Comparison Operators in Ruby
2.Comparison Operators and Expressions
3.Equality, Less Than, or Greater Than
4.The == and eql? return true or false