Array#uniq!

Anyone know why Array#uniq returns an array in every case and
Array#uniq! returns nil if nothing is removed? I’d prefer it to
return
the array in every case but I’m sure my attempt to reduce one line
of
code (no flames on this plz, it’s just fun) are superseded by some
really important concept I don’t know about. :slight_smile:

There are a number of “bang” methods that do this. If I recall
correctly, matz has said they do this so that you CAN’T chain the
methods.

I’m sure there’s a technical reason for this, but I don’t know what
it might be.

I agree that it’s irritating.

···

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Hi,

Anyone know why Array#uniq returns an array in every case and
Array#uniq! returns nil if nothing is removed? […]

There are a number of “bang” methods that do this. If I recall
correctly, matz has said they do this so that you CAN’T chain the
methods.

I thought Matz had said it was because there’d be no equally
efficient way to determine the did-anything-change test, otherwise.

I.e. so it’s there, as a feature, because if you did need it
for efficiency’s sake, there’d be no other way to do it.

?

Regards,

Bill

···

From: “Michael Campbell” michael_s_campbell@yahoo.com

Hi,

···

In message “Re: Array#uniq!” on 03/08/27, “Bill Kelly” billk@cts.com writes:

There are a number of “bang” methods that do this. If I recall
correctly, matz has said they do this so that you CAN’T chain the
methods.

I thought Matz had said it was because there’d be no equally
efficient way to determine the did-anything-change test, otherwise.

You guys are right. I’ve said both.

						matz.