Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GParserNode #Tree node for GParser
- def initialize(parent = nil)
- @children = Array.new
- @parent.attach_child(self) unless parent == nil
- end
- def attach_child(child)
- @children.push child
- child.parent = self
- end
- def detach_child_by_index(index)
- @children[index].parent = nil
- @children.delete(index)
- end
- def child_index(child)
- index = 0
- @children.each do |_child|
- return index if _child == child
- index += 1
- end
- end
- attr_accessor :parent, :children, :data
- end
Add Comment
Please, Sign In to add comment