From: Sylvain Joyeux Date: 2007-03-20T16:45:32+09:00 Subject: Re: [ ruby-Bugs-9376 ] Marshal.dump shouldn't complain about singletons if the _dump method is defined > |But what if that singleton class just contained a method that allowed > |direct access to a variable, or a quick hack to mutate something, > |should those methods make it so it cannot be dumped. Can't the > |interpreter just assume we know what we are doing? > I am not sure if we know what we are doing here. Dumping objects > without singleton information may trigger serious problems, that can > happen too easily. I don't see why as soon as the dumping/loading is done by user code. I defined _dump, if the singleton state is important, it is my job to save it anyway. So ... If triggering serious problems concerns you, you could also forbid inheritance from core classes (trust me, inheriting from Array or Hash can trigger serious problems too). > You can define its own marshal_dump method if you really want to dump > the object. No you can't, or I wrongly guessed how marshal_dump should be defined (marshal_dump and _dump are really not documented enough) [~]% cat bla.rb class Test def marshal_dump "" end end t = Test.new class << t @bla = 10 end Marshal.dump(t) [~]% ruby bla.rb bla.rb:11:in `dump': singleton can't be dumped (TypeError) from bla.rb:11 Thanks for looking into this Sylvain Joyeux