diff options
author | Rishi Jain <rishi@joshsoftware.com> | 2014-11-06 06:34:56 +0530 |
---|---|---|
committer | Rishi Jain <rishi@joshsoftware.com> | 2014-11-06 13:04:56 +0530 |
commit | 54a9653a04f43917eab0b323ef4ba5b1fc6c05f4 (patch) | |
tree | 5ad61c1e82a940767077f15b3af1034ac5df9793 /activesupport/lib | |
parent | 75099a933d0bf5e037037f78fbb305520955b064 (diff) | |
download | rails-54a9653a04f43917eab0b323ef4ba5b1fc6c05f4.tar.gz rails-54a9653a04f43917eab0b323ef4ba5b1fc6c05f4.tar.bz2 rails-54a9653a04f43917eab0b323ef4ba5b1fc6c05f4.zip |
added example of squish!, remove, test case for multiple occurrence of
pattern removal
added example for string#remove and test case for remove of multiple occurence of pattern
removed extra whitespaces
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/filters.rb | 9 |
1 files changed, 9 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 index 499b9b26bc..096292dc58 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -13,6 +13,9 @@ class String end # Performs a destructive squish. See String#squish. + # str = " foo bar \n \t boo" + # str.squish! # => "foo bar boo" + # str # => "foo bar boo" def squish! gsub!(/\A[[:space:]]+/, '') gsub!(/[[:space:]]+\z/, '') @@ -21,11 +24,17 @@ class String end # Returns a new string with all occurrences of the patterns removed. + # str = "foo bar test" + # str.remove(" test") # => "foo bar" + # str # => "foo bar test" def remove(*patterns) dup.remove!(*patterns) end # Alters the string by removing all occurrences of the patterns. + # str = "foo bar test" + # str.remove!(" test") # => "foo bar" + # str # => "foo bar" def remove!(*patterns) patterns.each do |pattern| gsub! pattern, "" |