Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created March 31, 2011 10:51
Show Gist options
  • Save benfoxall/896166 to your computer and use it in GitHub Desktop.
Save benfoxall/896166 to your computer and use it in GitHub Desktop.
Ruby tempfile monkey patch
# 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
@benfoxall
Copy link
Author

Actually realised that this is possible with: Tempfile.new ['base', '.ext']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment