[newbie] specifying file encoding

i have a very simple script in ISO-8859-1 :
#!/usr/bin/ruby

w = "émilion"
fo = File.open(“capitalize.txt”, File::RDWR|File::CREAT,0600)
fo.puts w.capitalize
fo.close

resulting in :
Èmilion E grave instead of Eacute

But the prob arroses because the output file “capitalize.txt” is in
MacOS Roman…

How could we secify the encoding of I/O files ???

In fact, the prob is worth than i thought if i change the encoding of
the file for the script to MacOS Roman

the w.capitalize
is written as :
émilion
that’s to say NO capitalisation on accentuated chars ???

···


Yvon

a string is considered by ruby as encoded as . If you
want to treat strings from other encodings, you can convert encoding using
“iconv” (bundled with ruby 1.8); in your case, you can use iconv to convert
the string to your local encoding (iso-8859-1) and then capitalize will work
fine.

emmanuel

PS: better support for this is planned for ruby 2.0

···

On Tuesday 23 of September 2003 21:15, Yvon Thoraval wrote:

How could we secify the encoding of I/O files ???


“Droit devant soi, on ne peut pas aller bien loin”
- Le petit prince, Antoine de Saint Exupéry

Emmanuel Touzery wrote:

a string is considered by ruby as encoded as . If you
want to treat strings from other encodings, you can convert encoding using
“iconv” (bundled with ruby 1.8); in your case, you can use iconv to convert
the string to your local encoding (iso-8859-1) and then capitalize will work
fine.

which made me wonder: how do I find out what is the current local
encoding for the computer in a portable (unix/windows) way?

emmanuel