From: Dave Thomas Date: 2001-09-04T07:14:24+09:00 Subject: [ruby-talk:20818] Re: RCR: non-bang equivalent to []= Tobias Reif writes: > AFAIK, there are many more methods that are destructive but don't > declare that in their name: > clear, delete, delete_at, delete_if, fill, pop, push, replace, shift, > unshift, Array#filter. > >... > > Something like "Beware, however, that there are a fair number of > destructive methods that don't have an '!' " in the FAQs it not a > nice discovery for everyone learning Ruby. "The plain version takes > a copy of the receiver, makes its change to it, and returns the > copy. The version with the ! modifies the receiver in place." is a > rule with many non-obvious exceptions. This fact which generates > confusion, and sabotages the "Princple of Least Surprise" in a very > relevant way. Being realistic, though, wouldn't you expect a[1] = 2 to modify the object referenced by 'a'. Similarly for 'delete' and company. There _are_ issues with '!', particularly to do with return values when the receiver isn't changed, but I don't think you should take the '!' as a part of the semantic content of the method being called. It really is no more than a hint that something "dangerous" is going on. Regards Dave