Refactoring with ASTs and Pattern Matching
summary
Demonstrates using Ruby ASTs and pattern matching to find and rewrite code shapes—example: automatic conversion of block patterns like {|v| v.foo } into &:foo via a RuboCop rule built with tree rewriter and pattern matching that extracts receiver and arg. Compares parsers Ripper -> whitequark -> prism, notes prism gives ~5x speedup and RuboCop corrections moving from minutes to seconds on multi-million‑line projects. Shows shape-based counting across large repos (hundreds per pattern), a working refactor rule, and LLMs producing almost‑complete parser code.
AI-written summary · about
chapters (6)
- 0:00Understanding ruby parsers
- 2:00Parser tools and evolution
- 6:34The role of Prism
- 9:45Introduction to pattern matching
- 13:51Applying pattern matching
- 18:45Future of Ruby tooling
related talks
29mAnalyzing an analyzer - A dive into how RuboCop works
01h 12mRuby Best Practice Patterns
35mRuboCop Sent You a Friend Request
41mWriting Lint for Ruby
27mSquashing Security Bugs with Rubocop
43mGrammars, Parsers, and Interpreters, In Ruby
32mruby best practice patterns
45mUsing Ruby to Generate Faster Ruby Code through Partial Evaluation
