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:



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

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

Instance Method Details

#<<(object) ⇒ Object



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

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

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



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

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

#[]=(object, _present) ⇒ Object



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

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