There are a bunch of escaping methods, some of them:
# Regexp escapings
>> Regexp.escape('*?{}.')
=> \*?{}.
>> URI.escape("test=100%")
=> "test=100%25"
>> CGI.escape("test=100%")
=> "test%3D100%25"
So, its really depends on the issue you need to solve. But I would avoid using inspect for escaping.
Update - there is a dump, inspect uses that, and it looks like it is what you need:
>> "
".dump
=> ""\n\t""
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…