From: Daniel Schierbeck Date: 2005-11-26T01:47:27+09:00 Subject: Re: `finalize' method? Hugh Sasse wrote: > On Sat, 26 Nov 2005, Daniel Schierbeck wrote: > >> Hugh Sasse wrote: >>> On Sat, 26 Nov 2005, Daniel Schierbeck wrote: >>> >>>> I just think it's weird that PHP has destructors and Ruby doesn't ;) >>>> >>>> http://www.php.net/manual/en/language.oop5.decon.php >>> I find this tricky too: the only model I can think of is that where >>> you need destructors, your constructor desstructs, and you get at >>> the object with a block, in the style of open("file"){|f| ...}; if >>> you see what I mean. >> No, not really. I really can't stretch enough that I'm a noob... :) > > The braces, curly brackets, are a block. The CS people will tell > you it is a closure. What it means is: In the current scope (local > variables defined, etc) execute open("file") to open the file for > reading, and then [when inside open it effectively calls yield] you > will have a parameter which we'll call f, and we'll do something > with it in the local scope until the closing brace of the block. On > the closing brace, open will close the file for us. The oft' used > each method behaves in a similar way. Oh, sorry, I misunderstood you: You mean something like this: class Klass def initialize yield self finalize end def finalize # do something end end Sorry, I'm kinda groggy ;) Cheers, Daniel