class String
Constants
- BLANK_REGEXP
Public Instance Methods
blank?()
click to toggle source
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
@return [true, false]
# File lib/r2-oas/lib/core_ext/object/blank.rb, line 119 def blank? BLANK_REGEXP === self end
squish()
click to toggle source
Returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each.
Note that it handles both ASCII and Unicode whitespace.
%{ Multi-line string }.squish # => "Multi-line string" " foo bar \n \t boo".squish # => "foo bar boo"
# File lib/r2-oas/lib/core_ext/string/filters.rb, line 15 def squish dup.squish! end
squish!()
click to toggle source
Performs a destructive squish. See String#squish
.
str = " foo bar \n \t boo" str.squish! # => "foo bar boo" str # => "foo bar boo"
# File lib/r2-oas/lib/core_ext/string/filters.rb, line 23 def squish! gsub!(/\A[[:space:]]+/, '') gsub!(/[[:space:]]+\z/, '') gsub!(/[[:space:]]+/, ' ') self end