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:
parent
3458873642
commit
8005ad3233
1 changed files with 7 additions and 6 deletions
|
@ -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, ""
|
||||
|
|
Loading…
Reference in a new issue