instance method
presence
Ruby on Rails 7.1.6
Since v2.3.18Signature
presence()
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'
@return [Object]
Source
# File activesupport/lib/active_support/core_ext/object/blank.rb, line 45
def presence
self if present?
end
Defined in activesupport/lib/active_support/core_ext/object/blank.rb line 45
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Object