Class: LazyList::Promise

Inherits:
Object show all
Defined in:
lib/lazylist.rb

Overview

A promise that can be evaluated on demand (if forced).

Direct Known Subclasses

MemoPromise

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Promise

Returns a new instance of Promise.



197
198
199
# File 'lib/lazylist.rb', line 197

def initialize(&block)
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Redirect all missing methods to the value of this Promise.



212
213
214
# File 'lib/lazylist.rb', line 212

def method_missing( *args, &block )
  __value__.__send__( *args, &block )
end

Instance Method Details

#__value__Object

Return the value of this Promise.



202
203
204
205
206
207
208
209
# File 'lib/lazylist.rb', line 202

def __value__
  case v = @block.call
  when Promise
    v.__value__
  else
    v
  end
end