Eric> Destructors are useful for more than memory allocation. For
    Eric> example, in a large Python program that I wrote some time
    Eric> ago, there is a class that when instantiated creates several
    Eric> temporary named pipes in /tmp. It has various methods that
    Eric> do various things to those files (such as start up some
    Eric> programs that talk through those named pipes), then it has a
    Eric> has a "cleanup" method to clean up those files, but if the
    Eric> program abends (let's say an exception is thrown) I want
    Eric> those files to go away. Otherwise they hang around in /tmp
    Eric> cluttering things up for days.  Not Good.

    Eric> Is there any way I can handle this sort of thing in Ruby?

    Dave> You might want to look at the tempfile.rb standard library
    Dave> package for a way to use finalizers to do just this.

Another approach is to use blocks to manage resources.  If you code
looks like typical "sandwich" code ...

    create_a_resource    # Top bread
    use_the_resource     # Meat
    close_the_resource   # Bottom bread

(This is a pretty typical pattern for code that would use destructors
in C++.)

Now, create a sandwich function using blocks ...

    def sandwich
      create_a_resource   # Top Bread Slice
      yield
    ensure
      close_the_resource  # Bottom Bread Slice
    end

And use it like this ...

    sandwich {
      use_the_resource   # Meat
    }

The resource will automatically be closed. 

-- 
-- Jim Weirich     jweirich / one.net    http://w3.one.net/~jweirich
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct, 
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)