Class: RR::HashWithObjectIdKey

Inherits:
Hash
  • Object
show all
Defined in:
lib/rr/hash_with_object_id_key.rb

Overview

TODO: Refactor to a side-effect-free strategy.

Instance Method Summary collapse

Methods inherited from Hash

#wildcard_match?

Constructor Details

#initializeHashWithObjectIdKey

:nodoc:



4
5
6
7
# File 'lib/rr/hash_with_object_id_key.rb', line 4

def initialize
  @keys = {}
  super
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
14
# File 'lib/rr/hash_with_object_id_key.rb', line 11

def [](key)
  @keys[key.__id__] = key
  super(key.__id__)
end

#[]=(key, value) ⇒ Object



22
23
24
25
# File 'lib/rr/hash_with_object_id_key.rb', line 22

def []=(key, value)
  @keys[key.__id__] = key
  super(key.__id__, value)
end

#delete(key) ⇒ Object



33
34
35
36
# File 'lib/rr/hash_with_object_id_key.rb', line 33

def delete(key)
  @keys.delete(key.__id__)
  super(key.__id__)
end

#eachObject



27
28
29
30
31
# File 'lib/rr/hash_with_object_id_key.rb', line 27

def each
  super do |object_id, value|
    yield @keys[object_id], value
  end
end

#get_with_object_idObject



9
# File 'lib/rr/hash_with_object_id_key.rb', line 9

alias_method :get_with_object_id, :[]

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rr/hash_with_object_id_key.rb', line 16

def has_key?(key)
  super(key.__id__)
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rr/hash_with_object_id_key.rb', line 42

def include?(key)
  super(key.__id__)
end

#keysObject



38
39
40
# File 'lib/rr/hash_with_object_id_key.rb', line 38

def keys
  @keys.values
end

#set_with_object_idObject



20
# File 'lib/rr/hash_with_object_id_key.rb', line 20

alias_method :set_with_object_id, :[]=