From: "David A. Black" Date: 2005-10-07T08:52:31+09:00 Subject: Re: select! not present but reject! is Hi -- On Fri, 7 Oct 2005, Rob Rypka wrote: > I think the exclamation paradigm overrides the subjective connotation > of select and reject. Regardless of whether or not someone uses it in > their own code, I doubt anyone would be confused by the meaning. I'm still not feeling a "dangerous version of select". It seems such a benign operation :-) > Select and reject are perfect compliments. I have, on several > occasions, tried to use select!, but had to rewrite them with reject! > instead (not a difficult transition). > > As for find_all!, that's just hard to read (and hard to distinguish > from find_all with many fonts), so I would never use it. Then again, > find_all (regardless of its relationship to select and reject) comes It's a synonym for select; they call the same method. That's a pretty hard relationship to disregard :-) > off as an extension of find, and the correlating find! method would be > silly (although fitting with the reality television metaphor). In the middle of writing this I finally got a handle on what bothers me about select! as (I think) it's being discussed: it's backwards. If you select! elements from an array (dangerous/destructive select), those elements should be *removed* from the array. It's like selecting people from the audience to come onto the stage: they are removed from the audience. The audience is not reduced to being just them. At the same time, the return value of select! should be an array of the selected items. The ! part would mean: they've been *permanently selected* (withdrawn from the array). Here's a whole little testbed for this. In this form it would make some sense, though I'm still not happy about the find_all! thing.... class Array def select! yes,no = partition {|e| yield(e) } replace(no) yes end end a = [1,2,3,4] b = a.reject! {|e| e > 2 } p a p b a = [1,2,3,4] b = a.select! {|e| e > 2 } p a p b # Output: [1, 2] [1, 2] [1, 2] [3, 4] David -- David A. Black dblack@wobblini.net