Ruby Booleans and Comparison
true and false are objects. Only nil and false are falsy. Comparisons: == != < > <= >= and <=> which returns -1, 0 or 1. && || ! and and/or/not combine.
Example
puts 5 > 3, 5 == 5.0, 5.eql?(5.0)
puts 1 <=> 2
puts (true && !false)
puts 0 ? "0 is truthy" : "0 is falsy"Result
true true false -1 true 0 is truthy
Exercise
Spaceship operator.
1 2
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.