Ruby - How to keep \n when I print out strings
ruby
Solution
i would suggest to use `p` instead of `puts`/`print`:
p "abc\nabc"
=> "abc\nabc"
and in fact with `pry` you do not need to use any of them, just type your string and enter:
str = "abc\nabc"
=> "abc\nabc"
str
=> "abc\nabc"
Problem
I would like to keep `\n` when I print out strings in ruby, Like now, if I use `puts` or `print`, `\n` will end up with a newline: ``` pry(main)> print "abc\nabc" abc abc ``` is there a way to let ruby print it out like: `abc\nabc` ? UPDATE Sorry that maybe I didn't make it more clear. I am debugging my regexps, so when I output a string, if a `\n` is displayed as a `\n`, not a newline, it would be easier for me to check. So @slivu 's answer is exactly what I want. Thanks guys.