前田です。 In message "[ruby-list:7008] builtin class inherit" TEI meiki <tei / harmony.co.jp> wrote: |モデムの継ったシリアルデバイスファイルを uucp とバッティングしないように |uucp 流の排他制御付で扱いたくて、以下のようなクラスを作りかけました。 |ここで、File class が組み込みクラスで、インスタンス変数を持てなくて |name を保存できなくて困っています。 |こういう場合どうするのが ruby の御作法なのでしょう? 継承するのはやめてDelegatorを使うというのはどうでしょう。 イメージ的にはこんな感じでしょうか。 # 例によって試していません(^^; require "delegate" class TTY < Delegator class << TTY def new(name, mode) lockfile = "/usr/spool/locks/LCK..#{name}" if File.exist? lockfile fail "can't acquire lock" end open(lockfile, "w") do |f| f.printf("%10d\n", $$) end return super(open("/dev/" + name, mode), lockfile) end alias open new end def initialize(file, lockfile) @file = file @lockfile = lockfile super(file) end def close @file.close File.delete(@lockfile) end def __get_obj__ return @file end end -- 前田 修吾