Method: SGF::Node#initialize

Defined in:
lib/sgf/node.rb

#initialize(children: [], parent: nil, **opts) ⇒ Node

Creates a new node. You can pass in a hash. There are two special keys, parent and children.

  • parent: parent_node (nil by default)

  • children: [list, of, children] (empty array if nothing is passed)

Anything else passed to the hash will become an SGF identity/property pair on the node.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sgf/node.rb', line 13

def initialize children: [], parent: nil, **opts
  # opts = { children: [], parent: nil }
  # opts.merge! args
  @depth = 0
  @children = []
  @properties = {}
  @parent = nil
  set_parent parent #opts.delete :parent
  add_children children #opts.delete :children
  add_properties opts
end