Local variables work, but they have to be defined outside of the scope of the
block:

  x = nil
  p = lambda { x ||= long_method }

  p.call
  p.call

This only calls long_method once, at least on my version of Ruby (1.8.1).

Apparently, without the preceding "x = nil" x goes back to being undefined
when the block closes, so changes to it aren't persistant. If it's defined
outside the scope of the block, though, those changes stay.

Maybe this will change when locals leak out of block scoping. Currently if
you want x to be accessible after the block, you need the preceding x = nil.
But in 2.0 it's changing so that you won't, so maybe you won't need it in
this case either.

- Dan