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
rbs-inline 生成してみた
Search
Tomoya Chiba
May 31, 2024
Programming
1
330
rbs-inline 生成してみた
Tomoya Chiba
May 31, 2024
Tweet
Share
More Decks by Tomoya Chiba
See All by Tomoya Chiba
Qiitaアーキテクチャの15年史:モノリスRailsから巨大化するサービスの技術負債をどう解消するか
tomoasleep
1
200
スポンサーブース用の ruby.wasm くじを vibe coding した話
tomoasleep
0
120
東京Ruby会議12ヘルパー楽しかった✌
tomoasleep
0
140
LiveShare で森羅万象を共同編集する(?)
tomoasleep
1
730
GitHub Actions による RSpec の時間を半分以上短縮した話
tomoasleep
2
1.5k
ts-morph と ast-grep でたくさんの TypeScript コードを書き換えた話
tomoasleep
4
4k
render 出来るオブジェクトの作り方
tomoasleep
0
250
Rails アプリを10年以上継続していくためのフロントエンドの底上げ
tomoasleep
3
1k
Rails のブラウザテストを Playwright で動かすようにしたらデバッグが簡単になって捗った
tomoasleep
4
3.1k
Other Decks in Programming
See All in Programming
『実践MLOps』から学ぶ DevOps for ML
nsakki55
2
410
Promise.tryで実現する新しいエラーハンドリング New error handling with Promise try
bicstone
3
460
What’s Fair is FAIR: A Decentralised Future for WordPress Distribution
rmccue
0
180
「10分以内に機能を消せる状態」 の実現のためにやっていること
togishima
1
460
Module Harmony
petamoriken
2
370
Flutterアプリ運用の現場で役立った監視Tips 5選
ostk0069
1
460
Amazon Bedrock Knowledge Bases Hands-on
konny0311
0
150
関数の挙動書き換える
takatofukui
4
600
Tangible Code
chobishiba
3
570
AIを駆使して新しい技術を効率的に理解する方法
nogu66
1
630
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
37
12k
AI駆動開発ライフサイクル(AI-DLC)のホワイトペーパーを解説
swxhariu5
0
1k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Visualization
eitanlees
150
16k
The Invisible Side of Design
smashingmag
302
51k
The Language of Interfaces
destraynor
162
25k
Embracing the Ebb and Flow
colly
88
4.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Agile that works and the tools we love
rasmusluckow
331
21k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
Typedesign – Prime Four
hannesfritz
42
2.9k
Code Review Best Practice
trishagee
72
19k
Six Lessons from altMBA
skipperchong
29
4.1k
Transcript
Tomoya Chiba (@tomoasleep) rbs-inline 生成してみた 1
Tomoya Chiba Twitter: @nemunemu3desu その他: @tomoasleep Qiita 株式会社 シニアエンジニア 4
時間前に LT に申し込みました Ruby に型が欲しい派閥 型はコード中に書きたい派閥 自己紹介 2
rbs-inline が作られている 3
soutaro/rbs-inline: Inline RBS type declaration コメントとして RBS が書ける rbs-inline が作られている
4
soutaro/rbs-inline: Inline RBS type declaration コメントとして RBS が書ける rbs-inline が作られている
5
https://github.com/soutaro/rbs-inline/wiki/Syntax-guide 文法どんな感じか 6
https://github.com/soutaro/rbs-inline/wiki/Syntax-guide 文法どんな感じか 7
https://github.com/soutaro/rbs-inline/wiki/Syntax-guide 文法どんな感じか 8
https://github.com/soutaro/rbs-inline/wiki/Syntax-guide 文法どんな感じか 9
まだ Experimental & プロトタイプなので注意 10
Ruby 中で RBS を書きたかった ( 生成したかった) 民としては最高 表現力も高そう Experimental だけど試したい…
めちゃくちゃ良さそう 11
破壊的変更が入っても、(Prism で) 機械的に書き換えればいいのでは? Experimental でも試したい!! 12
(YARD から) rbs-inline を生成してみた 13
(YARD から) rbs-inline を生成してみた 14
https://github.com/tomoasleep/yard_to_rbs_inline (YARD から) rbs-inline を生成してみた 15
多分 okura さんが解説してくれてるはず マニュアル: https://ruby.github.io/prism/rb/index.html にマニュアルがある bs-inline は Prism で動いている
rbs-inline を読めば Prism も学べる!! Prism をどう学ぶか 16
require 'prism'; Prism.parse("def hoge(a); end") Prism 使い方 (1) - パース処理
17
require 'prism'; Prism.parse("def hoge(a); end").value.statements Prism 使い方 (1) - パース処理
18
Prism::Visitor を使うと AST の走査が出来る class MyVisitor < Prism::Visitor #:: (Prism::CallNode)
-> void def visit_call_node(node) # メソッド呼び出しの Node に出くわしたときの処理 end #:: (Prism::DefNode) -> void def visit_def_node(node) # メソッド呼び出しの Node に出くわしたときの処理 end end Prism 使い方 (2) - Visitor 19
1. Prism でこれらの Node を見る メソッド定義 attr_reader 2. Node 直前のコメントとメソッドのパラメータを抽出
3. YARD を (racc で) 頑張って parse 4. rbs-inline のコメントを直前行に追加 Prism で rbs-inline 出力どんな感じか 20
Parser は2 箇所だけ見れば OK メソッド呼び出し メソッド定義 コメントを手前の行に挿入するだけ ( この辺は文字列操作でやる) コメント自動生成は
( 実は) Parser 入門に向いてる (?) 21
RubyKaigi の発表も楽しみ! 22
rbs collection, rbs-inline と徐々に RBS エコシステムが整いつつある Prism を学べば experimental でも気兼ねなく試せる!!
パーサーを書いて快適な rbs-inline ライフを! RBS を書く環境がどんどん整ってきてる!! 23