Class: Curry::LazySpice

Inherits:
SpiceArg show all
Defined in:
lib/curry.rb

Overview

Special spice that calls out to a block to get it’s argument. The block is called each time an argument is required. Unlike the other spices, this must be instantiated with the block you want lazily evaluated.

Instance Method Summary collapse

Methods inherited from SpiceArg

#inspect

Constructor Details

#initialize(&promise) ⇒ LazySpice

Returns a new instance of LazySpice.



121
122
123
124
# File 'lib/curry.rb', line 121

def initialize( &promise )
super("LAZYSPICE")
  @promise = promise
end

Instance Method Details

#spice_arg(args) ⇒ Object

called to provide the missing argument



126
127
128
# File 'lib/curry.rb', line 126

def spice_arg( args )  # called to provide the missing argument
  [@promise.call(args)]
end