String.tr bug?

Greetings,
I found strange behaviour of string.tr:

p “=+=/=”.tr("+/=", “,-@”)
got “.,.-.”
expected “@,@-@”

Is this bug in ruby?

[email protected] wrote:

I found strange behaviour of string.tr:

p “=+=/=”.tr("+/=", “,-@”)
got “.,.-.”
expected “@,@-@”

Is this bug in ruby?

It’s not a bug. For tr “,-@” is the same as “,-./0123456789:;<=>?@”. You
have
to escape the - to use it as a literal “-”:
“=+=/=”.tr("+/=", ‘,-@’) #=> “@,@-@”

HTH,
Sebastian