From: Eric MSP Veith Date: 2010-09-14T23:43:51+09:00 Subject: Re: method! and method? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 14 September 2010, Gene Angelo wrote: > I am trying to find the meaning of ! and ? appended to method names but > I cannot find what they mean. Can someone explain? First of all, it's a convention, nothing hard-wired. The question mark is probably the easier to explain: It marks a boolean- returning getter method. Where in e.g. Java you'd write isFile(..) or getStuff(..), with Ruby, it's just file? or stuff?. The exclamation mark is harder to grasp. It's meaning is along the lines of "pay attention with this method." Most commonly it is used to demark a destructive twin of another method. E.g., there can be a #sort and a #sort! method. While the first one would return a sorted copy of the original, the second would modify the original itself. There is, however, no sense in marking every destructive method with an exclamation mark. A File#delete method is obvious enough, there's no need for a File#delete!. Think of it as the evil twin of the one without the exclamation mark. :-) HTH. Eric -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkyPiJsACgkQhS0drJ3goJIGbQCcDAio4v10CDh5IeFYWW8/Dd2t NgIAnRjtcep7/AY/s3g3xeYvsRuLkloK =IJsL -----END PGP SIGNATURE-----