From: Kamarulnizam Rahim Date: 2011-01-27T12:58:24+09:00 Subject: Adding contents on yaml file without overwriting actual contents Hi, By running the following codes: --------------------------------------------------------------------------- convert_yaml = YAML::load_file('nizam.yaml') pp convert_yaml["System"]["Environmental"]["children"][2]["children"] convert_yaml["System"] = { "children" => [{"name"=>"nizam", "type"=>"Objective", "subtype"=>"None", "components"=> [{"type"=>"ContentBox", "title"=>"Audit", "args"=>{:content=>"None\n"}}, {"type"=>"ChildListingComponent", "title"=>"Current Targets for the Audit Objective:"}]}]} File.open("nizam_out.yaml", "w"){|f| YAML.dump(convert_yaml, f)} My yaml output turns out to be like this: -------------------------------------------------------------------------- System: children: - name: nizam type: Objective subtype: None components: - type: ContentBox title: Audit args: :content: | None - type: ChildListingComponent title: "Current Targets for the Audit Objective:" The actual yaml file before being converted is: --------------------------------------------------------------------------- System: H&S: name: "Health & Safety" components: - FlashWheel children: - name: "Training and Culture" type: Programme subtype: None components: - type: ContentBox title: "Training and Culture" args: :content: | None - type: ChildListingComponent title: "Training and Culture Programme Objectives" #Children named nizam should be added here children: - name: "Team" type: Objective subtype: None components: - type: ContentBox title: "Team" args: :content: | None - type: ChildListingComponent title: "Current Targets for the Team Objective:" My question is how do i add children named 'nizam' under "Health & Safety" without jeopardizing other contents (i.e "Training and Culture" and further contents of H&S). I think YAML.dump in not the correct way to do it. Thanks in advance. Nizam -- Posted via http://www.ruby-forum.com/.