Class: ActiveSupport::DescendantsTracker::DescendantsArray
- Inherits:
-
Object
- Object
- ActiveSupport::DescendantsTracker::DescendantsArray
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
Returns a new instance of DescendantsArray.
178
179
180
|
# File 'lib/active_support/descendants_tracker.rb', line 178
def initialize
@refs = []
end
|
Instance Method Details
#<<(klass) ⇒ Object
186
187
188
|
# File 'lib/active_support/descendants_tracker.rb', line 186
def <<(klass)
@refs << WeakRef.new(klass)
end
|
204
205
206
|
# File 'lib/active_support/descendants_tracker.rb', line 204
def cleanup!
@refs.delete_if { |ref| !ref.weakref_alive? }
end
|
190
191
192
193
194
195
196
197
198
|
# File '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 'lib/active_support/descendants_tracker.rb', line 182
def initialize_copy(orig)
@refs = @refs.dup
end
|
#refs_size ⇒ Object
200
201
202
|
# File 'lib/active_support/descendants_tracker.rb', line 200
def refs_size
@refs.size
end
|
208
209
210
211
212
213
214
|
# File 'lib/active_support/descendants_tracker.rb', line 208
def reject!
@refs.reject! do |ref|
yield ref.__getobj__
rescue WeakRef::RefError
true
end
end
|