From: Robert Klemme Date: 2010-03-03T16:10:05+09:00 Subject: Re: A gem for handling temporary file(s)? On 03/03/2010 05:07 AM, Albert Schlef wrote: > Paul Harrington wrote: >> Albert Schlef wrote: >>> I'm writing a program that needs to generate two or three temporary >>> files. >>> >>> (Specifically: my program runs a shell command and I need to pass the >>> shell command a path to a non-existing file which it will dump data to.) > [...] >> ri Tempfile >> >> that'll get you started > > Thanks! I didn't know about Tempfile. > > Though I have a little problem: Tempfile let me *open* a new temporary > file. But I just need to generate a temporary file *name*, which I'll > pass to a shell command. You could use a dirty hack and abuse a private method: irb(main):005:0> Tempfile.open('/tmp') {|tf| p tf, tf.send(:make_tmpname,'a','o')} # "a20100303-4173-kvk0d3-o" => [#, "a20100303-4173-kvk0d3-o"] irb(main):006:0> > I guess I'll immediately close the handle Tempfile.new() returns and > pass its path() to the shell command. What do you want the external program to do with the tempfile? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/