Module: Farce::Abstract::Flag Abstract
- Includes:
- Value, Internal::Copyable, Internal::ValueSerialization, Internal::Inspect, Internal::MarshalSupport::Flag
- Included in:
- Flag, Local::Flag
- Defined in:
- lib/farce/abstract/flag.rb
Overview
Common boolean interface and serialization for atomic flags.
This is a module rather than a class so Flag can inherit directly from the native flag and avoid delegation overhead.
Instance Method Summary collapse
-
#compare_and_set(expected_value, replacement_value) ⇒ Boolean
Replace the value only if it matches the expected value.
-
#set ⇒ true
Set the flag to true.
-
#store(value) ⇒ Boolean
Set the flag to the given value.
-
#swap(value) ⇒ Boolean
Replace the value and return its previous state.
-
#toggle ⇒ Boolean
Atomically invert the value.
-
#unset ⇒ false
Set the flag to false.
-
#value ⇒ Boolean
The current value.
-
#value=(value) ⇒ BasicObject
Alias for #store.
Methods included from Internal::ValueSerialization
#as_extended_json, #as_json, #to_bson, #to_bson_normalized_value, #to_cbor, #to_json, #to_msgpack
Methods included from Value
Methods included from Internal::Copyable
Instance Method Details
#compare_and_set(expected_value, replacement_value) ⇒ Boolean
Replace the value only if it matches the expected value.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#set ⇒ true
Set the flag to true.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#store(value) ⇒ Boolean
Set the flag to the given value.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#swap(value) ⇒ Boolean
Replace the value and return its previous state.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#toggle ⇒ Boolean
Atomically invert the value.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#unset ⇒ false
Set the flag to false.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#value ⇒ Boolean
Returns the current value.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |
#value=(value) ⇒ BasicObject
Alias for #store
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/farce/abstract/flag.rb', line 47 module Flag include Internal::MarshalSupport::Flag include Internal::Copyable include Value include Internal::ValueSerialization include Internal::Inspect # @api private def inspect_with(inspector) begin current = value rescue StandardError # FrozenError may inspect an allocated flag before it is initialized. return inspector.object_with_address(self) end super do yield if block_given? inspector.breakable inspector.object(current) end end end |