Class: Steady::SyncronizedHash
- Inherits:
-
Object
- Object
- Steady::SyncronizedHash
- Defined in:
- lib/steady.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key) ⇒ Object
- #apply(changes) ⇒ Object
-
#initialize ⇒ SyncronizedHash
constructor
A new instance of SyncronizedHash.
Constructor Details
#initialize ⇒ SyncronizedHash
Returns a new instance of SyncronizedHash.
8 9 10 11 |
# File 'lib/steady.rb', line 8 def initialize @hash = Hash.new @mutex = Mutex.new end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 |
# File 'lib/steady.rb', line 13 def [](key) @mutex.synchronize { @hash[key] } end |
#[]=(key) ⇒ Object
17 18 19 |
# File 'lib/steady.rb', line 17 def []=(key) @mutex.synchronize { @hash.[]=(key, value) } end |
#apply(changes) ⇒ Object
21 22 23 |
# File 'lib/steady.rb', line 21 def apply(changes) @mutex.synchronize { @hash.merge!(changes) } end |