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
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
450
Find and Replace Code based on AST
flyerhzm
0
580
Rails Performance Tips
flyerhzm
0
1.5k
Refactor ruby code based on AST
flyerhzm
4
4.4k
基于AST的代码优化
flyerhzm
10
940
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
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
980
Java 27新機能 / Java 27 new features
kishida
2
180
JRuby: Past, Present, and Future
headius
0
210
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
420
Agents on Rails - Rails at Scale 2026
irinanazarova
0
290
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
570
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
2.7k
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
220
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.3k
Heart of Swift Concurrency
koher
0
1.1k
Featured
See All Featured
It's Worth the Effort
3n
188
29k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
The Curious Case for Waylosing
cassininazir
1
540
30 Presentation Tips
portentint
PRO
1
410
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Building Applications with DynamoDB
mza
96
7.2k
My Coaching Mixtape
mlcsv
0
330
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
490
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Abbi's Birthday
coloredviolet
4
10k
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