Escape status within a string literal as argument of `String#tr`
سؤال
There is something mysterious to me about the escape status of a backslash within a single quoted string literal as argument of String#tr
. Can you explain the contrast between the three examples below? I particularly do not understand the second one. To avoid complication, I am using 'd'
here, which does not change the meaning when escaped in double quotation ("\d"
= "d"
).
'\\'.tr('\\', 'x') #=> "x"
'\\'.tr('\\d', 'x') #=> "\\"
'\\'.tr('\\\d', 'x') #=> "x"
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow