Class: Perpetuity::IdentityMap

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/identity_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.



5
6
7
# File 'lib/perpetuity/identity_map.rb', line 5

def initialize
  @map = Hash.new { |hash, key| hash[key] = {} }
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



3
4
5
# File 'lib/perpetuity/identity_map.rb', line 3

def map
  @map
end

Instance Method Details

#<<(object) ⇒ Object



13
14
15
# File 'lib/perpetuity/identity_map.rb', line 13

def << object
  map[object.class][object.id] = object
end

#[](klass, id) ⇒ Object



9
10
11
# File 'lib/perpetuity/identity_map.rb', line 9

def [] klass, id
  map[klass][id]
end