Skip to content

Instantly share code, notes, and snippets.

@earlonrails
Forked from siong1987/gist:168518
Last active August 29, 2015 14:16
Show Gist options
  • Save earlonrails/3fb7b86712f0b9ba2b86 to your computer and use it in GitHub Desktop.
Save earlonrails/3fb7b86712f0b9ba2b86 to your computer and use it in GitHub Desktop.
Object Store marshal object and save them to files in ruby http://marcuswestinblog.blogspot.com/2008/03/save-ruby-objects-to-disk-for-later.html
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'rubygems'
class ObjectStash
def self.store obj, file_name
marshal_dump = Marshal.dump(obj)
file = File.new(file_name,'w')
file.write marshal_dump
file.close
return obj
end
def self.load file_name
begin
file = File.open(file_name, 'r')
ensure
obj = Marshal.load file.read
file.close
return obj
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment