From: Robert Dober Date: 2006-03-28T18:06:07+09:00 Subject: Re: Why do some methods names which replace the content in place doesn't have the "!" sign? ------=_Part_15351_16964486.1143536749806 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 3/27/06, dblack@wobblini.net wrote: > > Hi -- > > On Mon, 27 Mar 2006, Eric Boucher wrote: > > > Hi, > > > > I was wandering why some ruby methods which replaces the contents of it= s > > variable doesn't follow the rules which say that when the method name > > has a "!" symbol at the end, it means that its contents will be replace > > in place. For example: > > > > Array#replace instead of Array#replace! > > Array#clear instead of Array#clear! > > ... > > > > Is it because the name really mean what it mean? Maybe am I all wrong? > > See Tim and Hal's responses. A further reflection on it: In cases > where it would make no sense for there to be a non-"dangerous" version > of the method, there's no need for the method/method! pair. In the > case of #replace, it's hard to imagine what it would mean to replace > the contents of an array without changing it. And in the case of > clear, a non-destructive version would just be the same as [] :-) > > So yes, it's because the name already implies the whole operation. > > > David > > -- > David A. Black (dblack@wobblini.net) > Ruby Power and Light, LLC (http://www.rubypowerandlight.com) > > "Ruby for Rails" chapters now available > from Manning Early Access Program! http://www.manning.com/books/black > > I am in a revolutionary mood today. So I will put it to extremes: It is a shame that methods can be defined in ruby, that do not end in "!" and still can modify instance variables of the receiver! (pun intended) Honestely I think that would be a nice thing to have and I never even thaught about it, I really appreciate Eric's view! Cheers Robert BTW If there are always exceptions it follows that there must exist at least on= e exception to that rule :)) -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_15351_16964486.1143536749806--