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
Refactor ruby code based on AST
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
flyerhzm
October 18, 2015
Programming
4.4k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Refactor ruby code based on AST
flyerhzm
October 18, 2015
More Decks by flyerhzm
See All by flyerhzm
玩转 AST
flyerhzm
0
440
Find and Replace Code based on AST
flyerhzm
0
570
Rails Performance Tips
flyerhzm
0
1.5k
基于AST的代码优化
flyerhzm
10
930
Write ruby code to change ruby code
flyerhzm
5
3.9k
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
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
56
38k
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
330
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
340
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
310
iOSDC2026登壇資料.pdf
riofujimon
0
150
FreeBSDでZabbixを動かす.pdf
kenkino
0
200
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
670
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
130
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
180
Jetpack Compose メカニズム
skydoves
0
370
アクセシビリティから考える情報設計
high_g_engineer
0
370
自分的「カンファレンスの楽しみ方」
syumai
0
200
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
BBQ
matthewcrist
89
10k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Test your architecture with Archunit
thirion
2
2.4k
Mobile First: as difficult as doing things right
swwweet
225
10k
Designing for Performance
lara
611
70k
Ruling the World: When Life Gets Gamed
codingconduct
0
330
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.1k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.9k
Transcript
Refactor ruby code based on AST Richard Huang @flyerhzm
None
None
Problem
Code Review
None
None
Repeat, Repeat, Repeat
None
None
Any solution?
CodeClimate
None
None
PullReview
How they work?
CodeClimate / PullReview flay flog brakeman rails_best_practices … Open Source
Gems
flay analyzes code for structural similarities
None
flog reports the most tortured code
None
brakeman a static analysis security vulnerability scanner for rails applications
None
rails_best_practices checks the quality of rails code
None
How they work?
flay flog brakeman rails_best_practices … ruby_parser ripper parser ruby parser
=> AST CodeClimate / PullReview
ParseTree • First ruby parser • Not support ruby 1.9
or newer
ruby_parser • Most popular ruby parser • Output is 100%
equivalent to ParseTree
None
None
ActiveRecord::Base belongs_to :user touch :archived_at def archive
ripper • Ruby built-in parser • Support ruby
None
ActiveRecord::Base belongs_to :user def archive touch :archived_at
parser • A new ruby parser • Support rewriting
None
ActiveRecord::Base belongs_to :user def archive touch :archived_at
Good enough?
Auto rewrite!
transpec the rspec syntax converter
None
None
None
None
rubocop static code analyzer based on the community ruby style
guide
None
None
transpec rubocop parser
None
Generic Solution
Synvert converts ruby code to better syntax
DSL • within_file / within_files • with_node / within_node •
if_exist_node / unless_exist_node • append / insert / insert_after / replace_with / remove • ……
None
None
None
Demo Convert rspec to new syntax Convert rails code from
2.3 to 3.0 Convert rails code from 3.2 to 4.0
Side Project not published yet
None
None
Refs CodeClimate - https://codeclimate.com/ PullReview - https://www.pullreview.com/ flay - https://github.com/seattlerb/flay
flog - https://github.com/seattlerb/flog brakeman - https://github.com/presidentbeef/brakeman rails_best_practices - https://github.com/railsbp/ rails_best_practices
Refs parsetree - https://github.com/seattlerb/parsetree ruby_parser - https://github.com/seattlerb/ruby_parser parser - https://github.com/whitequark/parser
rubocop - https://github.com/bbatsov/rubocop transpec - https://github.com/yujinakayama/transpec synvert - https://github.com/xinminlabs/synvert
Thank You