Recall & Review
beginner
What are the only falsy values in Ruby?
In Ruby, only
false and nil are falsy. Everything else is truthy.Click to reveal answer
beginner
Is the number 0 truthy or falsy in Ruby?
The number
0 is truthy in Ruby, unlike some other languages where it might be falsy.Click to reveal answer
beginner
What will this Ruby code print?<br>
if nil puts 'Yes' else puts 'No' end
It will print
No because nil is falsy in Ruby.Click to reveal answer
intermediate
Why does Ruby treat only
false and nil as falsy?Ruby's design makes it simple: only
false and nil mean 'no' or 'nothing'. Everything else counts as 'yes' or 'something'.Click to reveal answer
intermediate
How can understanding truthy and falsy values help you write better Ruby code?
Knowing which values are truthy or falsy helps you write clear conditions and avoid bugs, especially in
if statements and loops.Click to reveal answer
Which of these is falsy in Ruby?
✗ Incorrect
Only
nil and false are falsy in Ruby. All others, including 0, empty strings, and empty arrays, are truthy.What does this code print?<br>
puts false ? 'Yes' : 'No'
✗ Incorrect
Since
false is falsy, the ternary operator chooses the else part, printing No.Is the string "false" truthy or falsy in Ruby?
✗ Incorrect
Any string, even "false", is truthy in Ruby.
Which values will make an
if condition run its block in Ruby?✗ Incorrect
Ruby treats everything except
false and nil as true in conditions.What is the result of
!!nil in Ruby?✗ Incorrect
Double negation converts
nil to false.Explain which values are considered falsy in Ruby and why this matters when writing conditions.
Think about what Ruby treats as 'no' or 'nothing'.
You got /4 concepts.
Describe how Ruby's truthy and falsy values differ from other languages you might know.
Consider languages where 0 or empty strings might be falsy.
You got /3 concepts.