D
Daniel Schierbeck
Yeah, it's me again, your friendly neighbourhood power-suggester!
I'm wondering why there isn't a `finalize' method classes can define,
that will be called immediately before instances of that class are
garbage collected? I'm aware of ObjectSpace.define_finalizer, but it
seems un-OO, and it doesn't seem to work when being called from within
the instance methods. It also seems as if the Proc sent to
`define_finalizer' isn't called until *after* the object has been destroyed.
class Klass
def finalize
# finalize something
end
end
A use case (the best I can come up with at the moment):
class Contact
def initialize(filename)
@filename = filename
parse_xml_file(@filename)
end
def finalize
save_as_xml(@filename)
end
end
Cheers,
Daniel
I'm wondering why there isn't a `finalize' method classes can define,
that will be called immediately before instances of that class are
garbage collected? I'm aware of ObjectSpace.define_finalizer, but it
seems un-OO, and it doesn't seem to work when being called from within
the instance methods. It also seems as if the Proc sent to
`define_finalizer' isn't called until *after* the object has been destroyed.
class Klass
def finalize
# finalize something
end
end
A use case (the best I can come up with at the moment):
class Contact
def initialize(filename)
@filename = filename
parse_xml_file(@filename)
end
def finalize
save_as_xml(@filename)
end
end
Cheers,
Daniel