Skip to content

Instantly share code, notes, and snippets.

@nerdEd
Created January 19, 2012 22:53
Show Gist options
  • Save nerdEd/1643503 to your computer and use it in GitHub Desktop.
Save nerdEd/1643503 to your computer and use it in GitHub Desktop.
Using ObjectSpace.define_finalizer
class Source
def initialize(source_zip)
@tmp_dir = Dir.mktmpdir
ObjectSpace.define_finalizer(self, self.class.finalize(@tmp_dir))
# Dump contents of zip into tmp dir
end
def self.finalize(tmp_dir)
proc {FileUtils.rm_rf(tmp_dir)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment