"Yukihiro Matsumoto" <matz / ruby-lang.org> schrieb im Newsbeitrag 
news:1108909479.514053.4734.nullmailer / x31.priv.netlab.jp...
> Hi
>
> In message "Re: destructive! operations"
>    on Sun, 20 Feb 2005 17:22:34 +0900, Navindra Umanee 
> <navindra / cs.mcgill.ca> writes:
>
> |Is it more efficient to use the destructive versions of functions in
> |Ruby?  I know that in Lisp/Scheme destructive counterparts are usually
> |offered for efficiency reasons.
> |
> |Can I assume that string.gsub! is preferable to string.gsub when I
> |know that the side-effect won't be affecting any other code?
>
> Although most (not all) of bang methods are more efficient than their
> counterparts, I discourage the use of them unless the performance is
> really problem.  "Premature optimization is the source of all evil".

Although I agree to the latter statement, I beg to differ on the general 
remark - at least a bit.  I often use this

while ( line = gets )
  line.chomp!
  # work with line
end

because I know it's going to be potentially invoked often - even in scripts 
that are likely to run only on small input files.  But for large files where 
not every line is processed it easily divides the number of instances 
created by a factor of 2.

Kind regards

    robert