Class: RR::HashWithObjectIdKey

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeHashWithObjectIdKey

Returns a new instance of HashWithObjectIdKey.



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

def initialize
  @keys = {}
  super do |hash, subject_object|
    hash.set_with_object_id(subject_object, {})
  end
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



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

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

#delete(key) ⇒ Object



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

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

#eachObject



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

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

#get_with_object_idObject



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

alias_method :get_with_object_id, :[]

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#keysObject



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

def keys
  @keys.values
end

#set_with_object_idObject



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

alias_method :set_with_object_id, :[]=