So I think this is weird:
"x'y".gsub("'", "\\'")
=> "xyy"
The variant,
'x"y'.gsub('"', "\'")
=> "x'y"
Works just fine.
Either it's a bug (unlikely) or it's something with how Ruby handles backreferences that I don't understand. Can anyone explain what happens in the first case?