From: 7stud -- Date: 2012-12-24T19:19:06+09:00 Subject: Re: POLS and string-handling Paul Magnussen wrote in post #1090050: > Thanks for all the replies. I notice also that I can force changing of > the value (as opposed to the reference) by substituting a trivial > expression for the right-hand side of the assignment > Incorrect. x = "hello" y = x + "" puts x.object_id puts y.object_id --output:-- 2152313980 2152313940 The + operator up there is the name of a String method in ruby: x = "hello" y = x.+("") puts x.object_id puts y.object_id --output:-- 2152313980 2152313940 You are going to have to get used to the fact that: 1) Strings are mutable in ruby. 2) Some methods in the String class mutate their "receiver"(i.e. the object that called the method), and others methods in the String class return a new String object. If you are not sure how a method operates, then check the docs: http://www.ruby-doc.org/core-1.9.3/String.html#method-i-2B Writing something like the following to create a new String object: y = x + "" works, but it is code obfuscation at its worst. Ruby methods usually have names that are descriptive and alert the reader what they do--use them. -- Posted via http://www.ruby-forum.com/.