From: Erik Veenstra Date: 2006-01-25T09:28:12+09:00 Subject: Re: LazyLoad > Well, you've basically rewritten it at this point. :) :o) > But there are some issues it covers that you still have to > address... for example, what happens if the block raises an > exception? Will normal code be able to distiguish exceptions > raised by implicitly evaluated code at random locations from > those which are expected? Catching the exception, storing it and rethrowing it every time it's necessary (see below). Will that do? > Also, is passing parms to the block actually useful to you? No. It's just there. :) > On the other end of things -- one issue that I've still got > to address for myself in lazy.rb is threadsafety. So you've > improved on mine in that respect. That's what I like about technical discussions like this: Everybody can watch, learn, be part of the game and feel good. gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- class LazyLoad instance_methods.each do |method| undef_method(method) unless method =~ /^__/ end def initialize(*parms, &block) @parms = parms @block = block @mutex = Mutex.new @evaluated = false @exception = nil @real_object = nil end def method_missing(method_name, *parms, &block) @mutex.synchronize do begin @real_object = @block.call(*@parms) unless @evaluated rescue Exception => e @exception = e ensure @evaluated = true end end raise @exception if @exception @real_object.send(method_name, *parms, &block) end end ----------------------------------------------------------------