From: Martin Hart Date: 2004-02-12T23:22:33+09:00 Subject: YAML and Class Hi all, I notice that the default YAML (ruby 1.8.1) does not dump or load Class by default. I have extended my local copy to do so, but now I wonder if there is a reason why it does not support this feature that I have overlooked/not fully appreciated? Cheers, Martin FYI - this is my patch (Is there another way of creating a class without having to eval the string?) YAML.add_ruby_type(/^class/) { |type, val| val =~ /\A[A-Z][A-Za-z0-9_]*(::[A-Z][A-Za-z0-9_]*)*\z/ or raise YAML::Error, "Invalid Class: #{val.inspect}" eval val } class Class def to_yaml(opts = {}) YAML::quick_emit(nil, opts) { |out| out << "!ruby/class " self.name.to_yaml(:Emitter => out) } end def is_complex_yaml? false end end