How to count values in an array using 1.8.6?

Hi,

How can I count all keys in an array?

For instance, I want to do this

countme = [1,2,3,4,4,4,4,4,5]

=> [1, 2, 3, 4, 4, 4, 4, 4, 5]

countme.count

=> 9

but in ruby 1.8.6, there is only size which doesn't quite work...

···

--
Posted via http://www.ruby-forum.com/\.

How about

    countme.uniq.size

···

On Sat, Apr 16, 2011 at 12:49:06PM +0900, Richard Sandoval wrote:

Hi,

How can I count all keys in an array?

For instance, I want to do this

>> countme = [1,2,3,4,4,4,4,4,5]
=> [1, 2, 3, 4, 4, 4, 4, 4, 5]
>> countme.count
=> 9

but in ruby 1.8.6, there is only size which doesn't quite work...

--
Posted via http://www.ruby-forum.com/\.

--
______________________________________________________
/ yo-yo, n.: \

                                                     >
Something that is occasionally up but normally down. |
                                                     >

\ (see also Computer). /
------------------------------------------------------
       \ ,__,
        \ (oo)____
           (__) )\
              >>--|| *

Richard Sandoval <skolopen@yahoo.com> writes:

Hi,

How can I count all keys in an array?

For instance, I want to do this

countme = [1,2,3,4,4,4,4,4,5]

=> [1, 2, 3, 4, 4, 4, 4, 4, 5]

countme.count

=> 9

but in ruby 1.8.6, there is only size which doesn't quite work...

I can't quite see what the problem is here.

In 1.9.x, Array#{length,size,count} are synonymous, and 1.8.6 is just
missing the last of those, #count. #length and #size still behave the
exact same and return 9 for your example array.

Why??

···

2011/4/16 Richard Sandoval <skolopen@yahoo.com>:

but in ruby 1.8.6, there is only size which doesn't quite work...

--
Iñaki Baz Castillo
<ibc@aliax.net>