Class: Object

Inherits:
BasicObject
Defined in:
lib/capistrano_sentinel/initializers/active_support/blank.rb

Instance Method Summary collapse

Instance Method Details

#blank?true, false

An object is blank if it's false, empty, or a whitespace string. For example, false, '', ' ', nil, [], and {} are all blank.

This simplifies

!address || address.empty?

to

address.blank?

14
15
16
# File 'lib/capistrano_sentinel/initializers/active_support/blank.rb', line 14

def blank?
  respond_to?(:empty?) ? !!empty? : !self
end

#presenceObject

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'

41
42
43
# File 'lib/capistrano_sentinel/initializers/active_support/blank.rb', line 41

def presence
  self if present?
end

#present?true, false

An object is present if it's not blank.


21
22
23
# File 'lib/capistrano_sentinel/initializers/active_support/blank.rb', line 21

def present?
  !blank?
end