In the Rails docs, the example provided for the object.presence
method is:
region = params[:state].presence || params[:country].presence || \'US\'
<
Here's the point:
''.presence
# => nil
so if params[:state] == ''
:
region = params[:state].presence || 'US'
# => 'US'
region = params[:state] || 'US'
# => ''
What's more, it works in similar way (that is, returns nil
if object is 'empty') on every object that responds to empty?
method, for example:
[].presence
# => nil
Here's the documentation, for reference:
http://api.rubyonrails.org/classes/Object.html#method-i-presence