Class: String Private

Inherits:
Object show all
Defined in:
extend/string.rb,
dev-cmd/irb.rb,
extend/blank.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.

Direct Known Subclasses

Cask::DSL::Version

Constant Summary collapse

BLANK_RE =
/\A[[:space:]]*\z/
ENCODED_BLANKS_ =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let(Hash.new do |h, enc|
  h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
end, T::Hash[Encoding, Regexp])

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.

A string is blank if it’s empty or contains whitespaces only:

’‘.blank? # => true ‘ ‘.blank? # => true “\t\n\r”.blank? # => true ‘ blah ‘.blank? # => false

Unicode whitespace is supported:

“\u00a0”.blank? # => true

Returns:

  • (Boolean)


134
135
136
137
138
139
140
141
142
143
144
# File 'extend/blank.rb', line 134

def blank?
  # The regexp that matches blank strings is expensive. For the case of empty
  # strings we can speed up this method (~3.5x) with an empty? call. The
  # penalty for the rest of strings is marginal.
  empty? ||
    begin
      BLANK_RE.match?(self)
    rescue Encoding::CompatibilityError
      T.must(ENCODED_BLANKS_[encoding]).match?(self)
    end
end

#exclude?(string) ⇒ 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.

The inverse of String#include?. Returns true if the string does not include the other string.

“hello”.exclude? “lo” # => false “hello”.exclude? “ol” # => true “hello”.exclude? ?h # => false

Parameters:

Returns:

  • (Boolean)


12
# File 'extend/string.rb', line 12

def exclude?(string) = !include?(string)

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

Returns:

  • (Boolean)


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

def present? = !blank? # :nodoc: