Class: Object Private
- Inherits:
- BasicObject
- Defined in:
- extend/blank.rb,
extend/object/deep_dup.rb,
extend/object/duplicable.rb
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
private
An object is blank if it's false, empty, or a whitespace string.
-
#deep_dup ⇒ T.self_type
private
Returns a deep copy of object if it's duplicable.
-
#duplicable? ⇒ Boolean
private
Can you safely dup this object?.
-
#presence ⇒ T.self_type?
private
Returns the receiver if it's present, otherwise returns
nil
. -
#present? ⇒ Boolean
private
An object is present if it's not blank.
Instance Method Details
#blank? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
An object is blank if it's false, empty, or a whitespace string.
For example, nil
, ''
, ' '
, []
, {}
and false
are all blank.
Example
!address || address.empty?
can be simplified to
address.blank?
21 22 23 |
# File 'extend/blank.rb', line 21 def blank? respond_to?(:empty?) ? !!T.unsafe(self).empty? : false end |
#deep_dup ⇒ T.self_type
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a deep copy of object if it's duplicable. If it's not duplicable, returns +self+.
object = Object.new dup = object.deep_dup dup.instance_variable_set(:@a, 1)
object.instance_variable_defined?(:@a) # => false dup.instance_variable_defined?(:@a) # => true
17 18 19 |
# File 'extend/object/deep_dup.rb', line 17 def deep_dup duplicable? ? dup : self end |
#duplicable? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Can you safely dup this object?
False for method objects; true otherwise.
34 |
# File 'extend/object/duplicable.rb', line 34 def duplicable? = true |
#presence ⇒ T.self_type?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns the receiver if it's present, otherwise returns nil
.
object.presence
is equivalent to object.present? ? object : nil
.
Example
state = params[:state] if params[:state].present?
country = params[:country] if params[:country].present?
region = state || country || 'US'
can be simplified to
region = params[:state].presence || params[:country].presence || 'US'
47 48 49 |
# File 'extend/blank.rb', line 47 def presence self if present? end |
#present? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
An object is present if it's not blank.
27 |
# File 'extend/blank.rb', line 27 def present? = !blank? |