Ruby1.9にしたら invalid multibyte char (US-ASCII)

遅ればせながらRVMを導入し、Ruby1.9.xを導入したら、「invalid multibyte char (US-ASCII)」というエラーが出た。

So Ruby 1.9 rejects to parse any file with non-ASCII characters if you don’t specify the encoding. You can do so by adding a Ruby comment at the top of the file:

# encoding: utf-8

This tells the Ruby parser to interpret the file content using UTF-8 encoding. Of course, you need to specify the correct encoding (meaningly the encoding your editor used when the file was saved). Most Posix systems like Linux and Mac use UTF-8 by default nowadays. Windows however defaults to Latin-1 (ISO-8859-1).
Ruby 1.9 and file encodings — zargony.com

意訳:Ruby1.9では、ファイルの中に日本語のような非ASCII文字列が含まれるとパースを拒否します。そのため、ファイルの上部に「# encoding: utf-8」というコメントを加えてください。これは、RubyインタプリタUTF-8エンコーディングであることを知らせるものです。

Emacsでよく見かける「# -*- encoding: utf-8 -*-」でも良いらしい。マジックコメントと呼ばれるらしい。

追記:20110106

magic-commenterのようなツールもある。当方ではまだ使いこなしていないが、マジックコメントを挿入しているようである。

% gem install magic-commenter
% cd /path/to/root/of/ruby/files
% magic-commenter

参考: ruby-1.9.xで自動的にmagic-commentをつける - Hello, world! - s21g

追記:20130228

ちなみに、Ruby2.0では、デフォルトのエンコーディングがUTF-8になったので、マジックコメント不要になります!