Class: RFunk::Lazy
- Inherits:
-
Object
- Object
- RFunk::Lazy
- Defined in:
- lib/rfunk/lazy.rb
Instance Method Summary collapse
- #created? ⇒ Boolean
-
#initialize(lambda) ⇒ Lazy
constructor
A new instance of Lazy.
- #value ⇒ Object
Constructor Details
#initialize(lambda) ⇒ Lazy
Returns a new instance of Lazy.
3 4 5 6 7 |
# File 'lib/rfunk/lazy.rb', line 3 def initialize(lambda) @lambda = lambda @created = false @atomic = Concurrent::Atomic.new end |
Instance Method Details
#created? ⇒ Boolean
14 15 16 |
# File 'lib/rfunk/lazy.rb', line 14 def created? created end |
#value ⇒ Object
9 10 11 12 |
# File 'lib/rfunk/lazy.rb', line 9 def value atomic.update { @value ||= lambda.call.tap { self.created = true } } Option(atomic.value) end |