From: Takashi SUGA Date: 2002-03-11T16:38:18+09:00 Subject: [ruby-list:34313] singleton と  Marshal.dump $B?\2l$G$9!#(B singleton $B$H(BMarshal.dump$B$N4X78$GH=$i$J$$$H$3$m$,$"$k$N$G65$($F$/$@$5$$!#(B t2 $B$N$U$k$^$$$+$i$9$k$H!"(Bt1.foo $B$O(B Test $B%/%i%9$G$O$J$/$F!"(Bt1 $B%*%V%8%'%/%H$K(B $B4XO"$E$1$i$l$F$$$k$h$&$K8+$($k$N$G$9$,!"(Bt1 $B$,(B Marshal.dump $B$G$-$k$N$O2?8N$J(B $B$N$G$7$g$&$+(B? Ruby $B$N%P!<%8%g%s$O(Bruby 1.6.4 (2001-06-04) [i386-cygwin]$B$G$9!#(B module Foo; def foo; 'Test1' end end class Test; def baz; class << self; include Foo end end end t1 = Test.new; t1.baz t2 = Test.new t3 = Test.new; class << t3; def foo; 'Test3' end end t4 = Test.new; def t4.foo; 'Test4' end p t1.foo # "Test1" p t2.foo # undefined method `foo' for # (NameError) p t3.foo # "Test3" p t4.foo # "Test4" p Marshal.dump(t1) # "\004\005o:\tTest\000" p Marshal.dump(t2) # "\004\005o:\tTest\000" p Marshal.dump(t3) # singleton can't be dumped (TypeError) p Marshal.dump(t4) # singleton can't be dumped (TypeError) -- ////////// $B?\2l(B $BN4(B ///////////////////////// SGB02104@nifty.com //////// // http://www.asahi-net.com/~dd6t-sg/ mailto:suchowan@box.email.ne.jp //