This project is archived and is in readonly mode.
FalseClass should return false on a .presence check not nil
Reported by Philip Arndt | June 16th, 2010 @ 11:37 PM
When you create a variable and set it to false
and
then use .presence
on it, .presence
returns nil
where it should return
false
.
I've attached a patch which solves this by adding the presence
method to FalseClass and always returning self from it.
I've also updated the relevant tests to handle this change.
Comments and changes to this ticket
-
Philip Arndt June 17th, 2010 @ 12:02 AM
- Assigned user cleared.
-
Jeremy Kemper June 17th, 2010 @ 12:54 AM
- State changed from verified to wontfix
returns nil where it should return false
Why should it? The lack of presence is
nil
, andfalse
is not present, like" "
and[]
. -
Philip Arndt June 17th, 2010 @ 01:39 AM
false is a valid instance of the FalseClass and so a false value is in essence present, just like how currently true is returned as a valid instance of the TrueClass for true.presence - these are different than empty string or empty array.
Currently we get:
true.presence #=> true
false.presence #=> nil
Merging this patch means that you (more consistently I think) get:
true.presence #=> true
false.presence #=> false
if
statements will still work in the same fashion as before the only difference is that Rails no longer is hiding the actual value of false. -
Jeremy Kemper June 17th, 2010 @ 02:48 AM
false.blank? # => true
false.present? # => false
Presence is universal for all objects. If an object is not
blank?
,self
is returned. True and false are not special cases.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>