From: Albert Wagner Date: 2002-07-07T12:31:47+09:00 Subject: Re: passing to objects at the bottom On Saturday 06 July 2002 07:08 pm, Tom Sawyer wrote: > well, i have an object called a Miter, and it has an array of Table. > each Table has an array of Section. each Section has an array of Cell. > and each Cell has an array of Element. > > so when i create a Miter, i pass in a @layout and a @prefix. the @layout > gets parsed thus creating all those subobjects, but in so doing, each > Element has a @name which needs to be prefixed with @prefix. > I am probably totally off base, but maybe it will trigger another way of thinking about your problem. It appears that what you are trying to build is a tree structure, which usually lends itself to recursion. But your original post mentioned globals meaning that it's really a namespace problem. By controlling the descent in Miter you keep all elements in the same namespace as @prefix. class Miter def initialize(layout, prefix) @layout = layout @prefix = prefix @tables = Array.new buildTree end def buildTree parser(@layout).eachTable do |table| aTable = Array.new @tables.push(aTable) table.eachSection do |section| aSection = Array.new aTable.push(aSection) section.eachCell do |cell| aCell = Array.new aSection.push(aCell) cell.eachElement do |element| aCell.push(element) element.name = @prefix end end end end end def parser(aLayout) #answer a tree end end