From: Kevin Ballard Date: 2005-10-18T22:41:58+09:00 Subject: Re: A couple of questions/statements from a Ruby neohacker Robert Klemme wrote: > Christophe Grandsire wrote: > > I believe the convention that bang methods always have a non-bang > > alternative, and that destructive methods without a non-destructive > > alternative don't have one, is pretty well followed. > > Anomalies I can think of off the top of my head: > > - Hash#update and Hash#merge: those do the same but #merge creates a new > instance while #update doesn't. You do know that there exists a Hash#merge! as well, which Hash#update is an alias of, yes? I don't find this an anomaly. The name #update to me implies that the existing hash will be updated with the new keys, while #merge implies the two hashes will be merged to form a new one. And that's exactly what happens. > - Even for Array#delete it would make sense to have two variants - one > that returns a copy with selected elements removed and another one that > modifies in place. Except Array#delete returns the deleted element, so if you turned it into Array#delete! and added a new non-destructive Array#delete, then you'd have to change the return value, and the method would now be a completely different method. After all, an Array#delete that's non-destructive and returns the deleted element would be completely useless :P Granted, it would be nice to have a non-destructive method that returns the array minus the passed element[s]. Feel free to correct me if such a method already exists, but I couldn't find one the other day when I wanted it.