From: Anders Bengtsson Date: 2004-06-07T23:06:53+09:00 Subject: Re: Custom marshalling with YAML --- 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 then YAML.dump(Foo.new) will return "foo". But that's no good, since there's nothing to tell it that this "foo" should be de-YAMLed into a new Foo instance. Marshal.dump(Foo.new) will return "\004\010u:\010Foo\010foo", with all the needed meta-data. > _load is a class method! Yes. :) But what's the corresponding method for YAML? /Anders ===== __________________________________________________ Anders Bengtsson ndrsbngtssn@yahoo.se Stockholm, Sweden H�strusk och gr� moln - k�p en resa till solen p� Yahoo! Resor p� adressen http://se.docs.yahoo.com/travel/index.html