13
Illustrating both alphazero's and PreciousBodilyFluids answers:
class Foo
@@instance_collector = []
def initialize
@@instance_collector << self
#other stuff
end
def self.all_offspring
@@instance_collector
end
end
a = Foo.new
b = Foo.new
p Foo.all_offspring # => [#<Foo:0x886d67c>, #<Foo:0x886d668>]
p ObjectSpace.each_object(Foo).to_a # => [#<Foo:0x886d668>, #<Foo:0x886d67c>] #order is different