You can use the ObjectSpace
module to do this, specifically the each_object method.
ObjectSpace.each_object(Project).count
For completeness, here's how you would use that in your class (hat tip to sawa)
class Project
# ...
def self.all
ObjectSpace.each_object(self).to_a
end
def self.count
all.count
end
end