# I'm having a little issue with YAML

**URL:** <https://www.ruby-forum.com/t/im-having-a-little-issue-with-yaml/178220>\
**Category:** Ruby\
**Created:** [October 31, 2009, 6:12am UTC](https://www.ruby-forum.com/t/im-having-a-little-issue-with-yaml/178220 "2009-10-31T06:12:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdriSSSSn\_De\_la\_Cru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@AdriSSSSn\_De\_la\_Cru](https://www.ruby-forum.com/u/AdriSSSSn_De_la_Cru)\
**Post date:** [October 31, 2009, 6:12am UTC](https://www.ruby-forum.com/t/im-having-a-little-issue-with-yaml/178220/1 "2009-10-31T06:12:28Z")

</div>

Hi guys,

I’m seeing some strange behavior with YAML serialization/deserialization  
and would like someone to explain what’s going on with this, if  
possible.

I attached two files that you can run with:  
spec battle\_spec.rb (this one fails)  
spec battle2\_spec.rb (this one doesn’t fail)

The difference between the two, is just a character in the name of an  
instance variable.

The source code is very simple. It has three classes to represent a  
nested structure:

A Battlefield might contain many teams, a Team might contain many  
Warriors. In my sample it’s just one of each, to keep it simple.

The problem is that, the Team @members are nullified in some cases.

battle\_spec.rb shows a case where Team#members is nil.  
battle2\_spec.rb shows a case where Team#members is not nil (just  
changing a character in a instance variable name, the one that makes the  
Battlefield accessible for a Team [a var to point to its parent]).

I’m kinda new to this testing stuff, maybe I’m doing something wrong, if  
that’s the case, I’ll be glad to hear any advice or pointers.

If you need more info, I’ll be glad to provide it.

Best regards,  
VÃ­ctor AdriÃ¡n.

---

<div class="post-metadata">

**Author:** ![AdriSSSSn\_De\_la\_Cru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@AdriSSSSn\_De\_la\_Cru](https://www.ruby-forum.com/u/AdriSSSSn_De_la_Cru)\
**Post date:** [November 3, 2009, 7:54pm UTC](https://www.ruby-forum.com/t/im-having-a-little-issue-with-yaml/178220/2 "2009-11-03T19:54:33Z")

</div>

2009/10/31 Adrián De la Cruz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi guys,
> 
> I’m seeing some strange behavior with YAML serialization/deserialization  
> and would like someone to explain what’s going on with this, if  
> possible.

It seems that it has something to do with order. If you check  
generated YAML, the members are listed alphabetically.  
So if you call it @bparent it comes before @members, and after  
@members if it’s @parents.

If I comment out line “child.team = self” I get proper @members, but  
without @team attribute.

Hypothesis is that order of object creation is important here. I  
suggest browsing ruby bugtracker and or sources 🙂
