Search⌘ K

Challenge 1: Checking Truthiness

Explore how Ruby handles truthiness and equivalence by testing various objects in a practical coding challenge. Learn to interpret boolean evaluation results with the double negation operator to deepen your understanding of Ruby's conditional behavior.

We'll cover the following...

Problem statement

This exercise is about validating what we’ve learned about truthiness, and printing the results in a tabular form.

Consider the following array:

objects = [true, false, nil, 0, 1, "", []]

Add some code so that it outputs the following table:

object                     | !!object
true                       | [true|false]
false                      | [true|false]
nil                        | [true|false]
0                          | [true|false]
1                          | [true|false]
""                         | [true|false]
[]                         | [true|false]

Note: The last column should be filled in with either true or false, depending on what the !!object operation, which is the same as not not object, returns for each of the objects.

Try it yourself

UserCode
Solution
puts "object\t| !!object"
objects = [true, false, nil, 0, 1, "", []]
# Start your code here