Class: Lazy::Promise
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- DIVERGES =
diverges
Instance Method Summary collapse
-
#__result__ ⇒ Object
:nodoc:.
-
#__synchronize__ ⇒ Object
:nodoc:.
-
#initialize(&computation) ⇒ Promise
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#method_missing(*args, &block) ⇒ Object
:nodoc:.
-
#respond_to?(message) ⇒ Boolean
:nodoc:.
Constructor Details
#initialize(&computation) ⇒ Promise
: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
#method_missing(*args, &block) ⇒ Object
: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
#__result__ ⇒ Object
: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 |
#__synchronize__ ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/core/facets/lazy.rb', line 72 def __synchronize__ #:nodoc: yield end |
#inspect ⇒ Object
: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 |
#respond_to?(message) ⇒ Boolean
: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 |