In this article, we will cover boolean values in Ruby and go over examples that will make things about booleans a little more clear.
What is a boolean?
A boolean is a value used in logic statements to figure out if something is considered true or false.
There are a few methods in Ruby that will return true or false, such as
== → keep in mind that this operator is actually a method in Ruby and can change depending on in what context the method is implemented. There are also
truthy and falsy values, a truthy value is always true, anything in Ruby is truthy except
nil and they are the only values that are falsy.
I am sure you have seen methods ending with a question mark in Ruby before. Those methods are called predicate methods and by convention, they will always return true or false. We use this method to find out information about an object. These methods can be written something like this:
Boolean methods help us find out things about objects to make decisions. They are important to understand to make the code more cleaner. Remember that
nil are the only things that are “falsy” in Ruby; otherwise, everything else is “truthy”