<Ara.T.Howard / noaa.gov> schrieb im Newsbeitrag
news:Pine.LNX.4.60.0410120806520.8667 / harp.ngdc.noaa.gov...
> 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

What do you need that "t" for?  IMHO it's completely superfluous.  The
return value of initialize is always completely ignored.

Also from an aesthetical point of view, I'd expect the flag "litter" to
behave exactly the other way round: if litter is true throw it away; you
keep it if litter is true.

>    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.

Yep.

Regards

    robert