Need help to detect error

I don’t know what am I doing wrong, can anyone help me?
These two programs look very similar, but they yield different results.
Can anyone confirm this “error”?

=================================================================

FAILING EXAMPLE

=================================================================
class Battlefield
attr_accessor :teams
def initialize
@teams = []
end
def add_team(team)
@teams << team
team.bparent = self
end
end

class Team
attr_accessor :members, :bparent
def initialize
@members = []
@bparent = nil
end
def add_member(child)
@members << child
child.team = self
end
end

class Warrior
attr_accessor :team
def initialize
@team = nil
end
end

w = Warrior.new
t = Team.new
t.add_member(w)
b = Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y = YAML.load(b.to_yaml)
#Now have a look at the “members” array inside a team… it’s gone
y.inspect
y.teams.first.members.inspect

=================================================================

GOOD EXAMPLE

=================================================================
require ‘yaml’

class Battlefield
attr_accessor :teams
def initialize
@teams = []
end
def add_team(team)
@teams << team
team.parent = self
end
end

class Team
attr_accessor :members, :parent
def initialize
@members = []
@parent = nil
end
def add_member(child)
@members << child
child.team = self
end
end

class Warrior
attr_accessor :team
def initialize
@team = nil
end
end

w = Warrior.new
t = Team.new
t.add_member(w)
b = Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y = YAML.load(b.to_yaml)
#Now have a look at the “members” array inside a team, it’s still there
y.inspect
y.teams.first.members.inspect

Or anyone knows where can I contact some YAML guys to help me with this
obscure problem?

El mié, 11-11-2009 a las 16:58 +0900, Víctor Adrián de la Cruz Serrano
escribió:

That’s bizarre. All that I can see that’s different is because the
failing
version uses the attribute “bparent” and the other uses “parent”, the
backreferences occur in different places in the resulting YAML. I
believe
that Syck was taking over when _why left - you ought to file a bug.

(Unless there’s an obscure YAML rule that backreferences have to occur
after
literal values…)

Judson

2009/11/11 Víctor Adrián [email protected]

Yeah, but I don’t know where exactly should I report it. What is the
link to their bug tracker?

Exactly, the difference is only one char.
And I have found that it works with words like: parent, parenta,
parenton, parent.
But it fails with words like: battle, battlefield, bparent.

Strange, isn’t it?

El jue, 12-11-2009 a las 09:41 +0900, Judson L. escribió:

The single character difference tends to corroborate the cause of the
bug:
the reference that’s generated by #to_yaml fails if it comes earlier in
the
map - first, not last, not sure the details.

As to where to post bugs, Syck has been accepted into the standard
library
(one of many incredible contributions by _why) so I’d imagine that the
bugs
would be posted to http://redmine.ruby-lang.org/

Judson

2009/11/12 Víctor Adrián [email protected]