Class: ActiveSupport::DescendantsTracker::WeakSet

Inherits:
ObjectSpace::WeakMap
  • Object
show all
Defined in:
lib/active_support/descendants_tracker.rb,
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

Constructor Details

#initializeWeakSet

:nodoc:



34
35
36
# File 'lib/active_support/descendants_tracker.rb', line 34

def initialize
  @map = ObjectSpace::WeakMap.new
end

Instance Method Details

#<<(object) ⇒ Object



23
24
25
# File 'lib/active_support/descendants_tracker.rb', line 23

def <<(object)
  self[object] = true
end

#[](object) ⇒ Object Also known as: include?



38
39
40
# File 'lib/active_support/descendants_tracker.rb', line 38

def [](object)
  @map.key?(object.object_id)
end

#[]=(object, _present) ⇒ Object



43
44
45
# File 'lib/active_support/descendants_tracker.rb', line 43

def []=(object, _present)
  @map[object.object_id] = object
end