aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorPavel Pravosud <pavel@pravosud.com>2014-10-24 13:25:55 -0400
committerPavel Pravosud <pavel@pravosud.com>2014-10-25 18:06:02 -0400
commit73ad15103019f94b789a3b0f13209a0a988df584 (patch)
treeb05cd8ec710a14a6d98006796dbd36ebedc3585f /activesupport/lib/active_support
parent016af48b86f2096637f39c3194402d9891f35dcd (diff)
downloadrails-73ad15103019f94b789a3b0f13209a0a988df584.tar.gz
rails-73ad15103019f94b789a3b0f13209a0a988df584.tar.bz2
rails-73ad15103019f94b789a3b0f13209a0a988df584.zip
Make `String#remove` and `String#remove!` accept multiple arguments
Diffstat (limited to 'activesupport/lib/active_support')
-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>: