~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/string/filters.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module ActiveSupport #:nodoc:
 
2
  module CoreExtensions #:nodoc:
 
3
    module String #:nodoc:
 
4
      module Filters
 
5
        # Returns the string, first removing all whitespace on both ends of
 
6
        # the string, and then changing remaining consecutive whitespace
 
7
        # groups into one space each.
 
8
        #
 
9
        # Examples:
 
10
        #   %{ Multi-line
 
11
        #      string }.squish                   # => "Multi-line string"
 
12
        #   " foo   bar    \n   \t   boo".squish # => "foo bar boo"
 
13
        def squish
 
14
          dup.squish!
 
15
        end
 
16
 
 
17
        # Performs a destructive squish. See String#squish.
 
18
        def squish!
 
19
          strip!
 
20
          gsub!(/\s+/, ' ')
 
21
          self
 
22
        end
 
23
      end
 
24
    end
 
25
  end
 
26
end