From: "David A. Black" Date: 2004-11-13T06:18:55+09:00 Subject: bang methods (was: Re: true? & false?) Hi -- On Sat, 13 Nov 2004, Michael DeHaan wrote: > "In ruby there have many methods that names end with '!' like, collect!, > compact!. I was so used to that '!' means its return the object after > 'affect' and without '!' return the part of the object that was > affected." > > The exclamation actually means the operation is destructive and > forever changes the contents of the calling object. It doesn't have > anything to do with the return codes. It's a very nice convention. Bang (!) methods don't have to be destructive; the ! basically means "dangerous operation -- be careful!" So there can be non-destructive methods with ! (like exit!), and destructive methods without it (like Array#pop). A lot of destructive methods are also bang-methods, but there's no direct correlation. What this means, in Matz's words, is: "Every bang method has non-bang (i.e. safer) counterpart. You can totally forget about bang methods at first." David -- David A. Black dblack@wobblini.net