Class: Packet::DoubleKeyedHash

Inherits:
Object
  • Object
show all
Defined in:
lib/packet/double_keyed_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDoubleKeyedHash

Returns a new instance of DoubleKeyedHash.



5
6
7
8
# File 'lib/packet/double_keyed_hash.rb', line 5

def initialize
  @keys1 = {}
  @internal_hash = {}
end

Instance Attribute Details

#internal_hashObject

include Enumerable



4
5
6
# File 'lib/packet/double_keyed_hash.rb', line 4

def internal_hash
  @internal_hash
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/packet/double_keyed_hash.rb', line 15

def [] key
  @internal_hash[key] || @internal_hash[@keys1[key]]
end

#[]=(key1, key2, value) ⇒ Object



10
11
12
13
# File 'lib/packet/double_keyed_hash.rb', line 10

def []=(key1,key2,value)
  @keys1[key2] = key1
  @internal_hash[key1] = value
end

#delete(key) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/packet/double_keyed_hash.rb', line 19

def delete(key)
  t_key = @keys1[key]
  if t_key
    @keys1.delete(key)
    @internal_hash.delete(t_key)
  else
    @keys1.delete_if { |key,value| value == key }
    @internal_hash.delete(key)
  end
end

#eachObject



34
35
36
# File 'lib/packet/double_keyed_hash.rb', line 34

def each
  @internal_hash.each { |key,value| yield(key,value)}
end

#lengthObject



30
31
32
# File 'lib/packet/double_keyed_hash.rb', line 30

def length
  @internal_hash.keys.length
end