From: "James F.Hranicky" Date: 2003-02-13T23:28:34+09:00 Subject: Re: Why does Array#compact! return the array, but uniq! return a count? On Thu, 13 Feb 2003 22:51:06 +0900 "Mike Campbell" wrote: > I'm with Tom on this one. The whole thing seems like a Pythonista form of "Do > it this way. There is no other way." social engineering. I guess the main question is How often do I care whether or not the receiver was modified? For @fields.collect{ |field| field.group }.compact!.uniq! we don't really care whether compact!() or uniq!() do nothing, we're interested in ensuring the final state of the array generated by collect(). It just doesn't seem that often that we'll need to do this: unless (arr.uniq!) { # Darn! Do something because arr already contained unique # elements } For times when we care about the uniqueness or compactness of the elements of the array, we could have uniq? compact? if you plan on doing more than just calling uniq! or compact! anyway. Other ideas: - change ! methods to always return the receiver, create new methods that have the current ! functionality: expect_uniq! expect_compact! - leave the old methods alone, add new ones that always return the receiver ensure_uniq! ensure_compact! Personally, I'd prefer if by default most methods did modify and return the receiver, using another symbol to denote creation of a new object arr.sort<.each { arr.uniq<.each { or arr.sort*.each { arr.uniq*.each { or arr.sort+.each { arr.uniq+.each { but that's a pretty huge change :-> ---------------------------------------------------------------------- | Jim Hranicky, Senior SysAdmin UF/CISE Department | | E314D CSE Building Phone (352) 392-1499 | | jfh@cise.ufl.edu http://www.cise.ufl.edu/~jfh | ----------------------------------------------------------------------