String#delete returns a string with characters matching one or more specified character-set arguments removed. Its arguments use the same character-set rules as String#count, including negation and ranges. section 8.1.5
Remove selected characters
"David A. Black".delete("abc") # => "Dvid A. Blk" "David A. Black".delete("^abc") # => "aac" "David A. Black".delete("a-e", "^c") # => "Dvi A. Blck"
Read the argument as a character set rather than as a substring. A leading ^ reverses the selection, a range such as a-e selects a span, and multiple arguments combine character-set conditions. section 8.1.5
Do not confuse the similarly named deletion methods:
- Set#delete removes one object from a set; deleting an absent object does nothing and does not raise an error. section 9.5.2
- Dir#delete is an alias for Dir.rmdir and removes a directory rather than characters from a string. section 12.4.2
