aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-08-13 12:15:48 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-08-13 12:16:25 -0500
commit5da23a3f921f0a4a3139495d2779ab0d3bd4cb5f (patch)
tree4a4f6b44fb99f091418126261b684151d258fa48 /activesupport/lib/active_support/core_ext
parentd126a081ed840340dff5c6299d01d42aaaf32608 (diff)
downloadrails-5da23a3f921f0a4a3139495d2779ab0d3bd4cb5f.tar.gz
rails-5da23a3f921f0a4a3139495d2779ab0d3bd4cb5f.tar.bz2
rails-5da23a3f921f0a4a3139495d2779ab0d3bd4cb5f.zip
Add String#remove(pattern) as a short-hand for the common pattern of String#gsub(pattern, '')
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/string/filters.rb10
1 files changed, 10 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 a4cacaf789..2e2dd86a8b 100644
--- a/activesupport/lib/active_support/core_ext/string/filters.rb
+++ b/activesupport/lib/active_support/core_ext/string/filters.rb
@@ -20,6 +20,16 @@ class String
self
end
+ # Returns a new string with all occurances of the pattern removed. Short-hand for String#gsub(pattern, '').
+ def remove(pattern)
+ gsub pattern, ''
+ end
+
+ # Alters the string by removing all occurances of the pattern. Short-hand for String#gsub!(pattern, '').
+ def remove!(pattern)
+ gsub! pattern, ''
+ end
+
# Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>:
#
# 'Once upon a time in a world far far away'.truncate(27)