From: Brian Candler Date: 2008-12-15T22:33:46+09:00 Subject: Re: ruby 1.9.1: Encoding trouble: broken US-ASCII String Tom Link wrote: >> text = File.read("text.txt", :encoding=>"ISO-8859-1") > > Unfortunately, this isn't compatible with ruby 1.8. A script that uses > such a construct runs only with ruby 1.9. Sigh. If all else fails, read the source. I see that the encoding falls back to rb_default_external_encoding(), which returns default_external, setting it if necessary from rb_enc_from_index(default_external_index) This in turn is set from rb_enc_set_default_external This in turn is set from cmdline_options.ext.enc.name And this in turn is set from the -E flag (or certain legacy settings on -K). So: $ ruby19 -E ISO-8859-1 -e 'puts File.open("/etc/passwd").gets.encoding' ISO-8859-1 Yay. However, if it is possible to set the default external encoding programatically (i.e. not via the command line options) I couldn't see how. -- Posted via http://www.ruby-forum.com/.