From: "David A. Black" Date: 2007-08-24T20:38:21+09:00 Subject: Re: something I just found out, am sharing (:newbish) Hi -- On Fri, 24 Aug 2007, Robert Dober wrote: > On 8/24/07, David A. Black wrote: >> Hi -- > >> >> Don't worry -- there's no Academie Anglaise :-) > I am not French, only my wife is;), but it is a funny remark. >> >>> But seriously there is just no need to pay the cost of the >>> construction of another String / Array. >>> Performance difference is already enormous for moderately long strings : >> >> It depends, though; sometimes you might want a copy, sometimes you >> might definitely not. So the + vs. << decision may not be premature, >> and the right decision may not even be the optimizing one :-) > Hmm David when one does > a += b > the copy is thrown away and you have the same semantics (save some > implicit calls to to_s) as for > a << b They're not interchangeable, though: a = "Hello" b = " there" c = a a += b puts a # Hello there puts c # Hello a = "Hello" c = a a << b puts a # Hello there puts c # Hello there David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)