Class: String
- Defined in:
- lib/dns_one/core_ext/blank.rb,
lib/dns_one/core_ext/string.rb
Constant Summary collapse
- LOCAL_BLANK_RE =
/\A[[:space:]]*\z/
Instance Method Summary collapse
-
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:.
- #strip_text ⇒ Object
- #to_a ⇒ Object
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
129 130 131 132 133 134 |
# File 'lib/dns_one/core_ext/blank.rb', line 129 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? || LOCAL_BLANK_RE.match?(self) end |
#strip_text ⇒ Object
6 7 8 9 10 |
# File 'lib/dns_one/core_ext/string.rb', line 6 def strip_text split("\n") .map{|l| l.strip} .join("\n") end |
#to_a ⇒ Object
3 4 5 |
# File 'lib/dns_one/core_ext/string.rb', line 3 def to_a [self] end |