From: Austin Ziegler Date: 2004-10-13T01:36:31+09:00 Subject: Re: Ruby Directions (was Re: quality of error messages) On Wed, 13 Oct 2004 01:28:23 +0900, Markus wrote: > The odd thing is, all you are generally getting with them is a bit > of syntactic sugar. Consider the relationship between: > > s = gsub(p,v) > s.gsub!(p,v) > > i = i + k > i += k > > Unless you have lent a friend a reference to s and are using it to send > secret messages, you aren't really depending on the mutability of > strings so much as the modifability of variables. The two aren't equivalent. In fact, the following holds true in Ruby: def gsub(search, replace) self.dup.gsub!(search, replace) end So String#gsub! isn't at all equivalent to i += k, because: s = t = "foo" s.gsub!(/$/, "t") # => "foot" puts t # => "foot" I know that I use String#<< quite a bit, which means that nearly everything that I do depends on the mutability of Strings. (Well, to be more accurate, I use #<< quite a bit, and assume that it will Do The Right Thing, which means that I depend on the mutability of Strings). -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca : as of this email, I have [ 6 ] Gmail invitations