I'm trying to keep track of all instantiated subclass objects in an array in the super, so that I can call a method from super to iterate over them. I think I'm almost there but I can't figure out what I'm missing. Currently when I call super.my_array it's only returning an empty array, so there has to be something wrong with my initialize method. This is the abstracted version have I have so far:
class Klass
attr_reader :my_array
@@my_array = []
def initialize
@@my_array << self if super.class == Klass
end
def self.iterate_over_sub
@@my_array.each { |x| x.sub_method }
end
def sub_method
puts "#{self.class} is being called by super"
end
end