We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

jgn • 6 years ago

One thing to consider is that the Enumerable module does not include #size. You have to use #count (which enumerates over the items). This can be costly so you need to be careful.

dshoemaker • 7 years ago

If you're calling this on an ActiveRecord object then the conclusion is significantly different. length pulls the array into memory and count runs a "count query". size will use the cache if available and the count query if no cache is available.

Prabhakar Undurthi • 9 years ago

Clearly explained. Thanks!!

Akshay Mohite • 9 years ago

Thanks Prabhakar!

Wellington T. • 10 years ago

Thanks!!!

Freddy • 8 years ago

Number 3 method 2. you mean to say there are 3 elements that have a value = 7

Akshay Mohite • 8 years ago

Yes Freddy, that is correct.