Created
May 5, 2012 00:11
-
-
Save terrcin/2598654 to your computer and use it in GitHub Desktop.
Making Temfile.make_tmpname give a better quality unique name
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
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