Robert Klemme wrote in post #1044064: > On Sat, Feb 4, 2012 at 4:24 AM, Patrick Bayford <pbayford / talktalk.net> > wrote: >>> >>> Did you consider using Marshal? >>> >>>> I'd prefer using a proper database but can't get any of those to behave >>>> properly either!!! >>> >>> What does that mean? > >> I did try using Marshal, however, while the examples show how to use >> dump & load for in memory use, there was not enough information for me >> to get it to write to a file! I don't have enough Ruby experience yet to >> work out how to do this sort of stuff - I'm a Pascal/Delphi man by >> choice, and serializing objects is nearly all down to the coder. > > The docs at > http://www.ruby-doc.org/core-1.9.3/Marshal.html#method-c-dump > mention that you can pass an IO object. > > file_name = "foo.bin" > > # store > File.open(file_name, 'wb') {|io| Marshal.dump(obj, io)} > > # load > obj = File.open(file_name, 'rb') {|io| Marshal.load(io)} > > You should take care that "obj" is an object containing everything you > want to serialize. > >> As to the database comment, I have so far been unable to get mySQL >> working with Ruby 1.9, and don't (yet) know enough SQLite to make it's >> use practical. I have SQL Server too, but that has even poorer support >> documentation, as far as Ruby is concerned. Most of my attempts have >> failed at the connect stage. > > I'd try Marshal first. Much simpler to use and quite fast. > > Kind regards > > robert Thanks for the assist Robert - marshal does indeed work - the key for me was the IO reference, which is not well explained in the reference material! However, I have also discovered PStore, which is more convenient for me, as it will keep several objects in the same file. Example require 'pstore' require 'vwobjects' #m2 = Minions.new() #m2 = File.open('minions.bin', 'rb') {|io| Marshal.load(io)} #m3 = Minions.new() #m3 = File.open('specmins.bin', 'rb') {|io| Marshal.load(io)} store = PStore.new("C:/temp/vwdata") store.transaction do store['minions'] = m2 store['special'] = m3 end #Now reload data store.transaction do puts "Roots: #{store.roots.join(', ')}" m2 = store['minions'] puts"#{m2}" m3 = store['special'] puts"#{m3}" end m2 and m3 being custom objects which enclose an array, facilitating use as a list. -- Posted via http://www.ruby-forum.com/.