0
0
Rubyprogramming~5 mins

Boolean values (true, false, nil) in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A0
Bnil
Cfalse
Dfalse and nil
What does nil represent in Ruby?
ANo value or absence
BFalse value
CTrue value
DZero number
How can you check if a variable x is nil?
Ax == false
Bx == true
Cx.nil?
Dx == 0
Which of these is a Boolean value in Ruby?
Anil
Btrue
C0
D"false"
In Ruby, what will the expression if nil then 'yes' else 'no' end return?
A'yes'
Berror
Cnil
D'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.