From: Moxley Stratton Date: 2011-10-13T13:27:38+09:00 Subject: [ruby-core:40133] [Ruby - Bug #1443] String#gsub handles backslashes incorrectly Issue #1443 has been updated by Moxley Stratton. I will use String#[]= instead: string['pattern'] = File.read(some_file_with_backslashes_in_it) This meets my requirements. ---------------------------------------- Bug #1443: String#gsub handles backslashes incorrectly http://redmine.ruby-lang.org/issues/1443 Author: shawn landen Status: Rejected Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] =begin @Shyouhei Urabe I didn't see how to comment on the bug so i hid to file a new one This is a continuation of bug #1441 The backslashes are being doubled under single quotes and double quotes, but String#gsub requires you to quadruple (4x) them, 4 backslashes for every one in the resultant string. printf "b".gsub("b","\\\\") prints a single backslash(\), while it should print 2(\\). (as printf "\\\\"; does) The reason it looks different is because String#inspect shows strings as escaped. =end -- http://redmine.ruby-lang.org