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)

Constructor Details

- (HashWithObjectIdKey) initialize

:nodoc:



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

def initialize
  @keys = {}
  super
end

Instance Method Details

- (Object) [](key)



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

- (Object) []=(key, value)



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

- (Object) delete(key)



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

- (Object) each



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

- (Object) get_with_object_id



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

alias_method :get_with_object_id, :[]

- (Boolean) has_key?(key)



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

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

- (Boolean) include?(key)



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

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

- (Object) keys



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

def keys
  @keys.values
end

- (Object) set_with_object_id



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

alias_method :set_with_object_id, :[]=