Class: String Private
- 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
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. | 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
158 159 160 161 162 163 164 165 166 167 168 |
# File 'extend/blank.rb', line 158 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.
171 |
# File 'extend/blank.rb', line 171 def present? = !blank? # :nodoc: |