The == and eql? return true or false : Comparison Operators « Language Basics « Ruby






The == and eql? return true or false


# the <=> (spaceship operator) returns -1, 0, or 1, 
# depending on whether the first value is equal to the second (0), 
# less than the second (-1), or greater than the second (1).

# Test if two numbers are equal, less than, or greater than each other

puts 12 < 14 #less than
puts 12 < 12
puts 12 <= 12 # less than or equal to
puts 12.0 > 11.9
puts 12.0 >= 12 # greater than or equal to

 








Related examples in the same category

1.A Full List of Number Comparison Operators in Ruby
2.Comparison Operators and Expressions
3.Comparable module uses the <=> operator on the class that includes it.
4.Equality, Less Than, or Greater Than