From: Brian Marick Date: 2001-09-09T00:05:30+09:00 Subject: [ruby-talk:21004] Re: destructor At 04:38 PM 9/7/01, you wrote: > >From then on, you can use a block for objects of class Dave. A 'close' >method will get called automatically at the end if it exists > > Dave.use do |d| > # ... > end Cool. Maybe "stop_using" would be a better name than "close": module Resource def Resource.append_features(to) def to.use(*params, &blk) obj = new(*params, &blk) begin return yield(obj) ensure obj.stop_using if obj.respond_to?(:stop_using) end end end end -- Brian Marick, marick@testing.com www.testing.com - Software testing services and resources www.testingcraft.com - Where software testers exchange techniques www.visibleworkings.com - Adequate understanding of system internals