Method: Object#presence
- Defined in:
- lib/active_support/core_ext/object/blank.rb
#presence ⇒ Object
Returns the receiver if it’s present otherwise returns nil
. object.presence
is equivalent to
object.present? ? object : nil
For example, something like
state = params[:state] if params[:state].present?
country = params[:country] if params[:country].present?
region = state || country || 'US'
becomes
region = params[:state].presence || params[:country].presence || 'US'
45 46 47 |
# File 'lib/active_support/core_ext/object/blank.rb', line 45 def presence self if present? end |