From: Robert Klemme Date: 2009-12-21T20:53:24+09:00 Subject: Re: DESTROY in ruby 2009/12/21 Tech W. : >> No, objects in Ruby are simply garbage collected >> when they go out of scope.  It is never neccesary to explicitly >> destroy an object.  If there is any work you need done >> before an object goes away, you had best do it before you let >> it out of scope. > > for example, I openned a database handler in a class, and  new an object > from this class, when the object go out of the scope, I want it close the > database handler automatically. so how to implement this in Ruby? thanks > again. There is keyword "ensure". You can also use blocks for this like File.open does. You can read up on this here: http://blog.rubybestpractices.com/posts/rklemme/002_Writing_Block_Methods.html Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/