I’ve been trying hard to find a smart way of serializing objects using
the Marshal module, but there is a few issues which I need some help to
fix.
I’m getting statuses from the Twitter stream and saving them all in
separated files (that can contain one or more tweet objects) using
Marshal.dump (the file is opened using
File.new("./src/tweets/#{filename}.adl", “a+b”), where filename is a
string generated from the tweet id), but when I try to unserialize the
tweets all at once I get the following error:
test.rb:8: in 'restore: incompatible marshal file format (can’t be read)
(TypeError)
format version 4.8 required; 128.0 given
[…]
Here’s the code that tries to unserialize the tweets from the file:
result = Dir.glob("./tweets/*.adl")
result.each do |dir|
file = File.new(dir, “r”)
tweets = Array.new
until file.eof?
tweets << Marshal.restore(file)
end
end