I have a Ruby string that can sometimes contain some non-printable characters. Before I show it in the GUI I use String.dump to convert the string to user readable format. The side effect is that it also escapes double quotes. Is there an easy way to avoid that or only dump the string if it has any non-printable characters?
irb(main):041:0> s = "a=b,\"c=d\""
=> "a=b,\"c=d\""
irb(main):042:0> s.dump
=> "\"a=b,\\\"c=d\\\"\""
You can test for non-printable chars (or gsub them) with this regexp: