number_comparison
🔍 Comparing Numbers
Use comparison operators to compare numeric values: greater than (>
), less than (<
), equal (==
), not equal (!=
), and the spaceship operator (<=>
) which returns -1
, 0
, or 1
.
a = 5
b = 8
puts a > b # => false
puts a < b # => true
puts a == b # => false
puts a != b # => true
puts a <=> b # => -1 # a is less than b