From: Shannon Fang Date: 2002-11-28T16:09:20+09:00 Subject: Re: call-by-reference problem again Hi Bill, In my test the Arrays are all pointing to the same object, but the strings are not. I now understand that david has explained what happed in my prog. tks. shannon On Thu, 28 Nov 2002 08:15:18 +0900 William Djaja Tjokroaminata wrote: > Shannon Fang wrote: > > Another problem about reference is that, > > if a is an object, let b=a, then b is a copy of the object or a pointer > > to a? I encountered the following problem > > > a=b=c=Array.new > > d=e=f="" > > > In my program, if I modify a, b and c will be affected, in another word, > > a, b, c point to the same Array. while I modify d, e and f are not > > affected, which means, strings are assigned by value... what will happen > > if I write d=e=f=String.new? > > > Since everything in Ruby is object, I don't understand why String and > > Array are different... > > > Shannon > > Hi Shannon, > > I don't think your statement above is right. In Ruby, if you have > > a = b = c = ... = anything # Array.new, or "", or String.new, or else > > then if you call a "!" method on any of the above variables, then all the > variables are "affected" because in essence, there is only one single > object, which is referred to by so many variables. > > So using your own terminology/concept, in b=a, then b is a copy of the > "pointer" to a, and not a copy of the object pointed to by a. Please see > also http://www.glue.umd.edu/~billtj/ruby.html#objects. > > Regards, > > Bill