From: O01eg Oleg on
When I require file with UTF-8 encoding I get error:

irb(main):001:0> require '/tmp/share/mudserver/game.rb'
SyntaxError: /tmp/share/mudserver/game.rb:2: invalid multibyte char
(US-ASCII)
/tmp/share/mudserver/game.rb:2: invalid multibyte char (US-ASCII)
/tmp/share/mudserver/game.rb:2: syntax error, unexpected $end, expecting
keyword_end

when I simply assign unicode string to variable I don't get any error.
In C API I have such problem with rb_require and rb_eval_string.
I think that I have to set encoding for required files but cann't find
how.
P.S. I try use $KCODE but it no longer work:

irb(main):006:0> $KCODE = 'u'
(irb):6: warning: variable $KCODE is no longer effective; ignored

I try require recommended in Internet 'jcode' but it isn't exist and try
to add u prefix for string, but it cause error even in evalation:

irb(main):005:0> intro = u"привет"
NoMethodError: undefined method `u' for main:Object
--
Posted via http://www.ruby-forum.com/.

From: O01eg Oleg on
Caleb Clausen wrote:
> Are you using ruby 1.9? If so, then you need to add a magic encoding
> line as the first line (or second if the first is a shebang line) of
> your source file, like this:
> # encoding: utf-8
Thanks, it work.
--
Posted via http://www.ruby-forum.com/.