From: Aaron Schrab Date: 2005-09-23T06:14:02+09:00 Subject: Outputting custom YAML types in 1.8.3 I just upgraded my main development box (Debian unstable) to the new ruby 1.8.3 packages, and noticed a change in the behaviour of custom- defined #to_yaml methods. Simplified example code: require 'yaml' class Foo def to_yaml_type; "!example.com,2005/Foo"; end def to_yaml( opts={} ) YAML::quick_emit( object_id, opts ) do |out| out.map( to_yaml_type ) do |map| map.add :foo, 'bar' map.add :one, 2 end end end end puts( { 'a' => Foo.new }.to_yaml ) With previous versions this produced: --- a: !example.com,2005/Foo :foo: bar :one: 2 The output that I now get is: a: :foo: bar :one: 2 So there are a couple changes. First it's no longer outputting a line of dashes at the beginning. Second, and more importantly, it's no longer including the type information. Things work fine if I just define #to_yaml_type and #to_yaml_properties instead of #to_yaml, but I can't do that for some of my classes. I can also get it to work if I call yaml_as for the class and use the #taguri method generated by that as the argument when calling out.map(), but this wouldn't be compatible with older versions. Is this a bug, or is there something that I should be doing different? -- Aaron Schrab aaron@schrab.com http://www.schrab.com/aaron/ When you're dealing with like crazy aggressors like Libya or Iran or Microsoft, you are talking about people who could do anything. -- Bill Maher