From: WATANABE Hirofumi Date: 2003-05-01T00:00:34+09:00 Subject: [ruby-dev:20124] Re: jcode.rb わたなべです。 Shin-ichiro HARA writes: > import-module では、こんなふうに使います: > > require 'import-module' > require 'jstring_2' > $KCODE='e' > > str1 = 'あいうえお' > str2 = 'あいうえお' > > str1.import(JString) do > p str1[2] # => "う" > p str2[2] # => 164 > p str1.chop #=> "あいうえ" > p str2.chop #=> "あいうえ\244" > str2.import(JString) do > p str1[2] # => "う" > p str2[2] # => "う" > p str1.chop #=> "あいうえ" > p str2.chop #=> "あいうえ" > end > end > p str1.import(JString){|s| s[2]} #=> "う" > p str1[2] # => 164 > p str1.import(JString){str1.chop} #=> "あいうえ" > p str2.chop #=> "あいうえ\244" > > これは今の jstring_2.rb でも動いています。 これを動かすと % ruby test-jstring_2.rb ./jstring_2.rb:77: warning: character class has `]' without escape ./jstring_2.rb:77: warning: character class has `[' without escape ./jstring_2.rb:77: warning: character class has `]' without escape ./jstring_2.rb:77: warning: character class has `[' without escape "う" 164 test-jstring_2.rb:11: private method `chop' called for "あいうえお":String (NoMethodError) from test-jstring_2.rb:8:in `import' from /usr/local/lib/ruby/site_ruby/1.8/import-module.rb:407:in `import_module' from /usr/local/lib/ruby/site_ruby/1.8/import-module.rb:407:in `import' from test-jstring_2.rb:8 とエラーになってしまいます。 import-moduleは最新と思われる0.77を、Rubyは ruby 1.8.0 (2003-04-27) [i386-linux] ruby 1.6.8 (2003-04-20) [i386-linux] を使ってます。 原因はrb_define_global_function化してる所為かな。 実はimport-moduleも試したんですが、エラーになったので、 > >|原先生のimport-moduleでもできると思いますが、 > >|どちらか標準にならないかなあ。 とあいまいにごまかしたのでした。 > 石塚さんの scope-in-state は、もうちょっと大規模なシステムの > 変更も念頭にあって、手軽さでは import-module かな。 そうなんですよね。newしないで使えるからお手軽でimport-module のほうが好みなんですが。 -- わたなべひろふみ