From: Kjetil Orbekk Date: 2006-12-26T23:11:18+09:00 Subject: YAML problem with serializing of nested object structures Hi! I'm making a graph tool, and i have some problem with the serialization of my graphs. The problem comes when i try to load a graph i earlier serialized with YAML. In the objects i serialize, I have two instance variables (arrays, as below) that contain some other objects of similar type (also serialized). I managed to reproduce the problem with a simpler object structure below. To me, this seems very wierd, especially since it saves some data and breaks it when loading. Could it be a bug, or am I doing something wrong here? ruby --version is "1.8.4 (2005-12-24) [i486-linux]". My operating system is Debian GNU/Linux 4.0. Ruby code: ---------- require "yaml" # Test class with two instance variables to hold arrays with similar # objects class Test attr_accessor :c1, :c2 def initialize(c1=[], c2=[]) @c1, @c2 = c1, c2 end end a = Test.new b = Test.new([a],[Test.new]) a.c1 << b a.c2 << b # The problem comes when saving the whole thing as an array ary = [a, b] yaml1 = YAML.dump(ary) # +ary_from_yaml[0]+ looses its c2 even though it's clearly in the YAML output ary_from_yaml = YAML.load(yaml1) yaml2 = YAML.dump(ary_from_yaml) print "YAML 1\n" + yaml1 + "\n\n" print "YAML 2\n" + yaml2 + "\n\n" print "YAML 1 length: #{yaml1.length} \tYAML 2 length: #{yaml2.length}" -- ,= ,-_-. =. Do not use proprietary formats, ((_/)o o(\_)) use Free Software and open formats `-'(. .)`-' - www.gnu.org \_/ - www.openformats.org