Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

True values

  • false, nil, and the null pointer are "falsy" everything else, including 0 and "" are true
values = [0, "0", "", 1, true, false, nil]
values.each { |val|
  if val
    puts "#{val} is true"
  else
    puts "#{val} is NOT true"
  end
}
0 is true
0 is true
 is true
1 is true
true is true
false is NOT true
 is NOT true