class Object
github.com/rails/rails/activesupport
this is from active_support
def blank?
...to:
if !address.nil? && !address.empty?
This simplifies:
For example, "", " ", +nil+, [], and {} are blank.
An object is blank if it's false, empty, or a whitespace string.
def blank? respond_to?(:empty?) ? empty? : !self end
def presence
...becomes:
region = state || country || 'US'
country = params[:country] if params[:country].present?
state = params[:state] if params[:state].present?
HTTP POST/query parameters:
as not present at all. For example, this simplifies a common check for
This is handy for any representation of objects where blank is the same
object.presence is equivalent to object.present? ? object : nil.
Returns object if it's present? otherwise returns +nil+.
def presence self if present? end
def present?
def present? !blank? end