开发者

Difference between array.count and array.size

开发者 https://www.devze.com 2023-01-29 09:47 出处:网络
Is there any difference between array.count and array.size? I am getting errors sometimes on production environment while using arra开发者_C百科y.count, but the same works fine when I use array.size.

Is there any difference between array.count and array.size?

I am getting errors sometimes on production environment while using arra开发者_C百科y.count, but the same works fine when I use array.size.


Starting from Ruby 1.8.7, Array#count is the same of Array#size.

Please note that Array#count doesn't exist in Ruby versions lower than 1.8.7 so if you are running Ruby 1.8.6 in production, it will raise a NoMethodError.

Also, make sure you are talking about arrays. In ActiveRecord, for example, #size and #count are slightly different. #size understands caching like counter cache, while count doesn't.

0

精彩评论

暂无评论...
验证码 换一张
取 消