From: Robert Klemme Date: 2009-02-19T06:54:51+09:00 Subject: Re: Tree structure - how do we link nodes together? On 18.02.2009 15:18, Aldric Giacomoni wrote: > Robert Klemme wrote: >> 2009/2/18 Aldric Giacomoni <"aldric[removeme]"@trevoke.net>: >> >>> I know I could just use rubytree, which looks quite nice, but I'd like >>> to see what you guys would do about creating a tree and linking the >>> nodes together. >>> In C++ we'd just make pointers, so how would we do the equivalent in Ruby? >>> >> We use object references - as always when referring other objects. >> Ruby does not have the multitude of options that C++ has. > Alright, Robert - I don't know how that works in Ruby! Would you provide > me with a simple example, explain it, or point me to something that > explains it, please? I wasn't aware that you were after _such_ basic information. Actually, since you mentioned using rubytree I assumed that you are familiar with the language. The simplest and most basic form of a relation between two objects is probably: class Foo def set(x) @the_other = x end end f = Foo.new x = Foo.new f.set(x) Now f references x. I suggest you get your hands on David's new book once it is out and in the meantime consult those various introductory documents (can be found via http://www.ruby-doc.org/). Cheers robert