Created
March 31, 2011 10:51
-
-
Save benfoxall/896166 to your computer and use it in GitHub Desktop.
Ruby tempfile monkey patch
This file contains hidden or 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
# based on http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions#comment-94 | |
# Monkey patch the temp file so that it maintains the extension | |
class Tempfile | |
def make_tmpname basename, n | |
sprintf('%s%d-%d%s', File::basename(basename, ext), $$, n, File::extname(basename)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually realised that this is possible with:
Tempfile.new ['base', '.ext']