Class: Collectr::MemoryHash

Inherits:
Object
  • Object
show all
Defined in:
lib/collectr/memory/memory_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @title = name
  @store ||= ThreadSafe::Hash.new
end

Instance Attribute Details

#storeObject (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

#clearObject



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

#destroyObject



27
28
29
# File 'lib/collectr/memory/memory_hash.rb', line 27

def destroy
  @store ||= ThreadSafe::Hash.new
end

#empty?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


43
44
45
# File 'lib/collectr/memory/memory_hash.rb', line 43

def has_key?(key)
  key? key
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/collectr/memory/memory_hash.rb', line 46

def key?(key)
  @store.has_key? key
end

#keysObject



50
51
52
# File 'lib/collectr/memory/memory_hash.rb', line 50

def keys
  @store.keys
end

#sizeObject



39
40
41
# File 'lib/collectr/memory/memory_hash.rb', line 39

def size
  @store.size
end

#to_hashObject



54
55
56
# File 'lib/collectr/memory/memory_hash.rb', line 54

def to_hash
  @store  #.copy
end