Gavin Kistner wrote: > From: Joel VanderWerf [mailto:vjoel / path.berkeley.edu] >> Joel VanderWerf wrote: >>> Use closures and class scopes: >>> >>> class Foo >>> tmp1 = ExpensiveObject.new >>> tmp2 = ExpensiveObject.new >> Assuming you want to share the tmp1 and tmp2 among all instances of the >> class, which probably you don't want. Sorry. > > No, I very much do - each object is only needed as a 'scratch' pad for performing calculations within the method; before and after the method I don't care about the value. Your idea has interesting merit. I hadn't thought of closing and re-opening the class to 'reset' the closure scope. Or (for that matter) of using define_method to create a method as a closure as both you and David suggested. Watch out for threads, then. If your program can have multiple threads running these calculations, a mutex will keep them from fighting over the expensive objects. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407