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