You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,7 @@ It is built with only standard library dependencies. It additionally ships with
40
40
-[construct_keys](#construct_keys)
41
41
-[Visitor](#visitor)
42
42
-[visit_method](#visit_method)
43
+
-[visit_methods](#visit_methods)
43
44
-[BasicVisitor](#basicvisitor)
44
45
-[MutationVisitor](#mutationvisitor)
45
46
-[WithEnvironment](#withenvironment)
@@ -517,6 +518,26 @@ Did you mean? visit_binary
517
518
from bin/console:8:in `<main>'
518
519
```
519
520
521
+
### visit_methods
522
+
523
+
Similar to `visit_method`, `visit_methods` also checks that methods defined are valid visit methods. This variation however accepts a block and checks that all methods defined within that block are valid visit methods. It's meant to be used like:
524
+
525
+
```ruby
526
+
classArithmeticVisitor < SyntaxTree::Visitor
527
+
visit_methods do
528
+
defvisit_binary(node)
529
+
# ...
530
+
end
531
+
532
+
defvisit_int(node)
533
+
# ...
534
+
end
535
+
end
536
+
end
537
+
```
538
+
539
+
This is only checked when the methods are defined and does not impose any kind of runtime overhead after that. It is very useful for upgrading versions of Syntax Tree in case these methods names change.
540
+
520
541
### BasicVisitor
521
542
522
543
When you're defining your own visitor, by default it will walk down the tree even if you don't define `visit_*` methods. This is to ensure you can define a subset of the necessary methods in order to only interact with the nodes you're interested in. If you'd like to change this default to instead raise an error if you visit a node you haven't explicitly handled, you can instead inherit from `BasicVisitor`.
0 commit comments