Guest User

Untitled

a guest
Feb 21st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class GParserNode #Tree node for GParser
  2. def initialize(parent = nil)
  3. @children = Array.new
  4. @parent.attach_child(self) unless parent == nil
  5. end
  6.  
  7. def attach_child(child)
  8. @children.push child
  9. child.parent = self
  10. end
  11.  
  12. def detach_child_by_index(index)
  13. @children[index].parent = nil
  14. @children.delete(index)
  15. end
  16.  
  17. def child_index(child)
  18. index = 0
  19. @children.each do |_child|
  20. return index if _child == child
  21. index += 1
  22. end
  23. end
  24.  
  25. attr_accessor :parent, :children, :data
  26. end
Add Comment
Please, Sign In to add comment