Class: Obfusk::Atom
- Inherits:
-
Object
- Object
- Obfusk::Atom
- Defined in:
- lib/obfusk/atom.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #_, #deref)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value) ⇒ Atom
constructor
new Atom with value.
-
#swap!(&b) ⇒ Object
atomically swaps the value to be
b[oldvalue]
; useswith_value
. -
#with_value(&b) ⇒ Object
calls block with value; uses a mutex to synchronize.
Constructor Details
#initialize(value) ⇒ Atom
new Atom with value
21 22 23 24 |
# File 'lib/obfusk/atom.rb', line 21 def initialize(value) @mutex = Mutex.new @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly) Also known as: _, deref
Returns the value of attribute value.
16 17 18 |
# File 'lib/obfusk/atom.rb', line 16 def value @value end |
Instance Method Details
#swap!(&b) ⇒ Object
atomically swaps the value to be b[oldvalue]
; uses
with_value
33 34 35 |
# File 'lib/obfusk/atom.rb', line 33 def swap!(&b) with_value { |v| @value = b[v] } end |
#with_value(&b) ⇒ Object
calls block with value; uses a mutex to synchronize
27 28 29 |
# File 'lib/obfusk/atom.rb', line 27 def with_value(&b) @mutex.synchronize { b[value] } end |