From: Joel VanderWerf Date: 2004-03-25T06:45:37+09:00 Subject: Re: How to avoid duplicate object creations? Robert Klemme wrote: > AFAIK there is no hook in Marshal and Yaml that would allow to provide your > own object creation. Someone correct me if I'm wrong here. For Marshalled objects, you can define a YourClass._load and YourClass#_dump (note the first is a class method). The former can look at the marshalled data as a string and decide what object to create. The latter is what generates that string. See the Pickaxe for details. In Yaml, it's possible too, if you don't mind defining a custom ruby-type, in which case you are allowed to construct an object from the yaml data. I'm not sure if there is a hook to do this without defining a custom type. For examples, see yaml/rubytypes.rb in your ruby lib. The value returned from the block you give to "add_ruby_type" is the value that used for the object.