From: Adam Salter Date: 2009-09-10T11:38:08+09:00 Subject: Change Ruby 1.9 file encoding mid read --Apple-Mail-4--634825474 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Is it possible to change a file's encoding mid read? Trying do do something along the lines of the following: file = File.open('testfile.rb', 'r:US-ASCII') file.each_line do |line| if (file.lineno == 1 || file.lineno == 2) && line =~ / ^#.*coding:\s([\w-]+)/ file.force_encoding($1) end next if line.valid_encoding? puts "bad encoding: [%s:%d]" % [file.path, file.lineno] end -Adam --Apple-Mail-4--634825474--