Class: ActiveSupport::DescendantsTracker::DescendantsArray
- Includes:
- Enumerable
- Defined in:
- activesupport/lib/active_support/descendants_tracker.rb
Overview
DescendantsArray is an array that contains weak references to classes. Note: DescendantsArray is redundant with WeakSet, however WeakSet when used on Ruby 2.7 or 3.0 can trigger a Ruby crash: bugs.ruby-lang.org/issues/18928
Instance Method Summary collapse
- #<<(klass) ⇒ Object
- #cleanup! ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ DescendantsArray
constructor
A new instance of DescendantsArray.
- #refs_size ⇒ Object
- #reject! ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize ⇒ DescendantsArray
Returns a new instance of DescendantsArray.
120 121 122 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 120 def initialize @refs = [] end |
Instance Method Details
#<<(klass) ⇒ Object
124 125 126 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 124 def <<(klass) @refs << WeakRef.new(klass) end |
#cleanup! ⇒ Object
142 143 144 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 142 def cleanup! @refs.delete_if { |ref| !ref.weakref_alive? } end |
#each ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 128 def each @refs.reject! do |ref| yield ref.__getobj__ false rescue WeakRef::RefError true end self end |
#refs_size ⇒ Object
138 139 140 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 138 def refs_size @refs.size end |
#reject! ⇒ Object
146 147 148 149 150 151 152 |
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 146 def reject! @refs.reject! do |ref| yield ref.__getobj__ rescue WeakRef::RefError true end end |