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, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum

Constructor Details

#initializeDescendantsArray

Returns a new instance of DescendantsArray.


178
179
180
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 178

def initialize
  @refs = []
end

Instance Method Details

#<<(klass) ⇒ Object


186
187
188
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 186

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

#cleanup!Object


204
205
206
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 204

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

#eachObject


190
191
192
193
194
195
196
197
198
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 190

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

#initialize_copy(orig) ⇒ Object


182
183
184
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 182

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

#refs_sizeObject


200
201
202
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 200

def refs_size
  @refs.size
end

#reject!Object


208
209
210
211
212
213
214
# File 'activesupport/lib/active_support/descendants_tracker.rb', line 208

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