Albert Schlef wrote in post #988363:
> 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:
>
>   #<Encoding:UTF-8>
>   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?

Depends what you mean by "shouldn't be". The rules for encodings in ruby 
1.9 are (IMO) arbitrary and inconsistent.

In the case of external encodings: yes, they default to nil for files 
opened in write mode. This means that no transcoding is done on output. 
For example, if you have a String which happens to contain binary, or 
ISO-8859-1, it will be written out unchanged (i.e. the sequence of bytes 
in the String is the same sequence of bytes which will end up in the 
file).

If you want to transcode on output, you have to set the external 
encoding explicitly.

Since none of this is documented anywhere officially, I attempted to 
reverse engineer it. I've documented about 200 behaviours here:
https://github.com/candlerb/string19/blob/master/string19.rb

For my own code, I still use ruby 1.8 exclusively.

-- 
Posted via http://www.ruby-forum.com/.