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
1 changed files with 7 additions and 6 deletions

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, ""