Hi all,
In the solution to the Intro data structures: PolyTreeNode project, in the DFS function, the solution makes reference to ‘children’ rather than self.children or @children and I was wondering if there is any explanation for this or further reading available to understand this. Where children is an instance variable declared under the init function, I would have thought that it would have to be referred to using @ or self. syntax. The code is below, for reference. Thanks for the help!
def dfs(target = nil, &prc)
raise "Need a proc or target" if [target, prc].none?
prc ||= Proc.new { |node| node.value == target }
return self if prc.call(self)
children.each do |child|
result = child.dfs(&prc)
return result unless result.nil?
end
nil
end