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

#initializeHashWithObjectIdKey

:nodoc:



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

def initialize
  @keys = {}
  super do |hash, subject_object|
    hash.set_with_object_id(subject_object, {})
  end
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
16
# File 'lib/rr/hash_with_object_id_key.rb', line 13

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

#[]=(key, value) ⇒ Object



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

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

#delete(key) ⇒ Object



31
32
33
34
# File 'lib/rr/hash_with_object_id_key.rb', line 31

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

#eachObject



25
26
27
28
29
# File 'lib/rr/hash_with_object_id_key.rb', line 25

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

#get_with_object_idObject



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

alias_method :get_with_object_id, :[]

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rr/hash_with_object_id_key.rb', line 40

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

#keysObject



36
37
38
# File 'lib/rr/hash_with_object_id_key.rb', line 36

def keys
  @keys.values
end

#set_with_object_idObject



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

alias_method :set_with_object_id, :[]=