Is it OK to create a class array and save every object of that class in it? I’m not sure if there is something similar to this natively in Ruby or a design pattern that accomplish this, so this is my solution for accessing every object of a class:
class Foo
@@all = []
def self.all
@@all
end
def initialize
@@all << self
end
end
Foo.all.each do |foo|
# do something
end
You can do it, natively: