Class: String Private
- Defined in:
- extend/string.rb,
brew_irb_helpers.rb,
extend/blank/string.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, Rainbow::NullPresenter, Rainbow::Presenter
Constant Summary collapse
- BLANK_RE =
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.
/\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. | Regexp::FIXEDENCODING) end, T::Hash[Encoding, Regexp])
Instance Method Summary collapse
- #blank? ⇒ Boolean private
A string is blank if it's empty or contains whitespaces only:.
- #exclude?(string) ⇒ Boolean private
The inverse of String#include?.
- #present? ⇒ Boolean private
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
28 29 30 31 32 33 34 35 36 37 38 | # File 'extend/blank/string.rb', line 28 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 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.
41 | # File 'extend/blank/string.rb', line 41 def present? = !blank? # :nodoc: |
© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/String.html