Class: String
- Defined in:
- lib/dirwatch/extensions/blank.rb,
lib/dirwatch/string_extensions.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/- RESET_KEY =
"\033[0m".freeze
Instance Method Summary collapse
-
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:.
Instance Method Details
#blank? ⇒ true, false
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
65 66 67 68 69 70 |
# File 'lib/dirwatch/extensions/blank.rb', line 65 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? || BLANK_RE.match?(self) end |