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}
}
On May 19, 1:36 pm, jef
<jfferri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---