Wednesday, February 4, 2009

nil blank empty

Good to keep in mind. blank? (Added by rails active support) applies to nil and empty strings. False.blank? also evaluates to true... not idiomatically reasonable though, so I might not use that one.

irb(main):015:0> false.blank?
=> true
irb(main):006:0> "".blank?
=> true
irb(main):007:0> "".nil?
=> false
irb(main):008:0> "".empty?
=> true
irb(main):009:0> nil.blank?
=> true
irb(main):010:0> nil.nil?
=> true
irb(main):011:0> nil.empty?
NoMethodError: undefined method `empty?' for nil:NilClass
from (irb):11
from :0

No comments:

Post a Comment