nil and Truthiness
Only false and nil are falsy. 0 and empty strings are truthy.
Example
puts !!0, !!"", !!nil, !!false
x = nil
puts x.nil?, (x || "default"), x&.length.inspectResult
true true false false true default nil
Exercise
Safe navigation.
x.length
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.