Why is false.blank? => true?

When using a boolean attribute, often you want to insure that it has a
value that is either false or true, but not null. One would think
that “validates_presence_of :boolean_attribute” would work for such a
purpose, but it does not, because false.blank? => true. I’m guessing
this is the expected behavior, but I’m wondering about the rationale.
blank? would imply the lack of data (empty sets, nils), but false is a
value with a particular meaning, so having false.blank? => true
doesn’t make sense to me. Am I missing something?

This isn’t really a big deal, as you can use “validates_inclusion_of
:boolean_attribute, :in=>[false, true]”, but validates_presence_of
would make more sense (to me).

Jeremy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs