Serializes an object by simply calling marshal(name,object). When called without the second argument, it deserializes and recalls the object instead.
# save as marshalize.rb in /usr/local/lib/ruby/1.8/ and then require 'marshalize' TMP_DIR = "/Library/Caches/" def marshal(filename,data=nil) Dir.chdir(TMP_DIR) do if data != nil open(filename, "w") { |f| Marshal.dump(data, f) } elsif File.exists?(filename) open(filename) { |f| Marshal.load(f) } end end end def marshal_destroy(filename) Dir.chdir(TMP_DIR) do if File.exists?(filename) File.delete(filename) else return "File does not exists." end end end def marshal_clone(data) filename = srand.to_s << '.tmp' marshal(filename,data) h = marshal(filename) marshal_destroy(filename) return h end