RSS

tumble.lukeredpath

Aug 21
Permalink
Aug 16
Permalink
Aug 02
Permalink

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.