A
Aaron Schrab
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
ne, 2
end
end
end
end
puts( { 'a' => Foo.new }.to_yaml )
With previous versions this produced:
---
a: !example.com,2005/Foo
:foo: bar
ne: 2
The output that I now get is:
a:
:foo: bar
ne: 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?
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
end
end
end
end
puts( { 'a' => Foo.new }.to_yaml )
With previous versions this produced:
---
a: !example.com,2005/Foo
:foo: bar
The output that I now get is:
a:
:foo: bar
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?