On Mon, Jun 07, 2004 at 10:33:37PM +0900, Anders Bengtsson wrote:
> Hi,
> 
> I've run into a problem when replacing "Marshal.dump" with "YAML.dump".
> Some of my classes use custom marshalling, with "_dump" and "_load"
> methods. With YAML these methods are not used, which breaks the
> application.
> 
> YAML uses an object's "to_yaml" method if available. But that method
> expects valid YAML code to be returned, unlike "_dump" that can return
> just about anything. Also there doesn't seem to be anything
> corresponding to "_load".
> Any ideas about how I can make things compatible with both Marshal and
> YAML at the same time?

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

_load is a class method!

Regards,

  Michael