From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-04-08T10:11:44+09:00 Subject: Re: Out of scope - close/finalizers On Tue, 08 Apr 2003 03:06:32 +0200, MikkelFJ wrote: > "MikkelFJ" wrote in message > news:3e921047$0$136$edfadb0f@dtext01.news.tele.dk... > >> > Is it correct there does'nt exist any "out-of-scope" feature? >> >> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/6966 > > and then again: > http://www.eng.dmu.ac.uk/~hgs/ruby/RUBY_SNAPSHOT_RDOC/classes/Finalizer.html > http://www.eng.dmu.ac.uk/~hgs/ruby/RUBY_SNAPSHOT_RDOC/files/lib/ruby/1_8/finalize_rb.html I know you can do like this: def use(resource) resource.open yield ensure resource.close end use(alien_connection) do # do somethine end In order to use it, you must supply a block. Finalizers gets invoked when a object is being garbage collected. This is not necessarily when the object goes out-of-scope. Thus finalizers cannot be used to get notify on "out-of-scope". Am I right here? What I wanna make sure is that "blocks" is the one-and-only way to get notify on "out-of-scope"? Or is there other options, which im not aware of? -- Simon Strandgaard BTW. The reason why im asking is that im writing a text on how to embed ruby into c++. I don't wanna write incorrect stuff :-) http://metaeditor.sf.net/embed/