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, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pluck, #sum, #without

Constructor Details

#initializeDescendantsArray

Returns a new instance of DescendantsArray.



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

def initialize
  @refs = []
end

Instance Method Details

#<<(klass) ⇒ Object



80
81
82
83
# File 'lib/active_support/descendants_tracker.rb', line 80

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

#cleanup!Object



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

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

#eachObject



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

def each
  @refs.each do |ref|
    yield ref.__getobj__
  rescue WeakRef::RefError
  end
end

#initialize_copy(orig) ⇒ Object



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

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

#refs_sizeObject



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

def refs_size
  @refs.size
end

#reject!Object



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

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