From: Tech W. on 21 Dec 2009 01:23 Hello, Does ruby have a DESTROY method in its class? like, class Myclass def DESTROY something end end Thanks.
From: Edward Middleton on 21 Dec 2009 01:54 Tech W. wrote: > Does ruby have a DESTROY method in its class? like, > > class Myclass > def DESTROY > something > end > end Take a look at finalizers[1] Edward 1. http://ruby-doc.org/core/classes/ObjectSpace.html
From: Tech W. on 21 Dec 2009 03:08 > 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. Regards, W.
|
Pages: 1 Prev: [ANN] mms2r 2.4.0 Released Next: Nokogiri and xpath for changing value on the web |