Skip to content

Instantly share code, notes, and snippets.

@terrcin
Created May 5, 2012 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrcin/2598654 to your computer and use it in GitHub Desktop.
Save terrcin/2598654 to your computer and use it in GitHub Desktop.
Making Temfile.make_tmpname give a better quality unique name
require 'tempfile'
class Tempfile
# overriding so that the Time component of the tmpname including hours, seconds and usecs, was previously just year + month + day
def make_tmpname(basename, n)
case basename
when Array
prefix, suffix = *basename
else
prefix, suffix = basename, ''
end
t = Time.now.to_i.to_s + Time.now.usec.to_s
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment