From: Yusuke ENDOH Date: 2010-02-04T21:01:12+09:00 Subject: [ruby-core:28052] [Bug:trunk] invalid yaml emitted for Struct Hi, Aaron Patterson -- lib/yaml seems to emit invalid yaml document for Struct: $ ./ruby -ryaml -e ' Person = Struct.new(:name, :gender) puts Person.new("Jane", "female").to_yaml ' --- !ruby/struct:Person :name: Jane :gender: female The colon immediately before key names should not be emitted, I think. This causes rubyspec failure. 1) Object#to_yaml returns the YAML representation of a Struct object FAILED Expected "--- !ruby/struct:Person \n:name: Jane\n:gender: female\n" to match "--- !ruby/struct:Person\nname: Jane\ngender: female\n" /home/mame/work/ruby/spec/rubyspec/library/yaml/to_yaml_spec.rb:58:in `block (2 levels) in ' /home/mame/work/ruby/spec/rubyspec/library/yaml/to_yaml_spec.rb:5:in `' This seems because the type of each element of Struct#members are changed from String to Symbol on 1.9. In fact, the following patch works. diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb index e8c0c89..71f911a 100644 --- a/lib/yaml/rubytypes.rb +++ b/lib/yaml/rubytypes.rb @@ -72,7 +72,7 @@ class Struct # st = YAML::object_maker( struct_type, {} ) st.members.each do |m| - st.send( "#{m}=", val[m] ) + st.send( "#{m}=", val[m.to_s] ) end props.each do |k,v| st.instance_variable_set(k, v) @@ -89,7 +89,7 @@ class Struct # out.map( taguri, to_yaml_style ) do |map| self.members.each do |m| - map.add( m, self[m] ) + map.add( m.to_s, self[m.to_s] ) end self.to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) Could you commit this? Thanks, -- Yusuke ENDOH