From: Ara.T.Howard@... Date: 2004-10-12T23:14:36+09:00 Subject: Re: tempfiles created by tmpfile removed at exit - can I change this easily? On Tue, 12 Oct 2004, Graham Nicholls wrote: > Hi, I think the subject says it all, really. I'm trying to debug a script > (I think I'd call it a script as it is replacing a bash script), and if I > give -d as an argument to the script, then I'd like the tempfile not to be > deleted on exit. Will I have to override the close method in tmpfile, or is > there an easier way, please? i would try not to mess with the interals of Tempfile (although you could easily do it that way) and make a subclass with this behaviour, eg: harp:~ > cat a.rb require 'tempfile' class Tmpfile < Tempfile class << self; attr :litter, true; end def initialize(*a,&b) t = super ObjectSpace::undefine_finalizer self if self.class.litter t end end Tmpfile::litter = ENV['DEBUG'] t = Tmpfile::new __FILE__ puts t.path harp:~ > ruby a.rb /tmp/a.rb11653.0 harp:~ > ls /tmp/a.rb11653.0 ls: /tmp/a.rb11653.0: No such file or directory harp:~ > DEBUG=1 ruby a.rb /tmp/a.rb11655.0 harp:~ > ls /tmp/a.rb11655.0 /tmp/a.rb11655.0 whatever solution you choose - you must basically undefine the finalizer somehow. regards. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | When you do something, you should burn yourself completely, like a good | bonfire, leaving no trace of yourself. --Shunryu Suzuki ===============================================================================