Comparators aren’t the only operators available to you in Ruby. You can also use logical or boolean operators. Ruby has three: and (
&&), or (
||), and not (
!). Boolean operators result in boolean values:
The boolean operator and,
&&, only results in
true when both expression on either side of
true. Here’s how
true && true # => true true && false # => false false && true # => false false && false # => false
1 < 2 && 2 < 3 is
true because it’s true that one is less than two and that two is less than three.
Let’s practice a bit with
&&. Check out the boolean expressions and set each variable to
false depending on what value you expect the expression to return.