From: Gavin Sinclair Date: 2005-10-08T10:46:50+09:00 Subject: Re: select! not present but reject! is David A. Black wrote: > On Sat, 8 Oct 2005, Jacob Fugal wrote: > > > On 10/7/05, Mark Hubbart wrote: > > > >> Also, I'm not really advocating any action here. I'm just suggesting > >> that it would be a little weird for "select!" to be the exact opposite > >> of "reject!", since the Ruby definitions wouldn't stand up to the > >> English ones. > > > > I'll concede that, but IMNSHO consistency between the non-bang and > > bang versions seems more important. > > The most important thing, though, is that every method name be > appropriate. If select! ("dangerous select") is the best way to > communicate the "delete unless..." process, then it's right. If not, > then not. It's reasonable to expect that a/b == a!/b! -- but the > existence of a, b, and a! doesn't mean that b! is a good method name > for the inverse of a!. Perhaps not, but in this case, inconsistency would be unforgivable. You should be able to predict how a method will work based on your knowledge of how other, similar methods work. In this case it's absolutely clear. arr = (1..10).to_a arr.map! { |n| n*n } # -> arr == [1,4,9,...,100]; self is returned arr = (1..10).to_a arr.reject! { |n| n % 3 == 0 } # -> arr == [1,2,4,5,7,8]; self is returned arr = (1..10).to_a arr.select! { |n| n % 2 == 0 } # -> arr == [1,3,5,7,9]; self is returned It's a no-brainer. Consistency is paramount! Cheers, Gavin