-
Book Overview & Buying
-
Table Of Contents
The Ruby Workshop
By :
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:
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:
Figure 3.1: Output for the Boolean AND operator
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.
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...
Change the font size
Change margin width
Change background colour