[Ironruby-core] $KCODE and encodings

Shri Borde Shri.Borde at microsoft.com
Fri Feb 13 18:01:19 EST 2009

I was searching for string encoding issues in Ruby. Here is the summary of what I learnt, in case its useful to anyone else of if anyone has any corrections to this.

Ruby 1.8 support for encoding:

*         A comment like "# -*- coding: utf-8 -*-" at the start of the file is supposed to determine how to parse a .rb file, but I haven't really figured out how to make this work. Non-ansi characters cause an error while loading the file.

*         ruby.exe -K<kcode> sets $KCODE (which can also be set programmaticaly)

*         $KCODE affects the following:

*         Determines the encoding to use to parse .rb files. Normally, identifiers have to be ANSI, but the limitation is removed if $KCODE is set to "UTF8".

*         Affects whether inspect escapes non-ascii chars, or if it leaves them as is.

*         Affects how regexps without an explicit encoding interpret the input string.

Ruby 1.9 support for encodings:

*         Identifiers can be non-ANSI by default.

Ruby 2.0 support for encodings:

*         Each string and symbol knows its own encoding, and String#force_encoding can change the encoding of an existing string.

*         IO#encoding to control encoding to use for reading/writing from disk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090213/158c5556/attachment-0001.html>

More information about the Ironruby-core mailing list