From: Tech W. on
Hello,

Does ruby have a DESTROY method in its class? like,

class Myclass
def DESTROY
something
end
end


Thanks.



From: Edward Middleton on
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
> 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.