From: Luis Lavena Date: 2010-01-17T13:25:07+09:00 Subject: Re: Strange Encoding Behavior On Jan 17, 12:55 am, Lui Kore wrote: > The encoding of __FILE__ is always the same as Encoding.default_external > even if there is a magic column. Sometimes it is necessary to convert > the string into another encoding. Here is some code to demonstrate the > issue: > > #coding: utf-8 >     # put the script in a not-pure-ascii path to see the difference >     path = File.expand_path File.dirname __FILE__ > >     puts RUBY_VERSION + ' ' + RUBY_PLATFORM >       #=> "1.9.1 i386-mingw32" is my ruby version >     puts path.encoding >       #=> "GB2312" on my OS > >     # usually this "string.encode to, from" works, >     # but HERE the new string's content bytes seems unchanged >     puts \ >       path.encode 'utf-8', Encoding.default_external > >     path.force_encoding Encoding.default_external >     puts path.encode 'utf-8' >       # changed at last At 1.9.1, and some part of 1.9.2 still display certain issues with path/folders with non-ascii characters: http://redmine.ruby-lang.org/issues/show/1685 -- Luis Lavena