Class | Ohcount::ScratchDir |
In: |
lib/ohcount/scratch_dir.rb
|
Parent: | Object |
path | [R] |
Creates a uniquely named directory in the system tmp directory.
If a block is passed to the constructor, the path to the created directory will be yielded to the block. The directory will then be deleted when this block returns.
Sample usage:
ScratchDir.new do |path| # Do some work in the new directory File.new( path + '/foobaz', 'w' ) do # ... end end # Scratch directory is deleted here
# File lib/ohcount/scratch_dir.rb, line 23 def initialize @path = `mktemp -d /tmp/ohcount_XXXXXX`.strip if block_given? begin return yield(@path) ensure FileUtils.rm_rf(@path) end end end