From: Marnen Laibow-Koser Date: 2009-11-25T02:19:35+09:00 Subject: Re: Difference between << and += for Strings and Arrays. Bug Pieter Hugo wrote: > Hi Guys > > Thanks for the quick responses and insights. While I understand the > issue now I must confess that it perturbs my 'least surprise' > expectation. According to Matz, POLS is only meant to apply within Ruby, not with respect to other languages. > Why was it decided that '<<' should reference the original > object but '+' should create a new object. That's the way those two operators work in most classes where they're both defined. It's not that surprising. > When one works with a > variable one shouldn't need to worry about what other stuff is being > modified due to a unintentional reference? Actually, keeping this straight is a fundamental part of programming in Ruby. You can always use dup or clone to be safe. > What other operators are > doing this? Ask the code, not us. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.