From: Joel VanderWerf Date: 2005-03-19T09:08:27+09:00 Subject: Re: Advice on ASCII representation of objects for testing using string compares? Kirk Haines wrote: > Jonathan Kohl wrote: > > >>I've written a quick test that checks an input file for an application. >>I have a "known good" baseline file, and I want to check the new file >>against this. I attempted to serialize each conf file into objects to >>do string compares. If the strings are not equal, then we need to check >>the file for changes. If they are equal, the input file hasn't changed. > > > This sounds like a job for YAML. > > ----- > require 'yaml' > > a = {1,2,3,4,5,6} > b = {1,2,3,4,5,6} > aa = a.to_yaml > bb = b.to_yaml > puts "match" if aa == bb > ----- I've had problems with both Marshal and YAML when comparing loaded objects. YAML, for instance, does some funny things with floats. (Sorry, don't have specifics at hand.) To be safe, it is best to add an extra cycle: orig = MyObject.new... copy_for_test = Marshal.load(Marshal.dump(orig)) copy_from_disk = Marshal.load(string_or_file) if copy_for_test == copy_from_disk ...