Class: WithModel::DescendantsTracker::WeakSet
- Inherits:
-
ObjectSpace::WeakMap
- Object
- ObjectSpace::WeakMap
- WithModel::DescendantsTracker::WeakSet
- Defined in:
- lib/with_model/descendants_tracker.rb,
lib/with_model/descendants_tracker.rb
Overview
On TruffleRuby ObjectSpace::WeakMap
keys are strong references.
So we use object_id
as a key and the actual object as a value.
JRuby for now doesn't have Class#descendant, but when it will, it will likely have the same WeakMap semantic than Truffle so we future proof this as much as possible.
Instance Method Summary collapse
- #<<(object) ⇒ Object
- #[](object) ⇒ Object (also: #include?)
- #[]=(object, _present) ⇒ Object
-
#initialize ⇒ WeakSet
constructor
:nodoc:.
Constructor Details
#initialize ⇒ WeakSet
:nodoc:
23 24 25 |
# File 'lib/with_model/descendants_tracker.rb', line 23 def initialize @map = ObjectSpace::WeakMap.new end |
Instance Method Details
#<<(object) ⇒ Object
12 13 14 |
# File 'lib/with_model/descendants_tracker.rb', line 12 def <<(object) self[object] = true end |
#[](object) ⇒ Object Also known as: include?
27 28 29 |
# File 'lib/with_model/descendants_tracker.rb', line 27 def [](object) @map.key?(object.object_id) end |
#[]=(object, _present) ⇒ Object
32 33 34 |
# File 'lib/with_model/descendants_tracker.rb', line 32 def []=(object, _present) @map[object.object_id] = object end |