From: Robert Klemme Date: 2011-03-20T21:15:37+09:00 Subject: Re: A question about Ruby 1.9's "external encoding" On 03/20/2011 01:38 AM, Albert Schlef wrote: > I have the following program: > > p Encoding.default_external > File.open('testing', 'w') do |f| > p f.external_encoding > end > > and when I run it I the following output: > > # > nil > > In other words, the file's "external encoding" is nil. What does this > mean? Shouldn't this be "UTF-8", the default external encoding? --------------------------------------------------- IO#external_encoding io.external_encoding => encoding From Ruby 1.9.1 ------------------------------------------------------------------------ Returns the Encoding object that represents the encoding of the file. If io is write mode and no encoding is specified, returns +nil+. I'd say it means that the default encoding is used. > BTW, "ruby1.9.1 -v" gives me: > > ruby 1.9.1p378 (2010-01-10 revision 26273) [i486-linux] > > I'm using Ubuntu 10.04.1, and that's the most updated version of Ruby > 1.9.1. > irb(main):001:0> Encoding.default_external Encoding.default_external Encoding.default_external= irb(main):001:0> Encoding.default_external => # irb(main):002:0> Encoding.default_internal => nil irb(main):003:0> File.open("x","w"){|io| p io.external_encoding; io.puts "aä"} nil => nil irb(main):004:0> File.open("x","r:UTF-8"){|io| p io.external_encoding; io.read} # => "aä\n" irb(main):005:0> Apparently the file *is* encoded in UTF-8 because I can read it without errors and get what I expect. Kind regards robert