If Person is a Rails ActiveRecord class, and name is a table column with a type of string, then Person#name? doesn't seem to correspond to whether or not name is truthy. For example, if name is set to an empty string, the string is truthy, but name? returns false, at least for Rails 3.2.x. What does adding a question mark do?
I tried searching for this, but question marks aren't very googleable, or even symbolhoundable.
An answer to "Using question mark character in Rails/ActiveRecord column name" mentions that ActiveRecord automatically adds question marks to field (column?) names, but there are conflicting comments on what it does.
It will return true if a field is present? or not. So an empty string "" will return false.
The question mark methods are similar to present? but not the same. For instance, numeric values will return true if they aren't zero, whereas 0.present? returns true. Here's the line in the Rails source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With