module Concurrent::Dereferenceable
def apply_deref_options(value) # :nodoc:
@!visibility private
def apply_deref_options(value) # :nodoc: return nil if value.nil? return value if @do_nothing_on_deref value = value value = @copy_on_deref.call(value) if @copy_on_deref value = value.dup if @dup_on_deref value = value.freeze if @freeze_on_deref value end
def init_mutex
- See: #mutex -
Other tags:
- Note: - This method *must* be called from within the constructor of the including class.
def init_mutex @mutex = Mutex.new end
def mutex
-
(Mutex)
- the synchronization object
def mutex @mutex end
def set_deref_options(opts = {})
(**opts)
-
:copy_on_deref
(String
) -- call the given `Proc` passing the internal value and -
:freeze_on_deref
(String
) -- call `#freeze` before returning the data -
:dup_on_deref
(String
) -- call `#dup` before returning the data
Parameters:
-
opts
(Hash
) -- the options defining dereference behavior.
Other tags:
- Note: - Most classes that include this module will call `#set_deref_options`
def set_deref_options(opts = {}) mutex.lock @dup_on_deref = opts[:dup_on_deref] || opts[:dup] @freeze_on_deref = opts[:freeze_on_deref] || opts[:freeze] @copy_on_deref = opts[:copy_on_deref] || opts[:copy] @do_nothing_on_deref = !(@dup_on_deref || @freeze_on_deref || @copy_on_deref) mutex.unlock nil end
def value
-
(Object)
- the current value of the object
def value mutex.lock result = apply_deref_options(@value) mutex.unlock result end
def value=(val)
-
val
(Object
) -- the new value
def value=(val) mutex.lock result = @value = val mutex.unlock result end