July 2011
Intermediate to advanced
400 pages
8h 46m
English
Earlier, I mentioned that three dashes are used to mark the start of a new YAML section known as a document. For example, let’s assume you want to save two arrays, arr1 and arr2, to a file, multidoc.yml. Here arr1 is an array containing two nested arrays, and arr2 is an array containing two CD objects:
multi_docs.rb
arr1 = [ ["The Groovesters", "Groovy Tunes", 12 ],
[ "Dolly Parton", "Greatest Hits", 38 ]
]
arr2 = [ CD.new("Gribbit Mcluskey", "Fab Songs", 22),
CD.new("Wayne Snodgrass", "Singalong-a-Snodgrass", 24)
]This is my routine to dump these arrays to YAML and write them to a file (as explained in Chapter 13, the 'w' argument causes the file to be opened for writing):
File.open( 'multidoc.yml', 'w' ){ |f| YAML.dump( ...Read now
Unlock full access