# Loading a yaml File

**URL:** <https://www.ruby-forum.com/t/loading-a-yaml-file/138045>\
**Category:** Rails\
**Created:** [May 19, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/loading-a-yaml-file/138045 "2008-05-19T19:37:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jef](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@jef](https://www.ruby-forum.com/u/jef)\
**Post date:** [May 19, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/loading-a-yaml-file/138045/1 "2008-05-19T19:37:35Z")

</div>

Hi there.

I have a yaml file like this:

* * *

## first\_name: “paul” age: 23

## first\_name: “peter” age: 26

first\_name: “luc”  
age: 40

I load my yaml file in a variable called data:  
data = YAML.load\_file(“my\_file.yaml”)

I only get the first register.

I would like to get the whole file in a array like that:  
[{“first\_name”=\>“paul”,“age”=\> 23},{“first\_name”=\>“pierre”,“age”=\> 26},  
{“first\_name”=\>“luc”",“age”=\> 40}]

How can i do that

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![jef](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@jef](https://www.ruby-forum.com/u/jef)\
**Post date:** [May 19, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/loading-a-yaml-file/138045/2 "2008-05-19T21:13:04Z")

</div>

I think you need to change the file along these lines:

person1:  
first\_name: paul  
age: 23  
person2:  
first\_name:peter  
age: 26  
person3  
first\_name: luc  
age: 40

That structure should give you a hash to iterate:  
{  
“person1”=\>{“first\_name”=\>“paul”,“age”=\> 23},  
“person2”=\>{“first\_name”=\>“pierre”,“age”=\> 26},  
“person3”=\>{“first\_name”=\>“luc”",“age”=\> 40}  
}
