From: David Bailey Date: 2006-04-21T03:56:22+09:00 Subject: Re: Write Out Then Read In Hash of Two-element Arrays Farrel Lifson wrote: > Instead of writing your own de/serialization code why not give > Marshal.dump and Marshal.load a try: > >>> dumped_histHash = Marshal.dump(histHash) > => > "\004\010{\ni\000[\ai\017i\006i\006[\ai\020i\ai\a[\ai\021i\010i\010[\ai\022i\ > ti\t[\ai\023i\n" >>> loaded_histHash = Marshal.load(dumped_histHash) > => {0=>[10, 1], 1=>[11, 2], 2=>[12, 3], 3=>[13, 4], 4=>[14, 5]} > > If you need a human readable/editable file consider using YAML: > >>> require 'yaml' > => true >>> puts yaml_histHash = histHash.to_yaml > --- > 0: > - 10 > - 1 > 1: > - 11 > - 2 > 2: > - 12 > - 3 > 3: > - 13 > - 4 > 4: > - 14 > - 5 > => nil >>> loaded_histHash = YAML.load(yaml_histHash) > => {0=>[10, 1], 1=>[11, 2], 2=>[12, 3], 3=>[13, 4], 4=>[14, 5]} > > Farrel Farrel, Good suggestion. Had I not forgotten about marshal and yaml (after having read about it a while back in the pickaxe book), I would have done so initally. At any rate, thank you for the suggestion. And for jogging my memory! David -- Posted via http://www.ruby-forum.com/.