Class: CleanHash::MutexHash

Inherits:
Object
  • Object
show all
Defined in:
lib/clean-hash/mutex_hash.rb

Constant Summary collapse

MUTEX =
Mutex.new

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ MutexHash

Returns a new instance of MutexHash.



6
7
8
# File 'lib/clean-hash/mutex_hash.rb', line 6

def initialize name=nil
  @data ||= {}
end

Instance Method Details

#[](name) ⇒ Object



10
11
12
# File 'lib/clean-hash/mutex_hash.rb', line 10

def [] name
  @data[name.to_sym]
end

#[]=(name, value) ⇒ Object



14
15
16
17
18
# File 'lib/clean-hash/mutex_hash.rb', line 14

def []= name, value
  MUTEX.synchronize do
    @data[name.to_sym] = value
  end
end