From: Ian Macdonald Date: 2002-10-24T04:06:00+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) On Tue 22 Oct 2002 at 22:16:50 +0900, William Djaja Tjokroaminata wrote: > Based on previous responses, I think a standard example answer to your > question is something like this: > > a = 'aString' > c = a > a += ' modified using = +' > puts c # -> "aString" > > a = 'aString' > c = a > a << ' modified using <<' > puts c # -> "aString modified using <<" > > Because in Ruby the "=" operator only copies the reference (but not the > object), based on the above example, probably you can tell which is more > natural: for the "a += b" to behave like "a = a + b" or to behave like "a > << b". Thanks, William. Your example is both succinct and very clear. I've only been programming in Ruby for about nine months, so things like this still catch me out from time to time. On more than one occasion, I've been surprised by my variable changing value, simply because another pointer to the same variable was used to change its value. I'd suggest you put the above code snippet in your 'Things That Newcomers to Ruby Should Know' document, if it's not already there. Thanks to Hal, too, for his explanation. Ian -- Ian Macdonald | In Lexington, Kentucky, it's illegal to ian@caliban.org | carry an ice cream cone in your pocket. | | |