From: Robert Klemme Date: 2006-06-22T06:03:33+09:00 Subject: Re: The difference between s=s+”a” ans s<< ”a” 2006/6/21, Simon Kr�ger : > I think > s = s + "a" # > or > s += "a" > > should be the norm as long as you do not know that using it will cause > you problems (really only performance problems come to my mind) I use the rule exactly the other way round: usually use << unless that might cause problems. There's a lot of code out there that does += while all it wants to do is appending. += is less efficient and with my C++ background << more looks like "append". > Have a look at this: > -------------------------------------- > def greet_matz greeting > greeting << ' matz!' > puts greeting > end > > def greet_nobu greeting > greeting << ' nobu!' > puts greeting > end > > hello = 'hello' > greet_matz hello > greet_nobu hello > -------------------------------------- > #=> hello matz! > #=> hello matz! nobu! > > you will get what you expect if you use += It depends on what you expect. If methods are expected to get something that they append stuff to then the observed behavior is exactly what you expect and want. :-) For example, if you write a method that should append info about the current instance to something then you should use << because then even an IO object can be passed and the code still works as expected. As generally, you should know your tools and be knowing what you do. :-) Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/