Inside the irb:
"\'"
returns "'"
, however
"\""
returns "\""
, ie, it's the same as the input, without escaping the double quote. Using it with puts works as expected, but why does it not work when it is tried in this manner?
irb is working perfectly. You can't expect it to output """
.
By definition:
an escape character is a character which invokes an alternative interpretation on subsequent characters in a character sequence.
In your expected output """
clearly middle "
has a different interpretation. Hence its getting escaped.
To make things clearer:
"\""
#=> "\""
puts "\""
# "