From: Ned Konz Date: 2001-09-08T23:53:02+09:00 Subject: [ruby-talk:21001] Re: destructor I'm new to Ruby, so sorry if I'm asking a FAQ: On Friday 07 September 2001 02:38 pm, Dave Thomas wrote: > "Nat Pryce" writes: > > Ruby uses blocks to scope resource allocation and deallocation to scopes > > , just like C++ does with constructors/destructors. Look at the > > File::open method for an example. > > I liked Nat's idea a lot, so how about this: > > module Resource > def Resource.append_features(to) > def to.use(*params, &blk) > obj = new(*params, &blk) Why are you passing the block to new() here? What if it doesn't take one? Also, what happens when there's an exception in new() after resource acquisition? Would it make more sense to put the call to new() after the begin? > begin > return yield(obj) > ensure > obj.close if obj.respond_to?(:close) > end > end > end > end -- Ned Konz currently: Stanwood, WA email: ned@bike-nomad.com homepage: http://bike-nomad.com