I’m sure I can do this with a regex, but I can’t find any explanation for this behavior using just normal delete!:
#1.9.2
>> "helllom<em>".delete!"<em>"
=> "hlllo"
The docs don’t have anything to say about this. Seems to me that it’s treating '<em>' as a set. Where is this documented?
Edit: in my defense I was looking for special treatment of < and > in the docs under delete. Didn’t see anything about it and tried google, which also didn’t have anything to say about that — because it doesn’t exist.
String#deleteis one of those unfortunate methods that is difficult to explain (I have no idea what the use case is). In practice, I’ve always used gsub with an empty string as the second argument.Note that
String#gsub!also has weirdness such that you should not depend on its return value, it will returnnilif it does not alter the string, so it is best to usegsubif you depend on the return value, or if you want to mutate the string, then usegsub!but and don’t use anything else on that line.