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
The first two,
false are just what you think they are:
true represents “truth”, while
represents the opposite of it.
In other words, in Ruby,
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.
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.