Class: ActiveSupport::DescendantsTracker::DescendantsArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
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.



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

def initialize
  @refs = []
end

Instance Method Details

#<<(klass) ⇒ Object



189
190
191
# File 'lib/active_support/descendants_tracker.rb', line 189

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

#cleanup!Object



207
208
209
# File 'lib/active_support/descendants_tracker.rb', line 207

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

#eachObject



193
194
195
196
197
198
199
200
201
# File 'lib/active_support/descendants_tracker.rb', line 193

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

#initialize_copy(orig) ⇒ Object



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

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

#refs_sizeObject



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

def refs_size
  @refs.size
end

#reject!Object



211
212
213
214
215
216
217
# File 'lib/active_support/descendants_tracker.rb', line 211

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