Ruby: Destructors?

前端 未结 6 1996
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 04:26

I need to occasionaly create images with rmagick in a cache dir.

To then get rid of them fast, without loosing them for the view, I want to delete the image-files wh

6条回答
  •  情书的邮戳
    2020-11-30 04:55

    There's really no such thing as a destructor in Ruby.

    What you could do is simply clear out any files that are no longer open, or use the TempFile class which does this for you.

    Update:

    I previously claimed that PHP, Perl and Python do not have destructors, but this does appear to be false as igorw points out. I have not seen them used very often, though. A properly constructed destructor is essential in any allocation-based language, but in a garbage collected one it ends up being optional.

提交回复
热议问题