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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tomoya Chiba
May 31, 2024
Programming
1
350
rbs-inline 生成してみた
Tomoya Chiba
May 31, 2024
Tweet
Share
More Decks by Tomoya Chiba
See All by Tomoya Chiba
Qiitaアーキテクチャの15年史:モノリスRailsから巨大化するサービスの技術負債をどう解消するか
tomoasleep
1
15k
スポンサーブース用の ruby.wasm くじを vibe coding した話
tomoasleep
0
160
東京Ruby会議12ヘルパー楽しかった✌
tomoasleep
0
150
LiveShare で森羅万象を共同編集する(?)
tomoasleep
1
800
GitHub Actions による RSpec の時間を半分以上短縮した話
tomoasleep
2
1.6k
ts-morph と ast-grep でたくさんの TypeScript コードを書き換えた話
tomoasleep
4
4.1k
render 出来るオブジェクトの作り方
tomoasleep
0
270
Rails アプリを10年以上継続していくためのフロントエンドの底上げ
tomoasleep
3
1.1k
Rails のブラウザテストを Playwright で動かすようにしたらデバッグが簡単になって捗った
tomoasleep
4
3.1k
Other Decks in Programming
See All in Programming
SourceGeneratorのススメ
htkym
0
170
CSC307 Lecture 01
javiergs
PRO
0
680
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
330
CSC307 Lecture 06
javiergs
PRO
0
680
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
860
.NET Conf 2025 の興味のあるセッ ションを復習した / dotnet conf 2025 quick recap for backend engineer
tomohisa
0
120
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
580
Python札幌 LT資料
t3tra
7
1.1k
Package Management Learnings from Homebrew
mikemcquaid
0
130
CSC307 Lecture 02
javiergs
PRO
1
770
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
190
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.8k
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
280
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
160
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
370
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
53
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
210
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
230
The Cult of Friendly URLs
andyhume
79
6.8k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
420
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
ラッコキーワード サービス紹介資料
rakko
1
2.2M
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
230
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