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.



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

def initialize
  @refs = []
end

Instance Method Details

#<<(klass) ⇒ Object



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

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

#cleanup!Object



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

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

#eachObject



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

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

#initialize_copy(orig) ⇒ Object



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

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

#refs_sizeObject



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

def refs_size
  @refs.size
end

#reject!Object



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

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