[ruby-list:45773] Re: Ruby 1.9.1-rc1[mswin32]でマルチバイトを含むソースが実行できない

From: "Ayumu Aizawa" <ayumu.aizawa@...>
Date: 2009-01-01 08:43:20 UTC
List: ruby-list #45773
と、これを書いた後で気がついたんですが、ruby --helpででてくる表示から-Kkcodeが
消えています(実際は使えるみたいですが)。

そして-Eex[:in]というオプションが追加されているみたいなのですが、これの使い方が
よくわからないです。

  -Eex[:in]       specify the default external and internal character encodings
 →規定の外部/内部エンコーディングを指定する

ということみたいなのですが、先ほどの例に-Esjis:sjis を指定してもやはりASCIIと解釈
されている(?)みたいです。

C:\tmp>type test_sjis.rb
str = "あいうえお"
puts str

C:\tmp>ruby -v -Esjis:sjis test_sjis.rb
ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [i386-mswin32]
test_sjis.rb:1: invalid multibyte char (US-ASCII)
test_sjis.rb:1: invalid multibyte char (US-ASCII)

C:\tmp>ruby -v --help
ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [i386-mswin32]
Usage: ruby [switches] [--] [programfile] [arguments]
  -0[octal]       specify record separator (\0, if no argument)
  -a              autosplit mode with -n or -p (splits $_ into $F)
  -c              check syntax only
  -Cdirectory     cd to directory, before executing your script
  -d              set debugging flags (set $DEBUG to true)
  -e 'command'    one line of script. Several -e's allowed. Omit [programfile]
  -Eex[:in]       specify the default external and internal character encodings
  -Fpattern       split() pattern for autosplit (-a)
  -i[extension]   edit ARGV files in place (make backup if extension supplied)
  -Idirectory     specify $LOAD_PATH directory (may be used more than once)
  -l              enable line ending processing
  -n              assume 'while gets(); ... end' loop around your script
  -p              assume loop like -n but print line also like sed
  -rlibrary       require the library, before executing your script
  -s              enable some switch parsing for switches after script name
  -S              look for the script using PATH environment variable
  -T[level]       turn on tainting checks
  -v              print version number, then turn on verbose mode
  -w              turn warnings on for your script
  -W[level]       set warning level; 0=silence, 1=medium, 2=verbose (default for
 level)
  -x[directory]   strip off text before #!ruby line and perhaps cd to directory
  --copyright     print the copyright
  --version       print the version

2009/01/01 17:30 Ayumu Aizawa <ayumu.aizawa@gmail.com>:
> 木村さん
> ありがとうございます。
> マジックコメントを入れて実行したら期待通りの動きをしました。
> そして-Kオプションで規定のエンコードを指定する方法でも良いみたいですね。
>
>
> C:\sandbox>type test_sjis.rb
> # -*- coding: sjis -*-
> str = "あいうえお"
> puts str
> C:\sandbox>ruby -v test_sjis.rb
> ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [i386-mswin32]
> あいうえお
>
> 2009/01/01 16:57 KIMURA Koichi <hogemuta@gmail.com>:
>> 木村です。
>> あけましておめでとうございます。
>>
>> Ayumu Aizawa さんは書きました:
>>> あけましておめでとうございます。あいざわです。
>>> 昨日[ruby-list:45759]で公開されたインストールパッケージを使用してRuby-1.9.1-rc1を動かしてみたのですが
>>> 日本語(マルチバイト)が含まれるソースを動かそうとするとエラーとなってしまいます。
>>> sjisで書いたファイルとutf-8で書いたファイル両方で試してみたのですが結果は同じでした。
>>> Ruby1.8では期待通り動作します。
>>>
>>> OS: Windows XP SP3
>>> Ruby 1.9.1-rc1
>>>
>>> *test_sjis.rbはShift-JISで保存。
>>>
>>> C:\tmp>type test_sjis.rb
>>> str = "あいうえお"
>>> puts str
>>
>> マジックコメントをつけていないのですか?
>> つけていないのでエンコーディングが
>>
>>> C:\tmp>ruby -v test_sjis.rb
>>> ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [i386-mswin32]
>>> test_sjis.rb:1: invalid multibyte char (US-ASCII)
>>> test_sjis.rb:1: invalid multibyte char (US-ASCII)
>>
>> US-ASCII扱いになっておかしくなっているのではないですか?
>>
>>
>> --
>> 木村浩一/KIMURA Koichi
>>  I thought what I'd do was, I'd pretend I was one of those deaf-mutes or
>> shoud I?
>>  mail kbk at kt.rim.or.jp
>>  web  www.kt.rim.or.jp/~kbk/zakkicho/index.html
>>
>>
>
>

In This Thread