kpeng1
July 3rd, 2006, 12:40 PM
Hi,
The problem I am having is that I have a class that I define two class variables in. After setting one of the class variable myVar2, I append the results to my second variable myVar1. Afterwards, I clear the contents of myVar2 by using the .clear function, but the problem is that when I print the contents of myVar2 I do not see the contents that I have appended with myVar2. Does the << operator only appends a pointer or something and it does not append the entire content? Is there another operator or is this possibly some kind of scoping issue?
My code is show below. The addtoVar2 is always called before addtoVar1 is called.
class myClass
@@myVar1 =[]
@@myVar2 = []
def addtoVar1
@@myVar1 << "x, y" << @@myVar2
@@myVar2.clear
pp @@myVar1 # result is [x, y, []] not [x, y, [a, b, c, d]] why?
end
def addtoVar2
localVar = "a, b, c , d"
@@myVar2 << localVar
end
end
The problem I am having is that I have a class that I define two class variables in. After setting one of the class variable myVar2, I append the results to my second variable myVar1. Afterwards, I clear the contents of myVar2 by using the .clear function, but the problem is that when I print the contents of myVar2 I do not see the contents that I have appended with myVar2. Does the << operator only appends a pointer or something and it does not append the entire content? Is there another operator or is this possibly some kind of scoping issue?
My code is show below. The addtoVar2 is always called before addtoVar1 is called.
class myClass
@@myVar1 =[]
@@myVar2 = []
def addtoVar1
@@myVar1 << "x, y" << @@myVar2
@@myVar2.clear
pp @@myVar1 # result is [x, y, []] not [x, y, [a, b, c, d]] why?
end
def addtoVar2
localVar = "a, b, c , d"
@@myVar2 << localVar
end
end