Class: Collectr::MemoryHash
- Inherits:
-
Object
- Object
- Collectr::MemoryHash
- Defined in:
- lib/collectr/memory/memory_hash.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #destroy ⇒ Object
- #empty? ⇒ Boolean
- #fetch(key, &block) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(name, options = {}) ⇒ MemoryHash
constructor
A new instance of MemoryHash.
- #key?(key) ⇒ Boolean
- #keys ⇒ Object
- #size ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ MemoryHash
Returns a new instance of MemoryHash.
7 8 9 10 |
# File 'lib/collectr/memory/memory_hash.rb', line 7 def initialize(name, ={}) @title = name @store ||= ThreadSafe::Hash.new end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/collectr/memory/memory_hash.rb', line 5 def store @store end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/collectr/memory/memory_hash.rb', line 12 def [](key) @store[key] end |
#[]=(key, val) ⇒ Object
16 17 18 |
# File 'lib/collectr/memory/memory_hash.rb', line 16 def []=(key, val) @store[key] = val end |
#clear ⇒ Object
58 59 60 |
# File 'lib/collectr/memory/memory_hash.rb', line 58 def clear @store.clear end |
#delete(key) ⇒ Object
31 32 33 |
# File 'lib/collectr/memory/memory_hash.rb', line 31 def delete(key) @store.delete key end |
#destroy ⇒ Object
27 28 29 |
# File 'lib/collectr/memory/memory_hash.rb', line 27 def destroy @store ||= ThreadSafe::Hash.new end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/collectr/memory/memory_hash.rb', line 35 def empty? @store.empty? end |
#fetch(key, &block) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/collectr/memory/memory_hash.rb', line 20 def fetch(key, &block) @store.fetch(key, &block) # @store.fetch(key) do # block_given? ? yield(key) : nil # end end |
#has_key?(key) ⇒ Boolean
43 44 45 |
# File 'lib/collectr/memory/memory_hash.rb', line 43 def has_key?(key) key? key end |
#key?(key) ⇒ Boolean
46 47 48 |
# File 'lib/collectr/memory/memory_hash.rb', line 46 def key?(key) @store.has_key? key end |
#keys ⇒ Object
50 51 52 |
# File 'lib/collectr/memory/memory_hash.rb', line 50 def keys @store.keys end |
#size ⇒ Object
39 40 41 |
# File 'lib/collectr/memory/memory_hash.rb', line 39 def size @store.size end |
#to_hash ⇒ Object
54 55 56 |
# File 'lib/collectr/memory/memory_hash.rb', line 54 def to_hash @store #.copy end |