From: Brian Candler Date: 2010-04-19T16:42:18+09:00 Subject: Re: iconv transfer code Benoit Daloze wrote: > The easiest with File: File.open("myfile.ext", "w:UTF-8") This is a poor example of the point in question, although a good example of how hard ruby 1.9 is to understand. In fact: the default external encoding is nil for files opened for write, and does not depend on the environment at all. That is, File.open("myfile.ext","w") { |f| f.puts str } just outputs whatever bytes are in str, without meddling with them. Whereas File.open("myfile.ext","w:UTF-8") { |f| f.puts str} will attempt to re-encode str from its current encoding to UTF-8, and may raise an exception if it cannot do so. So if you want to write programs which don't crash, the first is arguably better. The rules for *reading* from files are completely different, and indeed "r:UTF-8" is the right thing to do if you are reading from a file which contains UTF-8 text and you don't want this to be affected by environment variable magic. -- Posted via http://www.ruby-forum.com/.