From: "NAKAMURA, Hiroshi" Date: 2003-10-10T11:38:29+09:00 Subject: [ruby-dev:21590] extend with marshal_dump/marshal_load なひです。 marshal_dump/marshal_loadが定義されていると、ivar同様、 extendもdumpされませんが、これは仕様でいいでしょうか。 ((class << self; self; end).ancestors - self.class.ancestors).collect { |m| m.name }.join(" ") をBar#marshal_dumpで返しておいて、Bar#marshal_loadで元に戻す という方法もありますが、例えばBaz#marshal_loadとか呼びたい場合には 間に合わないですよねぇ。。。 (Bar#marshal_loadよりBaz#marshal_loadを先に呼びたい) class Foo def marshal_load(obj); end def marshal_dump; end end class Bar < Foo def marshal_load(obj); end def marshal_dump; end end module Baz; end o1 = Bar.new o1.extend(Baz) o2 = Marshal.load(Marshal.dump(o1)) p (class << o1; self; end).ancestors # => [Baz, Bar, Foo, Object, Kernel] p (class << o2; self; end).ancestors # => [Bar, Foo, Object, Kernel]