Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Write ruby code to change ruby code
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
flyerhzm
September 19, 2014
Programming
3.9k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Write ruby code to change ruby code
flyerhzm
September 19, 2014
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
470
Find and Replace Code based on AST
flyerhzm
0
590
Rails Performance Tips
flyerhzm
0
1.5k
Refactor ruby code based on AST
flyerhzm
4
4.4k
基于AST的代码优化
flyerhzm
10
960
Building Asynchronous APIs
flyerhzm
25
9.2k
构建异步API服务
flyerhzm
19
7.5k
JRuby @ OpenFeint
flyerhzm
23
3.6k
Other Decks in Programming
See All in Programming
すこし踏み込む CancellationToken
htkym
2
1.7k
R8 の設定見直しでアプリサイズ削減
andpad
0
220
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
200
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
490
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Domain-Driven Transformation
hschwentner
2
2.3k
ジョジョの世界をXRで再現する
mofurune
0
160
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
150
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
490
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
470
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
GraphQLとの向き合い方2022年版
quramy
50
15k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
520
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
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