Add String#remove(pattern) as a short-hand for the common pattern of String#gsub(pattern, '')

上级 d126a081
* Add String#remove(pattern) as a short-hand for the common pattern of String#gsub(pattern, '')
*DHH*
* Adds a new deprecation behaviour that raises an exception. Throwing this
line into +config/environments/development.rb+
......
......@@ -20,6 +20,16 @@ def squish!
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)
......
......@@ -277,6 +277,11 @@ def test_truncate_multibyte
def test_truncate_should_not_be_html_safe
assert !"Hello World!".truncate(12).html_safe?
end
def test_remove
assert_equal "Summer", "Fast Summer".remove(/Fast /)
assert_equal "Summer", "Fast Summer".remove!(/Fast /)
end
def test_constantize
run_constantize_tests_on do |string|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册