# Does Find also tell you a count of the array size?

**URL:** <https://www.ruby-forum.com/t/does-find-also-tell-you-a-count-of-the-array-size/99163>\
**Category:** Rails\
**Created:** [July 20, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/does-find-also-tell-you-a-count-of-the-array-size/99163 "2006-07-20T18:54:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 20, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/does-find-also-tell-you-a-count-of-the-array-size/99163/1 "2006-07-20T18:54:15Z")

</div>

When I use @persons = Find(:all) (for example) and I get back an array  
of persons, is there an easy way to tell how many rows the find  
returned?

I have been using Persons.count(:all) but you would think Find knows how  
many it returned – is the count/array size stored somewhere in the ret  
array?

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 20, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/does-find-also-tell-you-a-count-of-the-array-size/99163/2 "2006-07-20T19:05:30Z")

</div>

On 7/20/06, Mike K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When I use @persons = Find(:all) (for example) and I get back an array  
> of persons, is there an easy way to tell how many rows the find  
> returned?
> 
> I have been using Persons.count(:all) but you would think Find knows how  
> many it returned – is the count/array size stored somewhere in the ret  
> array?

You can inspect your @persons array with irb. @persons.methods.sort  
for example will show you that you have a method called ‘count’.

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 20, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/does-find-also-tell-you-a-count-of-the-array-size/99163/3 "2006-07-20T19:24:41Z")

</div>

On 7/20/06, Mike K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When I use @persons = Find(:all) (for example) and I get back an array  
> of persons, is there an easy way to tell how many rows the find  
> returned?
> 
> I have been using Persons.count(:all) but you would think Find knows how  
> many it returned – is the count/array size stored somewhere in the ret  
> array?

As you stated the result is stored in an array, based on this you can  
use  
the methods of the array to find out the number of entries:

@people = Person.find :all  
@people\_count = @people.size

References:

[http://www.ruby-doc.org/core/classes/Array.html](http://www.ruby-doc.org/core/classes/Array.html)

> **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails?new=true&experiment=A)**
>
> NEWER EDITION AVAILABLE
> 
> The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> 
> 
> Ruby for Rails helps Rails...

Josh

---

<div class="post-metadata">

**Author:** ![thekog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@thekog](https://www.ruby-forum.com/u/thekog)\
**Post date:** [July 20, 2006, 7:32pm UTC](https://www.ruby-forum.com/t/does-find-also-tell-you-a-count-of-the-array-size/99163/4 "2006-07-20T19:32:02Z")

</div>

thanks, I found count and it is just what I needed 😉
