Class: Variable::IVar
Overview
Shared variable that can be written at most once
ignore :reek:InstanceVariableAssumption
Defined Under Namespace
Classes: Error
Constant Summary
Constants inherited from Variable
Instance Method Summary collapse
-
#populate_with ⇒ Object
Populate and return value, use block to compute value if empty.
-
#put(value) ⇒ self
Put value, raises if already full.
Methods inherited from Variable
#initialize, #read, #take, #take_timeout, #try_put, #with
Constructor Details
This class inherits a constructor from Variable
Instance Method Details
#populate_with ⇒ Object
Populate and return value, use block to compute value if empty
The block is guaranteed to be executed at max once.
Subsequent reads are guaranteed to return the block value.
250 251 252 253 254 255 256 257 258 |
# File 'lib/variable.rb', line 250 def populate_with return @value if full? synchronize do perform_put(yield) if empty? end @value end |
#put(value) ⇒ self
Put value, raises if already full
234 235 236 237 238 239 240 241 |
# File 'lib/variable.rb', line 234 def put(value) synchronize do fail Error, 'is immutable' if full? perform_put(value) end self end |