Truthiness in Ruby
nil and false.
What Is Truthiness?
In a condition, Ruby does not require a strict boolean. Any value is treated as either truthy or falsy. Knowing the rule prevents subtle bugs.
if "hello"
puts "Strings are truthy"
endOnly Two Falsy Values
Ruby's rule is delightfully simple: only false and nil are falsy. Everything else is truthy.
puts "nil is falsy" unless nil
puts "false is falsy" unless falseAll lessons in this course
- if, unless, ternary
- case/when Expressions
- Truthiness in Ruby
- Guard Clauses