class Piggly::Util::Thunk

Wraps a computation and delays its evaluation until a message is sent to it. Computation can be forced by calling `force!`

Public Class Methods

new(&block) click to toggle source
# File lib/piggly/util/thunk.rb, line 17
def initialize(&block)
  @block = block
end

Public Instance Methods

force!() click to toggle source
# File lib/piggly/util/thunk.rb, line 21
def force!
  unless @block.nil?
    @value = @block.call
    @block = nil
  end

  @value
end
method_missing(name, *args, &block) click to toggle source
# File lib/piggly/util/thunk.rb, line 34
def method_missing(name, *args, &block)
  force!.send(name, *args, &block)
end
thunk?() click to toggle source
# File lib/piggly/util/thunk.rb, line 30
def thunk?
  true
end