Class: Perpetuity::IdentityMap
- Inherits:
-
Object
- Object
- Perpetuity::IdentityMap
- Defined in:
- lib/perpetuity/identity_map.rb
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
- #<<(object) ⇒ Object
- #[](klass, id) ⇒ Object
-
#initialize ⇒ IdentityMap
constructor
A new instance of IdentityMap.
Constructor Details
#initialize ⇒ IdentityMap
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
#map ⇒ Object (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 16 17 |
# File 'lib/perpetuity/identity_map.rb', line 13 def << object klass = object.class id = object.instance_variable_get(:@id) map[klass][id.to_s] = object.dup end |
#[](klass, id) ⇒ Object
9 10 11 |
# File 'lib/perpetuity/identity_map.rb', line 9 def [] klass, id map[klass][id.to_s] end |