How to print \ "in Ruby

The ruby quotes can be printed in a row, if it immediately precedes the backslash: print " \" "

.

But how do I print \"

in ruby ​​without the backslash disappearing due to the presence of the quote mark just before it?

Thanks in advance.

+3


source to share


1 answer


You can use single quote ( '

) instead of double quote ( "

) to prevent interpretation of the escape sequence:

irb(main):001:0> print '\"'
\"=> nil

      



or %q{...}

, if there are many in the line '

:

irb(main):002:0> print %q{\"}
\"=> nil

      

+6


source







All Articles