CHAPTER 7

image

Booleans

Booleans within Ruby are actually known as parts of the TrueClass and FalseClass, rather than a Boolean Data Type as such. It is worth noting that nil (Ruby's version of a null) is not a Boolean.

2.1.1 :001 > true.class => TrueClass2.1.1 :002 > false.class => FalseClass

Creating Boolean Values

Creating a Boolean value within Ruby is similar to creating a String/Numeric value. You simply set a variable to the value required (true or false):

2.1.1 :001 > test = true => true2.1.1 :002 > puts testtrue => nil2.1.1 :003 > test.class => TrueClass

Expression Tests

Within Ruby a number of expression tests return a Boolean value; which ...

Get Ruby Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.