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

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?

Returns:

  • (Boolean)


21
22
23
# File 'extend/blank.rb', line 21

def blank?
  respond_to?(:empty?) ? !!T.unsafe(self).empty? : false
end

#deep_dupT.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

Returns:

  • (T.self_type)


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.

Returns:

  • (Boolean)


34
# File 'extend/object/duplicable.rb', line 34

def duplicable? = true

#presenceT.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'

Returns:

  • (T.self_type, nil)


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.

Returns:

  • (Boolean)


27
# File 'extend/blank.rb', line 27

def present? = !blank?