Class: Nasty::IdentityMap
Instance Method Summary collapse
- #add(item) ⇒ Object
- #evict(item) ⇒ Object
- #has_item_for?(id) ⇒ Boolean
-
#initialize(items = {}) ⇒ IdentityMap
constructor
A new instance of IdentityMap.
- #item_for(id) ⇒ Object
Constructor Details
#initialize(items = {}) ⇒ IdentityMap
Returns a new instance of IdentityMap.
3 4 5 |
# File 'lib/nasty/identity_map.rb', line 3 def initialize(items = {}) @items = items end |
Instance Method Details
#add(item) ⇒ Object
7 8 9 |
# File 'lib/nasty/identity_map.rb', line 7 def add(item) @items[item.id] = item end |
#evict(item) ⇒ Object
19 20 21 |
# File 'lib/nasty/identity_map.rb', line 19 def evict(item) @items.reject! { |key, value| key == item.id } end |
#has_item_for?(id) ⇒ Boolean
11 12 13 |
# File 'lib/nasty/identity_map.rb', line 11 def has_item_for?(id) @items.has_key?(id) end |
#item_for(id) ⇒ Object
15 16 17 |
# File 'lib/nasty/identity_map.rb', line 15 def item_for(id) @items[id] end |