"anne001" <anne / wjh.harvard.edu> schrieb im Newsbeitrag news:1140522334.803789.181360 / g14g2000cwa.googlegroups.com... >I am using a tree and traversing down a tree to generate opengl code > How could I easily list the opengl code that I am generating, instead > of running it? > > def applytransform > GL.PushMatrix(); > GL.Translate(*@Translation); > GL.Translate(*@jointP); > if @parent != nil > GL.Translate(*@parentjointP); > end > GL.Rotate(*@rotation); > GL.Translate(*@jointP.minus); > end > > def traversetree > GL.Clear(GL::COLOR_BUFFER_BIT); > GL.PushMatrix(); > applytransform > @children.each {|childnode| childnode.traversetree} > drawprimitive > GL.PopMatrix(); > GLUT.SwapBuffers(); > end I'd refactor the traversal out of the code and encapsulate actions on tree nodes in blocks or a specific visitor class. In your case a specific class might be better because you seem to need entry and exit code. Something like: .... def traversetree(visitor) visitor.entry[self] @children.each {|childnode| childnode.traversetree(visitor)} visitor.exit[self] end .... GLVisitor = Struct.new(:entry, :exit) code_runner = GLVisitor.new( lambda do |n| GL.Clear(GL::COLOR_BUFFER_BIT) GL.PushMatrix() n.applytransform end, lambda do |n| n.drawprimitive GL.PopMatrix(); GLUT.SwapBuffers(); end) code_lister = GLVisitor.new( lambda ... HTH Kind regards robert