From: "Mauricio Fernández" Date: 2004-11-17T22:58:56+09:00 Subject: Re: OpenStructable (was: OpenStruct#update) On Wed, Nov 17, 2004 at 10:26:48PM +0900, trans. (T. Onoma) wrote: > | | While you are at it, please consider > | | > | | http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3687 > | | > | | and the other msgs in that thread. > | > | Okay, thanks. So what constitutes compatible marshal data? > > Off the top of my head, would this work? > > def marshal_dump > Marshal.dump(@table) > end > > def marshal_load(obj) > @table = Marshal.load(obj) > @table.each_key{|key| self.new_ostruct_member(key) } > end It introduces an unneeded indirection level (you end up marshalling a string with the marshalled table; compare to http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3690) and doesn't solve the data compatibility problem: I believe that the goal is having # run with the new code File.open("data", "w"){|f| f.write Marshal.dump(OpenStruct.new(:a => 1))} # run with the old code p Marshal.load(File.read("data")) # we want => OpenStruct, not String or Hash and vice versa. -- Hassle-free packages for Ruby? RPA is available from http://www.rubyarchive.org/