File tree Expand file tree Collapse file tree
lib/active_support/core_ext/string Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * Add String#remove(pattern) as a short-hand for the common pattern of String#gsub(pattern, '')
2+
3+ * DHH*
4+
15* Adds a new deprecation behaviour that raises an exception. Throwing this
26 line into +config/environments/development.rb+
37
Original file line number Diff line number Diff line change @@ -20,6 +20,16 @@ def squish!
2020 self
2121 end
2222
23+ # Returns a new string with all occurances of the pattern removed. Short-hand for String#gsub(pattern, '').
24+ def remove ( pattern )
25+ gsub pattern , ''
26+ end
27+
28+ # Alters the string by removing all occurances of the pattern. Short-hand for String#gsub!(pattern, '').
29+ def remove! ( pattern )
30+ gsub! pattern , ''
31+ end
32+
2333 # Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>:
2434 #
2535 # 'Once upon a time in a world far far away'.truncate(27)
Original file line number Diff line number Diff line change @@ -277,6 +277,11 @@ def test_truncate_multibyte
277277 def test_truncate_should_not_be_html_safe
278278 assert !"Hello World!" . truncate ( 12 ) . html_safe?
279279 end
280+
281+ def test_remove
282+ assert_equal "Summer" , "Fast Summer" . remove ( /Fast / )
283+ assert_equal "Summer" , "Fast Summer" . remove! ( /Fast / )
284+ end
280285
281286 def test_constantize
282287 run_constantize_tests_on do |string |
You can’t perform that action at this time.
0 commit comments