On Sun, 2003-05-18 at 00:47, vinita Papur wrote:
> A quick question.  How can one discern when an object goes out of scope?
> I'd like to do something like this:

Objects don't have scope.  Variables do.  (a subtle distinction)

> create a function, which will get stuff from a database.
> allow a set function to set to an instance hash.
> When the object is going out of scope, save all that stuff to the database.

Use a block to manage resources.  Like this ...

  def my_function
    stuff = get_stuff_from_database
    yield(stuff)
  ensure
    save_stuff_to_database(stuff)
  end

(this is the sandwich pattern)

  my_function { |stuff|
    do_interesting_things_with(stuff)
  }

> is that an END {} block?  I don't see DESTROY {} blocks in Ruby, and I don't
> want objects to live on until the process with it closes in mod_ruby, so
> what do I use under those conditions?

The END { } block is executed at the end of a program, as it is
exiting.  You're right, you probably don't want to use END.  I think the
block example above should be close to what you need.

-- 
-- Jim Weirich     jweirich / one.net    http://jimweirich.umlcoop.net
---------------------------------------------------------------------
"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)