Class: Multiton::InstanceMutex

Inherits:
Hash show all
Defined in:
lib/standard/facets/multiton.rb

Overview

Mutex to safely store multiton instances.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#&, #*, #+, #-, #<<, #alias!, #argumentize, autonew, #collate, #collate!, #count, #data, #dearray_singular_values, #dearray_values, #deep_merge, #deep_merge!, #deep_rekey, #deep_rekey!, #delete_unless, #delete_values, #delete_values_at, #diff, #each_with_key, #except, #except!, #extractable_options?, #fetch_nested, #graph!, #insert, #inverse, #join, #keys?, new_with, #object_state, #only_keys?, #recurse, #recurse!, #recursively, #rekey, #rekey!, #replace_each, #revalue, #revalue!, #reverse_merge, #reverse_merge!, #shelljoin, #shellwords, #slice, #slice!, #stringify_keys, #stringify_keys!, #subset, #swap!, #symbolize_keys, #symbolize_keys!, #to_b, #to_mod, #to_ostruct, #to_ostruct_recurse, #to_proc, #to_struct, #traverse, #traverse!, #update_each, #update_keys, #update_values, #weave, zip, #|

Methods included from Random::HashExtensions

#rand_key, #rand_key!, #rand_pair, #rand_pair!, #rand_value, #rand_value!, #shuffle, #shuffle!

Methods included from URI::Hash

#to_uri

Constructor Details

#initializeInstanceMutex

:nodoc:


156
157
158
# File 'lib/standard/facets/multiton.rb', line 156

def initialize
  @global = Mutex.new
end

Class Method Details

.synchronizeObject


164
165
166
# File 'lib/standard/facets/multiton.rb', line 164

def (DummyMutex = Object.new).synchronize
  yield
end

Instance Method Details

#default(arg) ⇒ Object


168
169
170
# File 'lib/standard/facets/multiton.rb', line 168

def default(arg)
  @global.synchronize{ fetch(arg){ store(arg, Mutex.new) } }
end

#initialized(arg) ⇒ Object


160
161
162
# File 'lib/standard/facets/multiton.rb', line 160

def initialized(arg)
  store(arg, DummyMutex)
end