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

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?

On 7/20/06, Mike K. [email protected] 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’.

On 7/20/06, Mike K. [email protected] 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.manning.com/black/

Josh

thanks, I found count and it is just what I needed :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs