aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-03 12:09:26 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-03 12:09:26 -0200
commit4259cc0c5003c26f72105419c3d60e362f539040 (patch)
tree7693c91b1f0e360d475e642d849d7df1bc315c37 /activesupport/lib
parentbadd616cc931dc64de2540d734f5e01000262c0f (diff)
parent73ad15103019f94b789a3b0f13209a0a988df584 (diff)
downloadrails-4259cc0c5003c26f72105419c3d60e362f539040.tar.gz
rails-4259cc0c5003c26f72105419c3d60e362f539040.tar.bz2
rails-4259cc0c5003c26f72105419c3d60e362f539040.zip
Merge pull request #17383 from rwz/string-remove
Make `String#remove` and `String#remove!` accept multiple arguments Conflicts: activesupport/CHANGELOG.md
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/string/filters.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb
index 2b1583d4ac..499b9b26bc 100644
--- a/activesupport/lib/active_support/core_ext/string/filters.rb
+++ b/activesupport/lib/active_support/core_ext/string/filters.rb
@@ -20,14 +20,18 @@ class String
self
end
- # Returns a new string with all occurrences of the pattern removed. Short-hand for String#gsub(pattern, '').
- def remove(pattern)
- gsub pattern, ''
+ # Returns a new string with all occurrences of the patterns removed.
+ def remove(*patterns)
+ dup.remove!(*patterns)
end
- # Alters the string by removing all occurrences of the pattern. Short-hand for String#gsub!(pattern, '').
- def remove!(pattern)
- gsub! pattern, ''
+ # Alters the string by removing all occurrences of the patterns.
+ def remove!(*patterns)
+ patterns.each do |pattern|
+ gsub! pattern, ""
+ end
+
+ self
end
# Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>: