# Need help to detect error

**URL:** <https://www.ruby-forum.com/t/need-help-to-detect-error/178782>\
**Category:** Ruby\
**Created:** [November 11, 2009, 8:58am UTC](https://www.ruby-forum.com/t/need-help-to-detect-error/178782 "2009-11-11T08:58:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/u/VSSS_ctor_AdriSSSSn)\
**Post date:** [November 11, 2009, 8:58am UTC](https://www.ruby-forum.com/t/need-help-to-detect-error/178782/1 "2009-11-11T08:58:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/u/VSSS_ctor_AdriSSSSn)\
**Post date:** [November 12, 2009, 1:45am UTC](https://www.ruby-forum.com/t/need-help-to-detect-error/178782/2 "2009-11-12T01:45:40Z")

</div>

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Ã³:

---

<div class="post-metadata">

**Author:** ![VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/u/VSSS_ctor_AdriSSSSn)\
**Post date:** [November 12, 2009, 1:46am UTC](https://www.ruby-forum.com/t/need-help-to-detect-error/178782/3 "2009-11-12T01:46:15Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/u/VSSS_ctor_AdriSSSSn)\
**Post date:** [November 12, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/need-help-to-detect-error/178782/4 "2009-11-12T17:48:32Z")

</div>

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Ã³:

---

<div class="post-metadata">

**Author:** ![VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@VSSS\_ctor\_AdriSSSSn](https://www.ruby-forum.com/u/VSSS_ctor_AdriSSSSn)\
**Post date:** [November 16, 2009, 9:00pm UTC](https://www.ruby-forum.com/t/need-help-to-detect-error/178782/5 "2009-11-16T21:00:52Z")

</div>

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/](http://redmine.ruby-lang.org/)

Judson

2009/11/12 VÃ­ctor AdriÃ¡n [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
