From: Tim Hunter Date: 2009-02-16T09:19:19+09:00 Subject: Re: invalid byte sequence in US-ASCII (ArgumentError) Luther wrote: > I'm having some trouble migrating from 1.8 to 1.9.1. I have this line of > code: > > text.gsub! "\C-m", '' > > ...which generates this error: > > /home/luther/bin/dos2gnu:16:in `gsub!': invalid byte sequence in > US-ASCII (ArgumentError) > > The purpose is to strip out any ^M characters from the string. I've > tried a couple of different magic comments with utf-8, but the error > message still shows the same "US-ASCII". I also tried changing the \C-m > to 13.chr, but I still got the same error, suggesting that control > characters aren't even allowed in strings anymore. > > I'm sure this must be a common migration problem, but I can't find a > solution no matter how hard I search the web. Any help would be greatly > appreciated. > > Luther > > > Since Ruby is claiming the source file is US-ASCII it seems likely that it's not noticing the magic comment. Make sure your magic comment is the first line in the script, or if you're using a shebang line, the second line. That is, either # encoding: utf-8 or #! /usr/local/bin/ruby # encoding: utf-8 -- RMagick: http://rmagick.rubyforge.org/