Method: Fast.search
- Defined in:
- lib/fast.rb
.search(pattern, node, *args) { ... } ⇒ Object
Search recursively into a node and its children. If the node matches with the pattern it returns the node, otherwise it recursively collect possible children nodes
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/fast.rb', line 259 def search(pattern, node, *args) if (match = match?(pattern, node, *args)) yield node, match if block_given? match != true ? [node, match] : [node] else case node when Array node.flat_map { |child| search(pattern, child, *args) } else node.each_child_node .flat_map { |child| search(pattern, child, *args) } .compact.flatten end end end |