diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/filters.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb new file mode 100644 index 0000000000..3a69131ea0 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -0,0 +1,24 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module String #:nodoc: + module Filters + # Returns the string, first removing all whitespace on both ends of + # the string, and then changing remaining consecutive whitespace + # groups into one space each. + # + # Examples: + # %{ Multi-line + # string }.squish # => "Multi-line string" + # " foo bar \n \t boo".squish # => "foo bar boo" + def squish + strip.gsub(/\s+/, ' ') + end + + # Performs a destructive squish. See String#squish. + def squish! + replace(squish) + end + end + end + end +end |