At 19:06 03/05/2004 +0900, you wrote: >On Mon, May 03, 2004 at 01:45:45PM +0900, Jean-Hugues ROBERT wrote: > > > Hum... OK. I am wrong. How can I have a block variable that survives > > multiple across multiple invocation ? > > >You don't. A proc is just a simple lambda without mutable internal state. >If you want a proc-like object that can have mutable internal state, >define a class and define its [] method. That's simpler. OK. So: class CacheProc < Proc def [](*args) @val = call(*args) unless defined? @val; @val end end Now: x = CacheProc.new { long_method } p x[] # => result of long_method p x[] # => cached result p x.call() # result of long_method p x[] # => cached result (first one) Thanks ! >Ok, it is possible with lambdas too, but I'm not sure how exactly. So far I am assuming that proc and lambda are the same, you seem unsure about that. Yours, Jean-Hugues