Issue #8512 has been updated by Eregon (Benoit Daloze).

Status changed from Open to Rejected

This is due to Regexp replace syntax and literal strings.

In literal strings, you need two \ to produce one \ character (a single is the start of an escape character like \t, \n, ...).
And in Regexp replacement strings, you need to escape the \ (a single one is the beginning of a special replacement sequence like \1,\&,...).
So that makes 4 \ for one produced in replacement strings:

> "\\".gsub(/\\/, "\\\\").length
=> 1
> "\\".gsub("\\", "\\\\\\\\").length
=> "\\\\"

Not so nice, but definitely expected behavior.
----------------------------------------
Bug #8512: gsub() works incorrect 
https://bugs.ruby-lang.org/issues/8512#change-39858

Author: galnaktar (Oleg K)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0p195 (2013-05-14) [i386-mingw32]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


irb(main):005:0> "\\".gsub("\\", "\\\\").length 
=> 1 
irb(main):006:0> "\\".gsub("\\", "XX").length 
=> 2

bug is duplicated with rejected bug #8511


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