0Pricing
Ruby Academy · Lesson

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"
end

Only 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 false

All lessons in this course

  1. if, unless, ternary
  2. case/when Expressions
  3. Truthiness in Ruby
  4. Guard Clauses
← Back to Ruby Academy