Forum: Ruby Question about -K, $KCODE, command line

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel B. (Guest)
on 2006-05-26 22:42
(Received via mailing list)
Hi all,

If I run a program from the shell like "ruby test.rb -K u", why isn't
$KCODE set within the program to "UTF8"?

# test.rb
puts $KCODE

ruby test.rb -K u -> "NONE" ???

It looks like the only way to change it is to assign to $KCODE directly
within the program.  Why? Would changing $KCODE from a command line
option have unintended side effects?

Dan
Ross B. (Guest)
on 2006-05-26 23:01
(Received via mailing list)
On Sat, 2006-05-27 at 03:38 +0900, Daniel B. wrote:
> It looks like the only way to change it is to assign to $KCODE directly
> within the program.  Why? Would changing $KCODE from a command line
> option have unintended side effects?

You need -Ku, not -K u. The K is being taken as empty, and the 'u' is
being passed as an argument to your script.

$ ruby -Ku -e 'puts $KCODE'
UTF8
$ ruby -e 'puts $KCODE' -Ku
UTF8
Daniel B. (Guest)
on 2006-05-26 23:20
(Received via mailing list)
Ross B. wrote:
>>
> UTF8
>

I tried that.

Actually, my *real* problem was that I was putting the option *after*
the program name.  DUH!

Thanks,

Dan
This topic is locked and can not be replied to.