From: Jeremy Bopp Date: 2011-01-27T12:26:26+09:00 Subject: Re: writing on yaml file On 01/26/2011 08:03 PM, Kamarulnizam Rahim wrote: > I also alter some of the codes: > > convert_yaml = YAML::load_file('nizam.yaml') > pp > convert_yaml["System"]["Environmental"]["children"][2]["children"] > convert_yaml["System"]= > [{"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.yaml", "w"){|f| YAML.dump(convert_yaml.to_yaml, f)} In your previous report, you receive this error: C:/Users/Hekmatyer/Documents/NetBeansProjects/Nizam_BARU/lib/Environmental.rb:167:in `[]': can't convert String into Integer (TypeError) Without knowing how line 167 in Environment.rb relates to the code snippets in question it's hard to tell where the problem might be. My guess is that the problem lies in the second line (pp convert_yaml[...) from each snippet. First of all, try commenting that out and see if your problem goes away. If it does, then the problem is likely that you're attempting to use a string to index into an array when you intend to lookup in a hash. In other words, the content of convert_yaml has a different structure than you expect in your code. To further debug this, you should replace your current pp line with the following lines: convert_yaml["System"] convert_yaml["System"]["Environmental"] convert_yaml["System"]["Environmental"]["children"] convert_yaml["System"]["Environmental"]["children"][2]["children"] One of the above lines will reproduce the error, and you can use the line number of the file listed in the error to identify which of the statements is problematic. -Jeremy