From: Brian Candler Date: 2009-11-25T03:06:52+09:00 Subject: Re: Difference between << and += for Strings and Arrays. Bug? Pieter Hugo wrote: > Why was it decided that '<<' should reference the original > object but '+' should create a new object. Perhaps because of the way C++ uses << with streams: cout << "Hello world!"; > When one works with a > variable one shouldn't need to worry about what other stuff is being > modified due to a unintentional reference? That's what mutable objects are all about. Yes, it certainly can be a source of bugs if you don't take care, but mutating state expected in OOP. If you don't like this, you could always try Erlang instead... > What other operators are > doing this? I noticed that the '.pop' array method was also modifying > the referenced array Lots of operators modify the object. Look at 'ri String' and 'ri Array' and then check out each of the methods. Examples: String#replace, String#upcase!, String#chomp! Sometimes they come in pairs which modify in-place or create a new object for you. For example, str.upcase is really just a shortcut for str.dup.upcase! -- Posted via http://www.ruby-forum.com/.