Boolean Operators
As we know, Booleans tell us whether a value or condition is true
and false
. We can work with Booleans using the following three operators:
- AND
- OR
- NOT
The AND Operator
In Ruby, the AND operator is represented by a double ampersand, &&
. It represents what the truthiness is across two values if both are true
. Consider the following sample code snippet:
var1 = true var2 = true var1 && var2 var1 = false var2 = true var1 && var2 var1 = false var2 = false var1 && var2
The output should look like this:
In the preceding example, the var1
and var2
variables depict true
and false
Boolean states in different combinations and the &&
operator gives results as per the combination.
The OR Operator
In Ruby, the OR operator is represented by a double pipe, ||
. It represents what the truthiness is across two values if one is true
. Consider...