Class: Farce::Abstract::Lazy Abstract
- Inherits:
-
Object
- Object
- Farce::Abstract::Lazy
- Includes:
- Value, Internal::Copyable, Internal::Inspect, Internal::MarshalSupport::Initialize
- Defined in:
- lib/farce/abstract/lazy.rb
Overview
This class is abstract.
Shared factory, caching, and delegation behavior for lazy values.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(factory = nil) ⇒ Lazy
constructor
A new instance of Lazy.
-
#value ⇒ BasicObject
The first time this method is called, the value will be computed based on the factory provided.
Methods included from Value
Methods included from Internal::Copyable
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ BasicObject (private)
Delegates all method calls to #value.
111 |
# File 'lib/farce/abstract/lazy.rb', line 111 def method_missing(...) = value.public_send(...) |
Instance Method Details
#value ⇒ BasicObject
The first time this method is called, the value will be computed based on the factory provided. Subsequent calls will return the same value.
Concurrent access computes the value once. Shareable variants support calls from any Ractor.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/farce/abstract/lazy.rb', line 34 def value atom = internal_atom value = atom.value if value.nil? value = atom.store_if_absent do value = compute_value value.nil? ? UNDEFINED : value end end value unless UNDEFINED.equal?(value) end |