Class: Lazy::Promise
Overview
:nodoc:
Direct Known Subclasses
Constant Summary
- DIVERGES =
diverges
Instance Method Summary (collapse)
-
- (Object) __result__
:nodoc:.
-
- (Object) __synchronize__
:nodoc:.
-
- (Promise) initialize(&computation)
constructor
:nodoc:.
-
- (Object) inspect
:nodoc:.
-
- (Object) method_missing(*args, &block)
:nodoc:.
-
- (Boolean) respond_to?(message)
:nodoc:.
Constructor Details
- (Promise) initialize(&computation)
:nodoc:
69 70 71 |
# File 'lib/core/facets/lazy.rb', line 69 def initialize( &computation ) #:nodoc: @computation = computation end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(*args, &block)
:nodoc:
125 126 127 |
# File 'lib/core/facets/lazy.rb', line 125 def method_missing( *args, &block ) #:nodoc: __result__.__send__( *args, &block ) end |
Instance Method Details
- (Object) __result__
:nodoc:
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/core/facets/lazy.rb', line 84 def __result__ #:nodoc: __synchronize__ do if @computation raise LazyException.new( @exception ) if @exception computation = @computation @computation = DIVERGES # trap divergence due to over-eager recursion begin @result = demand( computation.call( self ) ) @computation = nil rescue DivergenceError raise rescue Exception => exception # handle exceptions @exception = exception raise LazyException.new( @exception ) end end @result end end |
- (Object) __synchronize__
:nodoc:
72 73 74 |
# File 'lib/core/facets/lazy.rb', line 72 def __synchronize__ #:nodoc: yield end |
- (Object) inspect
:nodoc:
108 109 110 111 112 113 114 115 116 |
# File 'lib/core/facets/lazy.rb', line 108 def inspect #:nodoc: __synchronize__ do if @computation "#<#{ __class__ } computation=#{ @computation.inspect }>" else @result.inspect end end end |
- (Boolean) respond_to?(message)
:nodoc:
118 119 120 121 122 123 |
# File 'lib/core/facets/lazy.rb', line 118 def respond_to?( ) #:nodoc: = .to_sym == :__result__ or == :inspect or __result__.respond_to? end |