Skip to content

Instantly share code, notes, and snippets.

@rpearce
Created April 10, 2017 22:55
Show Gist options
  • Select an option

  • Save rpearce/48db5e41d7dde123fc86b81b3437f064 to your computer and use it in GitHub Desktop.

Select an option

Save rpearce/48db5e41d7dde123fc86b81b3437f064 to your computer and use it in GitHub Desktop.

Revisions

  1. rpearce created this gist Apr 10, 2017.
    10 changes: 10 additions & 0 deletions tmp.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    module Tmp
    def self.build(src:, name:, ext:, binmode: false)
    file = Tempfile.new([name, ext], Rails.root.join('tmp'))
    file.binmode if binmode
    open(src) { |f| file.write(f.read) }
    file.rewind
    file.close
    file
    end
    end