Reputation: 2194
I needed a ruby string with "\("
in it and found the escaping playing trick on me.
"\("
gives me "("
"\\("
gives me "\\("
Upvotes: 1
Views: 62
Reputation: 96914
"\\("
is correct, the problem is that the result of inspect
(which is what IRB uses to display the return value of the last call) is not the same as the actual contents because of the escaping:
puts "\\(".inspect #prints: "\\("
puts "\\(" #prints: \(
If you don't need interpolation, just use single quotes:
puts '\(' #prints: \(
Upvotes: 7