Method: String#squish!

Defined in:
activesupport/lib/active_support/core_ext/string/filters.rb

#squish!Object

Performs a destructive squish. See String#squish.

str = " foo   bar    \n   \t   boo"
str.squish!                         # => "foo bar boo"
str                                 # => "foo bar boo"


21
22
23
24
25
26
27
# File 'activesupport/lib/active_support/core_ext/string/filters.rb', line 21

def squish!
  # Search for two or more `[[:space:]]` OR a single
  # [[:space:]] that isn't `" "`.
  gsub!(/([[:space:]]{2,}|[[[:space:]]&&[^ ]])/, " ")
  strip!
  self
end