api详细介绍了 presence
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'
下面的一样
region = params[:state].presence || params[:country].presence || 'US'
详细解释
def presence
self if present?
end
def present?
!blank?
end