Class: AtomicRuby::AtomicBoolean
- Inherits:
-
Object
- Object
- AtomicRuby::AtomicBoolean
show all
- Defined in:
- lib/atomic-ruby/atomic_boolean.rb
Defined Under Namespace
Classes: InvalidBooleanError
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AtomicBoolean.
9
10
11
12
13
14
15
16
17
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 9
def initialize(value)
unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
raise InvalidBooleanError, "expected boolean to be a `TrueClass` or `FalseClass`, got #{value.class}"
end
@boolean = Atom.new(value)
Ractor.make_shareable(self)
end
|
Instance Method Details
#false? ⇒ Boolean
27
28
29
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 27
def false?
value == false
end
|
#make_false ⇒ Object
35
36
37
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 35
def make_false
@boolean.swap { false }
end
|
#make_true ⇒ Object
31
32
33
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 31
def make_true
@boolean.swap { true }
end
|
#toggle ⇒ Object
39
40
41
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 39
def toggle
@boolean.swap { |current_value| !current_value }
end
|
#true? ⇒ Boolean
23
24
25
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 23
def true?
value == true
end
|
#value ⇒ Object
19
20
21
|
# File 'lib/atomic-ruby/atomic_boolean.rb', line 19
def value
@boolean.value
end
|