One of the most common and most deadly errors you can make: using length instead of count. You can repeat this multiple times, but you will always find someone who’ll use it the way it shouldn’t be used.

So, first just to make it clear:

#count – collection.count

Counts number of elements using SQL query (SELECT COUNT(*) FROM…)

#count result is not stored internally during object life cycle, which means, that each time we invoke this method, SQL query is performed again

Why would you even care?

Well it might have a huge impact on your apps performance (and resource consumption). In general if you don’t want to care at all and you want to delegate this responsibility to someone else, use #size. If you want to care, then play with it and understand how it works, otherwise you might end up doing something like this:

print "We have #{User.all.length} users!"

And this is the performance difference on my computer (with only 16k users):