True, False, and Nil

There are three more “things” that we’d like to mention quickly, just because you’ll see quite frequently: These are true, false, and nil.

The first two, true and false are just what you think they are:

The object true represents “truth”, while false represents the opposite of it.

In other words, in Ruby, true and false are also “things”, just like numbers, Strings, Arrays, and Hashes. You can assign them to variables, pass them around, and otherwise use them. They’re fairly simple things, but they’re also very useful.

The third object nil represents “nothing”. Yeah, that’s right. In Ruby there’s a “thing” that represents the absence of things. This might be a interesting topic to discuss on a philosophical level, but for now we’ll just see how it works in Ruby.

The object nil represents “nothing”.

You’ll see later that every operation (“method”) in Ruby always returns exactly one thing (i.e. one object), and that’s why there needs to be a “thing” that represents “nothing”.

This will start to feel pretty natural to you pretty soon.