--pgp-sign-Multipart_Thu_May_29_23:23:25_2008-1
Content-Type: text/plain; charset=US-ASCII

At Thu, 29 May 2008 03:03:01 +0900,
David Flanagan wrote:
> Array.nitems has just been removed from 1.9, and as near as I can make
> out from trying to read ruby-dev, Enumerable.count is suggested as a
> replacement.

I didn't think there was a supporter for the method, since even Keiju
himself, the father of the method, said in an interview that he hated
it that he added the method of such a strange feature.

> I wonder if it is possible to make Enumerable.count a true work-alike
> replacement for nitems.
>
> Currently, if count is invoked with no argument and no block, it
> returns an Enumerator.  I'm not why this is useful and wonder if
> instead, it could return the number of non-nil elements just as nitems
> does in 1.8. That would provide a clear porting path for 1.8 code that
> uses nitems: just change nitems to count.
>
> Am I missing something?  Is there a use-case for an Enumerator
> returned by Enumerable#count?

I think not.  Actually it is not official (I know it's not fair but I
intentionally omitted it from rdoc and NEWS) that it returns an
enumerator at the moment, and it would indeed be better if it returned
something more useful and obvious from the name.

My question is if counting the number of non-nil elements can be more
useful and obvious than any other feature, such as:

1) counting the number of all elements (the same as size/length for Array)
2) counting the number of "true" elements (not nil nor false)
3) counting the number of unique elements ([1,2,3,4,2,2,1].count 4)

What do you think?

--
Akinori MUSHA / http://akinori.org/

--pgp-sign-Multipart_Thu_May_29_23:23:25_2008-1
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

iEYEABECAAYFAkg+vF4ACgkQkgvvx5/Z4e47bACfTePz1AqT3YHixMmGexR3biTv
NdEAoJv2Gm/ZvYhUDLuvVHBYN7SIM9Tv

fu
-----END PGP SIGNATURE-----

--pgp-sign-Multipart_Thu_May_29_23:23:25_2008-1--