From: "Thomas B." Date: 2008-09-22T04:56:45+09:00 Subject: Re: Instance variable acting like class variable? Mike Jo wrote: > The problem is with #add_collected. When it is called its updating > @collected for all instances of Node. @collected is suppose to be an > array of arrays. I'm not sure why it's behaving the way that it is. I'm > still a bit new to ruby. Can anyone give me some insight on why its > behaving the way that it is please. Thanks. 1. The method << is an in-place modifier, you don't have to assign the result, you just write array< a=[] => [] irb(main):011:0> a<<[1,2] => [[1, 2]] irb(main):012:0> a<<[2,5] => [[1, 2], [2, 5]] 3. My guess for your main problem is that you create just one instance of Node and then assign it to all the places where you want to keep your nodes. If you create your nodes like this: nodes=Array::new(num_nodes,Node::new(args)) then this is the case - you create one node and populate the array with pointers to the node. (The correct solution would be nodes=Array::new(num_nodes){Node::new(args)} because this form calls the block for each newly created elements, so you'd have num_nodes separate nodes.) But it's just my guess, you'd have to post your code that creates the nodes to verify it. TPR. -- Posted via http://www.ruby-forum.com/.