[Ruby] enterprise
ふと思いたって、こんなことを試してみた。
$ cat hello.rb
# -*- encoding:utf-8 -*-
# UTF-8 なファイルだとどうなるかテスト
class Foo
def bar
a = "これは"
b = "テスト"
puts (a + b).encoding
puts (a + b).encode("EUCJP")
end
end
Foo.new.bar
$ ruby -v hello.rb
ruby 1.9.2dev (2009-06-15 trunk 23694) [i686-linux]
UTF-8
これはテスト
$ enterprise hello.rb
ruby_parser-2.0.2/lib/ruby_lexer.rb:638:in `scan': \
invalid byte sequence in EUC-JP (ArgumentError)
それでは、ruby の -E オプションを使ってみる。
$ ruby -Eutf-8 /usr/local/ruby-trunk/bin/enterprise hello.rb
xmlに変換できた。 enterprise_ruby を試そう。
$ enterprise_ruby hello.xml
enterprise/file_loader.rb:5:in `eval': "\xE3" to UTF-8 in conversion
from ASCII-8BIT to UTF-8 to EUC-JP (Encoding::UndefinedConversionError)
それじゃあと
$ ruby -Eutf-8 /usr/local/ruby-trunk/bin/enterprise_ruby hello.xml
enterprise/file_loader.rb:5:in `eval': "\xE3" to UTF-8 in conversion
from ASCII-8BIT to UTF-8 to EUC-JP (Encoding::UndefinedConversionError)
$ ruby -E:utf-8 /usr/local/ruby-trunk/bin/enterprise_ruby hello.xml
enterprise/file_loader.rb:5:in `eval': "\xE3" to UTF-8 in conversion
from ASCII-8BIT to UTF-8 to EUC-JP (Encoding::UndefinedConversionError)
$ ruby -Eutf-8:utf-8 /usr/local/ruby-trunk/bin/enterprise_ruby hello.xml
enterprise/file_loader.rb:5:in `eval': "\xE3" to UTF-8 in conversion
from ASCII-8BIT to UTF-8 to EUC-JP (Encoding::UndefinedConversionError)
うーむ。 ちなみに hello.xml の中には、
# -*- encoding:utf-8 -*-
に相当すると思われる記載は見当たらず。
US-ASCII 以外は、まだちゃんと扱えないかも。
| 固定リンク
この記事へのコメントは終了しました。
コメント