1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Update documentation examples for String#remove [skip ci]

This commit is contained in:
Anton Davydov 2015-02-28 13:41:52 +03:00
parent 3458873642
commit 8005ad3233

View file

@ -24,17 +24,18 @@ class String
end
# Returns a new string with all occurrences of the patterns removed.
# str = "foo bar test"
# str.remove(" test") # => "foo bar"
# str # => "foo bar test"
# str = "foo bar test baz"
# str.remove(" test baz") # => "foo bar"
# str.remove(" test ", /baz/) # => "foo bar"
# str # => "foo bar test baz"
def remove(*patterns)
dup.remove!(*patterns)
end
# Alters the string by removing all occurrences of the patterns.
# str = "foo bar test"
# str.remove!(" test") # => "foo bar"
# str # => "foo bar"
# str = "foo bar test baz"
# str.remove!(" test ", /baz/) # => "foo bar"
# str # => "foo bar"
def remove!(*patterns)
patterns.each do |pattern|
gsub! pattern, ""