Recall & Review
beginner
What are the three special values used to represent truthiness and absence in Ruby?
They are
true (for truth), false (for falsehood), and nil (for 'nothing' or 'no value').Click to reveal answer
beginner
In Ruby, which values are considered false in conditional statements?
Only
false and nil are treated as false. Everything else is true, including 0 and empty strings.Click to reveal answer
beginner
What does
nil represent in Ruby?nil means 'no value' or 'nothing here'. It is Ruby's way to say a variable or expression has no meaningful value.Click to reveal answer
beginner
How do you check if a variable is
nil in Ruby?You can use the method
.nil? like variable.nil? which returns true if the variable is nil.Click to reveal answer
intermediate
What is the difference between
false and nil in Ruby?false means explicitly false, while nil means no value or absence of value. Both behave as false in conditions but have different meanings.Click to reveal answer
Which of these values is NOT considered false in Ruby?
✗ Incorrect
In Ruby, only false and nil are false. The number 0 is considered true.
What does
nil represent in Ruby?✗ Incorrect
nil means no value or absence of value in Ruby.
How can you check if a variable
x is nil?✗ Incorrect
The method .nil? returns true if the variable is nil.
Which of these is a Boolean value in Ruby?
✗ Incorrect
true and false are Boolean values. nil is a special value meaning no value.
In Ruby, what will the expression
if nil then 'yes' else 'no' end return?✗ Incorrect
Since nil is treated as false, the else branch runs, returning 'no'.
Explain the role of
true, false, and nil in Ruby and how they behave in conditions.Think about how Ruby decides if something is true or false in an if statement.
You got /5 concepts.
Describe how to check if a variable is
nil and why this might be useful.Consider how you know if a box is empty or not.
You got /4 concepts.