【发布时间】:2012-02-29 14:56:04
【问题描述】:
单引号字符串的转义规则在以下示例中看起来不一致: Ruby 转义单引号字符串的具体规则是什么?
p str1 = 'a\b\c'
#=> "a\\b\\c" looks fine, I know single quotes don't do escaping
p str2 = 'a\\b\\c'
#=> "a\\b\\c" hmm? It actually escapes
# Trying double quotes
p str3 = "a\b\c"
#=> Error, \c isn't valid
p str4 = "a\\b\\c"
#=> "a\\b\\c"
p str1 == str4, str2 == str4
# true, true
【问题讨论】: