Lazy evaluation in Ruby using lazy.rb
# Foo.long_running_process will not be called here
@result = promise { Foo.long_running_process }
# it will be called here
@result.some_method
This can cause unexpected results in your unit tests though, so be careful - provide a fake implementation if necessary:
# test_helper.rb
module Kernel
def promise(&block)
yield
end
end
Grab the code.
