From: Brian Candler Date: 2010-11-04T19:18:00+09:00 Subject: Re: Ruby 1.9.2 with Rails 3.0.1 Luis Lavena wrote in post #959207: >> The solution was to put the following line at the top of this file >> (seeds.rb) >> >> # encoding: utf-8 >> >> If someone can articulate some simple rules for character encoding in >> Ruby 1.9.2 p0 and Rails 3.0.1 environment, that will be quite useful. >> > > Ruby interprets each file 'encoding' or magical comments to decide > which encoding is going to use for that particular file. > > If the file lacks encoding it assumes the one provided by > Encoding.default_external, which in your case seems US-ASCII. That answer is wrong - but I don't blame you for giving a wrong answer, since the whole encoding nonsense in ruby 1.9 is ridiculously complicated. The correct answer is: the encoding of a ruby 1.9 source file (and hence the String literals within that file) is *always* US-ASCII, unless you tag it with a #encoding line which says otherwise. I have so far collected about 200 rules for how encodings work in ruby 1.9: https://github.com/candlerb/string19/blob/master/string19.rb Unfortunately, this list is just the tip of the iceberg. To be complete, it would have to describe the encoding-related behaviour of every method on String, every method which accepts a String, and every method which returns a String. Regards, Brian. -- Posted via http://www.ruby-forum.com/.