From: Luther Date: 2009-02-16T11:18:16+09:00 Subject: Re: invalid byte sequence in US-ASCII (ArgumentError) On Mon, 2009-02-16 at 09:19 +0900, Tim Hunter wrote: > 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) > > > 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 > I put the encoding line right after my shebang line, but it had no effect. In further investigation, I tried running my program on a different text file, and it worked fine. The original text file had some very odd characters at the beginning and the end of the file. Once I deleted that metadata, my program worked fine. This means the problem was with the "text" variable rather than the arguments. This seems very wrong to me since it threw an ArgumentError. Or maybe I don't know anything about exceptions. So, my problem is partially solved, but now I know my program will puke on any text file with multibyte characters. Luther