From: Michael Neumann Date: 2004-06-07T23:49:28+09:00 Subject: Re: Custom marshalling with YAML On Mon, Jun 07, 2004 at 11:06:53PM +0900, Anders Bengtsson wrote: > --- Michael Neumann wrote: > > How about this: > > > > module Kernel > > def to_yaml > > if respond_to? :_dump > > _dump(nil).to_yaml # TODO: _dump takes one paramter > > else > > raise > > end > > end > > end > > That would be a nice solution. But the string returned by _dump > probably won't be valid YAML. > > If I have the following class > > class Foo > def _dump(x) > "foo" > end > > def to_yaml > _dump > end > end Take a look at lib/yaml/rubytypes.rb. There's a to_yaml_type and a YAML.add_ruby_type method. Maybe this is a start. Regards, Michael