# YAML::Syck::Map.children\_with\_index has a non-useless mode?

**URL:** <https://www.ruby-forum.com/t/yaml-map-children-with-index-has-a-non-useless-mode/78972>\
**Category:** Ruby\
**Created:** [December 11, 2006, 5:46am UTC](https://www.ruby-forum.com/t/yaml-map-children-with-index-has-a-non-useless-mode/78972 "2006-12-11T05:46:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [December 11, 2006, 5:46am UTC](https://www.ruby-forum.com/t/yaml-map-children-with-index-has-a-non-useless-mode/78972/1 "2006-12-11T05:46:53Z")

</div>

Ruboids:

I have some dirt-simple YAML, and I need to traverse the object model  
returned by YAML.parse().

So if the top-level object is a Map (corresponding naturally to a native  
Hash), how do I get the keys and values?

Try this:

```
map.children_with_index.each do |kid, key|
        p kid
        p key
      end

```

The 'key’s come out healthy Scalars, but the 'kid’s are always nil!  
Permutations involving map[key] and map.at(key) also return nil, because  
that’s what

Oh why can’t I get non-nil kids from my map?? (Without using  
map.value[key]  
to go down to the Hash - because I don’t want to!)

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [December 11, 2006, 6:06am UTC](https://www.ruby-forum.com/t/yaml-map-children-with-index-has-a-non-useless-mode/78972/2 "2006-12-11T06:06:54Z")

</div>

Phlip wrote:

> ```
> map.children_with_index.each do |kid, key|
> p kid
> p key
> end
> 
> ```
> 
> The 'key’s come out healthy Scalars, but the 'kid’s are always nil!  
> Permutations involving map[key] and map.at(key) also return nil, because  
> that’s what
> 
> Oh why can’t I get non-nil kids from my map?? (Without using  
> map.value[key] to go down to the Hash - because I don’t want to!)

The problem might lie in your code, or your YAML database. The parts  
that  
are not in your message.
