Class: ActiveSupport::DescendantsTracker::DescendantsArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
activesupport/lib/active_support/descendants_tracker.rb

Overview

DescendantsArray is an array that contains weak references to classes.

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pluck, #sum, #without

Constructor Details

#initializeDescendantsArray

Returns a new instance of DescendantsArray.



71
72
73
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 71

def initialize
  @refs = []
end

Instance Method Details

#<<(klass) ⇒ Object



79
80
81
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 79

def <<(klass)
  @refs << WeakRef.new(klass)
end

#cleanup!Object



97
98
99
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 97

def cleanup!
  @refs.delete_if { |ref| !ref.weakref_alive? }
end

#eachObject



83
84
85
86
87
88
89
90
91
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 83

def each
  @refs.reject! do |ref|
    yield ref.__getobj__
    false
  rescue WeakRef::RefError
    true
  end
  self
end

#initialize_copy(orig) ⇒ Object



75
76
77
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 75

def initialize_copy(orig)
  @refs = @refs.dup
end

#refs_sizeObject



93
94
95
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 93

def refs_size
  @refs.size
end

#reject!Object



101
102
103
104
105
106
107
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 101

def reject!
  @refs.reject! do |ref|
    yield ref.__getobj__
  rescue WeakRef::RefError
    true
  end
end