-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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