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
320
rbs-inline 生成してみた
Tomoya Chiba
May 31, 2024
Tweet
Share
More Decks by Tomoya Chiba
See All by Tomoya Chiba
スポンサーブース用の ruby.wasm くじを vibe coding した話
tomoasleep
0
94
東京Ruby会議12ヘルパー楽しかった✌
tomoasleep
0
130
LiveShare で森羅万象を共同編集する(?)
tomoasleep
1
690
GitHub Actions による RSpec の時間を半分以上短縮した話
tomoasleep
2
1.4k
ts-morph と ast-grep でたくさんの TypeScript コードを書き換えた話
tomoasleep
4
4k
render 出来るオブジェクトの作り方
tomoasleep
0
240
Rails アプリを10年以上継続していくためのフロントエンドの底上げ
tomoasleep
3
990
Rails のブラウザテストを Playwright で動かすようにしたらデバッグが簡単になって捗った
tomoasleep
3
3.1k
Sorbetやっていき(たい)宣言
tomoasleep
0
450
Other Decks in Programming
See All in Programming
開発生産性を上げるための生成AI活用術
starfish719
1
150
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
160
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
330
Local Peer-to-Peer APIはどのように使われていくのか?
hal_spidernight
2
440
NetworkXとGNNで学ぶグラフデータ分析入門〜複雑な関係性を解き明かすPythonの力〜
mhrtech
3
980
開発者への寄付をアプリ内課金として実装する時の気の使いどころ
ski
0
340
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
130
大規模アプリのDIフレームワーク刷新戦略 ~過去最大規模の並行開発を止めずにアプリ全体に導入するまで~
mot_techtalk
0
370
Breaking Up with Big ViewModels — Without Breaking Your Architecture (droidcon Berlin 2025)
steliosf
PRO
1
300
メモリ不足との戦い〜大量データを扱うアプリでの実践例〜
kwzr
1
780
どの様にAIエージェントと 協業すべきだったのか?
takefumiyoshii
2
590
麻雀点数計算問題生成タスクから学ぶ Single Agentの限界と Agentic Workflowの底力
po3rin
5
2.1k
Featured
See All Featured
Docker and Python
trallard
46
3.6k
It's Worth the Effort
3n
187
28k
Bash Introduction
62gerente
615
210k
A Tale of Four Properties
chriscoyier
160
23k
Music & Morning Musume
bryan
46
6.8k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
How STYLIGHT went responsive
nonsquared
100
5.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Agile that works and the tools we love
rasmusluckow
331
21k
Making the Leap to Tech Lead
cromwellryan
135
9.5k
Designing Experiences People Love
moore
142
24k
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