Ruby Nullish States

Just want to point out a great post by Joyce Echessa talking about the differences between all the nullish state methods for Ruby: Nil? Empty? Present? Blank?

#nil?#empty?#blank?#present?
5falseNoMethodErrorfalsetrue
""falsetruetruefalse
" "falsefalsetruefalse
"\t\n"falsefalsetruefalse
[]falsetruetruefalse
["a"]falsefalsefalsetrue
{}falsetruetruefalse
{a: "b"}falsefalsefalsetrue
Set.newfalsetruetruefalse
niltrueNoMethodErrortruefalse
truefalseNoMethodErrorfalsetrue
falsefalseNoMethodErrortruefalse

She goes into a deep dive of each in her post.
https://blog.appsignal.com/2018/09/11/differences-between-nil-empty-blank-and-present.html

Leave a Comment