Issue #17110 has been updated by mame (Yusuke Endoh).

Status changed from Open to Rejected

See the document.

> The backslash character `\` can be used to escape `^` or `-` and is otherwise ignored unless it appears at the end of a range or the end of the from_str or to_str:

https://docs.ruby-lang.org/en/2.7.0/String.html#method-i-tr

So you can write `"\\".tr("C\\", "BA")` according to the document.

This seems undocumented, but `\` can be used to escape `\`, so you can also write `"\\".tr("\\\\C", "AN")`.

----------------------------------------
Bug #17110: String.tr unexpected behaviour with backslash
https://bugs.ruby-lang.org/issues/17110#change-86991

* Author: theplen (Joey Sheets)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
`"\\".tr("\\","A")` works great, with `"\\"` becoming `"A"`.

`"\\".tr("\\C","AB")` should also output `"A"`, but instead outputs `"\\"`.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>