From: Rick DeNatale Date: 2009-02-19T01:54:56+09:00 Subject: Re: Tree structure - how do we link nodes together? --0016362835a60778a60463344897 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Wed, Feb 18, 2009 at 9:29 AM, Aldric Giacomoni <"aldric[removeme]"@ trevoke.net> wrote: > Dylan Evans wrote: > > [Note: parts of this message were removed to make it a legal post.] > > > > I would be inclined to use an array, part of the beauty of dynamic > languages > > is the typeless nature of arrays which does away with a lot of management > > code, in c++ trees i normally write a base node class then branch and > leaf > > nodes which is a lot of work compared to [x, [y, z]] > > Of course if you wanted to create branch nodes for some custom purpose > then > > you could just assign the children to it since they are passed by > reference. > > > > > How would .. passing the children by reference work? Ruby is a uniformly object oriented language, all values are object references. Variables, and parameters are simply named references to objects, not the objects themselves. Individual slots in an array also hold reverences to objects rather than the objects themselves, they just don't have names. So everything is passed by object reference. This is not the same thing as passing by referernce in a language like C, although the differences can be subtle. Here's an oldie but goody of mine which might help understand the relationship between variables, values, and objects. http://talklikeaduck.denhaven2.com/articles/2006/09/13/on-variables-values-and-objects -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale --0016362835a60778a60463344897--