File tree 3 files changed +19
-0
lines changed
lib/active_support/core_ext/string
3 files changed +19
-0
lines changed 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
+
1
5
* Adds a new deprecation behaviour that raises an exception. Throwing this
2
6
line into +config/environments/development.rb+
3
7
Original file line number Diff line number Diff line change @@ -20,6 +20,16 @@ def squish!
20
20
self
21
21
end
22
22
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
+
23
33
# Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>:
24
34
#
25
35
# '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
277
277
def test_truncate_should_not_be_html_safe
278
278
assert !"Hello World!" . truncate ( 12 ) . html_safe?
279
279
end
280
+
281
+ def test_remove
282
+ assert_equal "Summer" , "Fast Summer" . remove ( /Fast / )
283
+ assert_equal "Summer" , "Fast Summer" . remove! ( /Fast / )
284
+ end
280
285
281
286
def test_constantize
282
287
run_constantize_tests_on do |string |
You can’t perform that action at this time.
0 commit comments