nil vs empty vs blank in ruby and rails

Methodnil?if()empty?blank?present?(!blank)any?
ScopeRubyRubyRubyRailsRailsRails
ObjectallallString, Array, HashallallEnumerable
niltruefalseNoMethodErrortruefalseNoMethodError
falsefalsefalseNoMethodErrortruefalseNoMethodError
truefalsetrueNoMethodErrorfalsetrueNoMethodError
0 falsetrueNoMethodErrorfalsetrueNoMethodError
1falsetrueNoMethodErrorfalsetrueNoMethodError
'""'falsetruetruetruefalseNoMethodError
""falsetruefalsetruefalseNoMethodError
[]falsetruetruetruefalsefalse
[nil]falsetruefalsefalsetruefalse
{}falsetruetruetruefalsefalse
{a:nil}falsetruefalsefalsetruetrue


Related Articles


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.