description
Works in regular Ruby. Does not work in IronRuby because the deserialized type is IronRuby::StandardLibrary::Yaml::PrivateType and not what it should be. Repro code below.
require 'yaml'
require 'pp'
class Test < Hash
attr_accessor :a
attr_accessor :b
def initialize(a, b, value)
super(value)
self["key1"] = 10
self["key2"] = 20
@a = a
@b = b
end
def yaml_initialize(tag, val)
@a = val.delete("a")
@b = val.delete("b")
super.update(val)
end
def to_yaml( opts = {} )
YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
self.each do |k, v|
map.add( k, v )
end
self.instance_variables.sort.each { |iv|
map.add( iv[1..-1], instance_eval( iv.to_s ) )
}
end
end
end
end
test = Test.new(4, 3, { 'a' => 1, 'b' => 2})
yaml = YAML.dump(test)
back = YAML.load(yaml)
puts yaml
puts back.class
puts back.taguri
pp back
pp back.a
pp back.b