Class: ActiveSupport::DescendantsTracker::WeakSet
- Inherits:
-
ObjectSpace::WeakMap
- Object
- ObjectSpace::WeakMap
- ActiveSupport::DescendantsTracker::WeakSet
- Defined in:
- activesupport/lib/active_support/descendants_tracker.rb,
activesupport/lib/active_support/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
A new instance of WeakSet.
Constructor Details
#initialize ⇒ WeakSet
Returns a new instance of WeakSet.
33 34 35 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 33 def initialize @map = ObjectSpace::WeakMap.new end |
Instance Method Details
#<<(object) ⇒ Object
22 23 24 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 22 def <<(object) self[object] = true end |
#[](object) ⇒ Object Also known as: include?
37 38 39 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 37 def [](object) @map.key?(object.object_id) end |
#[]=(object, _present) ⇒ Object
42 43 44 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 42 def []=(object, _present) @map[object.object_id] = object end |