From: Shin-ichiro HARA Date: 2003-04-30T19:13:09+09:00 Subject: [ruby-dev:20118] Re: jcode.rb 原です。 >まつもと ゆきひろです >|わたなべです。 >|以前石塚さんのscope-in-sateの話が出たときに >| >| module Jcode >| module String >| ... >| end >| end >| >|という構成にすれば >| >| ScopeJcode = ScopeInState.new(Jcode) >| >| p 'あい'.chop #=> "あ\244" >| ScopeJcode.scope_in do >| p 'あい'.chop #=> "あ" >| end >| p 'あい'.chop #=> "あ\244" >| >|とできていいんじゃないかなと思ったことがあります。 >|原先生のimport-moduleでもできると思いますが、 >|どちらか標準にならないかなあ。 > >標準にするのは構わないんですが、似たようなのが複数あるのは避 >けたいので、どちらを選ぶかですよね。実際に使った人の感想が聞 >きたいです。あ、もちろん作った人の感想も。 実際に使って見た人いるんですかね。私も感想が聞きたいです。 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 でも動いています。 石塚さんの scope-in-state は、もうちょっと大規模なシステムの 変更も念頭にあって、手軽さでは import-module かな。 もっとも、import-module の中身は大分石塚さんのアイデアを取り 込んでるんですが。