Loading a yaml File

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.

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}
}