Is there any difference between array.count and array.size?
I am getting errors sometimes on production environment while using array.count, but the same works fine when I use array.size.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Starting from Ruby 1.8.7,
Array#countis the same ofArray#size.Please note that
Array#countdoesn’t exist in Ruby versions lower than 1.8.7 so if you are running Ruby 1.8.6 in production, it will raise aNoMethodError.Also, make sure you are talking about arrays. In ActiveRecord, for example,
#sizeand#countare slightly different.#sizeunderstands caching like counter cache, while count doesn’t.