From: Wayne Walker Date: 2010-04-15T01:52:11+09:00 Subject: [ruby-core:29514] [Bug #3147] gsub evaluates the passed in replacement string making results unpredictable when replacement string is dynamically generated Bug #3147: gsub evaluates the passed in replacement string making results unpredictable when replacement string is dynamically generated http://redmine.ruby-lang.org/issues/show/3147 Author: Wayne Walker Status: Open, Priority: Normal ruby -v: ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-linux] after the interpreter evaluates the replacement string (if it's a literal in "" or ''), gsub further evaluates it during execution changing the effective replacement string. irb(main):016:0> a = 'Y' => "Y" irb(main):017:0> b = 'Z\1' => "Z\\1" irb(main):018:0> c = '\\\1' => "\\\\1" irb(main):019:0> a.gsub(/(Y)/, b) => "ZY" irb(main):020:0> a.gsub(/(Y)/, c) => "\\1" The last result is expected to be "\\Y" ---------------------------------------- http://redmine.ruby-lang.org