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 empty?, all? and match? /or == → 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 false and nil and they are the only values that are falsy.

Boolean Methods

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 false and nil are the only things that are “falsy” in Ruby; otherwise, everything else is “truthy”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store