Class: Packet::DoubleKeyedHash
- Inherits:
-
Object
- Object
- Packet::DoubleKeyedHash
- Defined in:
- lib/packet/double_keyed_hash.rb
Instance Attribute Summary collapse
-
#internal_hash ⇒ Object
include Enumerable.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key1, key2, value) ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ DoubleKeyedHash
constructor
A new instance of DoubleKeyedHash.
- #length ⇒ Object
Constructor Details
#initialize ⇒ DoubleKeyedHash
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_hash ⇒ Object
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 |
#each ⇒ Object
34 35 36 |
# File 'lib/packet/double_keyed_hash.rb', line 34 def each @internal_hash.each { |key,value| yield(key,value)} end |
#length ⇒ Object
30 31 32 |
# File 'lib/packet/double_keyed_hash.rb', line 30 def length @internal_hash.keys.length end |