Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Write ruby code to change ruby code
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
flyerhzm
September 19, 2014
Programming
5
3.7k
Write ruby code to change ruby code
flyerhzm
September 19, 2014
Tweet
Share
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
310
Find and Replace Code based on AST
flyerhzm
0
420
Rails Performance Tips
flyerhzm
0
1.3k
Refactor ruby code based on AST
flyerhzm
4
4.1k
基于AST的代码优化
flyerhzm
10
890
Building Asynchronous APIs
flyerhzm
25
9.1k
构建异步API服务
flyerhzm
19
7.4k
JRuby @ OpenFeint
flyerhzm
23
3.4k
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
270
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
CSC307 Lecture 04
javiergs
PRO
0
650
Implementation Patterns
denyspoltorak
0
270
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.1k
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
920
CSC307 Lecture 07
javiergs
PRO
0
520
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
560
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
400
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
590
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
520
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.2k
Featured
See All Featured
Test your architecture with Archunit
thirion
1
2.1k
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
49k
Chasing Engaging Ingredients in Design
codingconduct
0
110
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
270
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
KATA
mclloyd
PRO
34
15k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
100
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
120
Transcript
Write ruby code to change ruby code Richard Huang Xinmin
Labs
About Me Founder at Xinmin Labs Full Stack Developer Open
Source Enthusiast @flyerhzm
Problem
Hey, let’s use rspec new syntax for project A Yes,
sure, I love the rspec new syntax
Hey, let’s use rspec new syntax for project B Hmmm…ok
Hey, let’s use rspec new syntax for project C Oh,
no, I don’t want to repeat it again
Developers love upgrading and refactoring code
Developers hate changing code again and again
Automation
Metric Tools
Metric Tools • cane - fails your build if code
quality thresholds are not met • reek - is a tool that examines Ruby classes, modules and methods and reports any code smells it finds. • rails_best_practices - is a tool to check the quality of rails code. • ……
Tell you what to do, but can’t do for you
IDE
IDE • can rename class / method / variable name
• can extract methods • can ……
IDE • can’t customize
Based on text
Based on text Replace FactoryGirl.create with create ! $ sed
-i '' 's/FactoryGirl.create/create/g' spec/**/*.rb
Based on text Replace FactoryGirl.create with create ! !
Based on text Hard to be accurate ! ! !
!
Based on text Hard to convert complicated cases ! !
! !
Based on AST
What’s AST AST is short for Abstract Syntax Tree
What’s AST
Why AST It is much more accurate to parse ruby
code.
None
None
How to use AST • ripper • ParseTree - https://github.com/seattlerb/parsetree
• ruby_parser - https://github.com/seattlerb/ruby_parser • parser - https://github.com/whitequark/parser
How to use AST
Example transpec - https://github.com/yujinakayama/ transpec
None
Based on AST Accurate, but hard to write and read
Synvert https://github.com/xinminlabs/synvert
Demo http://xinminlabs.github.io/synvert/
None
Synvert • Add useful attributes to AST nodes ! •
Provide DSL to parse and rewrite code
Attributes for AST node
Attributes for AST node
Attributes for AST node
Attributes for AST node Check out more attributes http://xinminlabs.github.io/synvert/rules/
DSL • within_file / within_files • with_node / within_node •
if_exist_node / unless_exist_node • append / insert / insert_after / replace_with / remove • ……
DSL Check out more DSL http://xinminlabs.github.io/synvert/dsl/
None
Playground http://synvert-tools.herokuapp.com/
Snippets https://github.com/xinminlabs/synvert-snippets
Want more? • Fork and send pull request • Open
issues on github • Hire us to refactor your project
Q&A ! Thank you