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
YARD with RBS Syntax
Search
Takumi Shotoku
July 06, 2023
Technology
1
490
YARD with RBS Syntax
【オフライン開催】Omotesando.rb #87
https://omotesandorb.connpass.com/event/287544/
Takumi Shotoku
July 06, 2023
Tweet
Share
More Decks by Takumi Shotoku
See All by Takumi Shotoku
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
190
"型"のあるRailsアプリケーション開発 / Typed Rails application development
sinsoku
9
2.5k
Let's get started with Ruby && Rails Tips
sinsoku
0
370
LTの敷居を下げる / Lower the threshold for LT
sinsoku
1
330
CircleCIの高速化🚀 / CircleCI faster
sinsoku
3
1.2k
Railsアプリと型検査 / Rails app and type checking
sinsoku
5
1.4k
💎のつくりかた 2023 / How to make gems 2023
sinsoku
2
340
Make tests run faster
sinsoku
2
650
Get started with OSS contributions
sinsoku
2
1.2k
Other Decks in Technology
See All in Technology
20241220_S3 tablesの使い方を検証してみた
handy
3
240
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
420
MLOps の現場から
asei
6
630
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
160
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
Password-less Journey - パスキーへの移行を見据えたユーザーの準備 @ AXIES 2024
ritou
3
1.4k
AIのコンプラは何故しんどい?
shujisado
1
190
.NET 9 のパフォーマンス改善
nenonaninu
0
530
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
110
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Your Own Lightsaber
phodgson
103
6.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
Building an army of robots
kneath
302
44k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Visualization
eitanlees
146
15k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Mobile First: as difficult as doing things right
swwweet
222
9k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Transcript
YARD with RBS Syntax Omotesando.rb #87 2023/07/06 1
ࣗݾհ • ໊લ: ਖ਼ಙ (aka: ਆ) • ձࣾ: - •
GitHub: @sinsoku (ը૾ӈ্) • Twitter: @sinsoku_listy (ը૾ӈԼ) • ͖ͳݴޠ: Rust • Railsྺ: 8͘Β͍ 2
ઌ݄͔ΒRBSΛ͍࢝Ί·ͨ͠ 3
͖͔͚ͬ: MedPeerͷϒϩά 4
ࣾͷ૯ҙ: ܕͷԸܙΛड͚͍ͨ ʢͨͩ͠ܕࣗͰॻ͖ͨ͘ͳ͍ʣ 5
RBSಋೖͷํ • *.rbs ࣗಈੜ͢Δ • rbs collection • rbs prototype
• sord1 ʢYARD -> rbsʣ • gemͷෆͯ͠Δܕఆٛ࠷খݶ͚ͩ༻ҙ 1 https://github.com/AaronC81/sord 6
ಋೖͷৄࡉׂѪʢͨͿΜϒϩάॻ͘ʣ 7
͔͜͜Βຊ 8
Α͋͘ΔYARDͷྫ class User # @param item [Item] ΞΠςϜ # @param
amount [Integer] ྔ # @param coupon [Coupon] Ϋʔϙϯ # @return [Boolean] ߪೖͷޭ/ࣦഊ def buy(item, amount, coupon = nil); end end 9
୭େͨ͠આ໌Λॻ͍͍ͯͳ͍ 10
ීஈܕ͚ͩॻ͚ेͰʁ 2 2 େࣄͳ෦ʹઆ໌Λॻ͚͘ͲɺܕͱҾ໊Ͱेͳέʔεଟ͍ɻ 11
ͦΜͳgemΛ࡞Γ·ͨ͠ 12
! yard-sig https://github.com/sinsoku/yard-sig 13
͜Ε͕ class User # @param item [Item] ΞΠςϜ # @param
amount [Integer] ྔ # @param coupon [Coupon] Ϋʔϙϯ # @return [Boolean] ߪೖͷޭ/ࣦഊ def buy(item, amount, coupon = nil); end end 14
͜͏ͳΔ class User # @!sig (Item, Integer, ?Coupon) -> bool
def buy(item, amount, coupon = nil); end end 15
yard-sig • YARDϓϥάΠϯ • yard doc --plugin sig Ͱ༻Մ3 •
จ๏RBS Syntaxͱಉ͡ • ෦Ͱ @param @return ͳͲͷλάʹม 3 .yardopts ʹ --plugin sig Λࢦఆ͢Δͱָ 16
σϞʢϦϦʔε࡞ۀʣ 17
͓·͚: Rails v7.0.5ͷ has_one ͕ਏ͍ 18
ͷཁ طଘϨίʔυ͕͋Δͱ͖ͷ create_association ͷڍಈ͕มΘΔɻ • v7.0.4: save(validate, INSERT) -> destroy(DELETE)
• v7.0.5: destroy(DELETE) -> save(validate, INSERT) v7.0.4·ͰผʑͷτϥϯβΫγϣϯͰɺόϦσʔγϣϯʹࣦഊ͠ ͯطଘϨίʔυ͕আ͞Ε͍ͯͨɻ 19
Өڹ͕͋Δέʔε 1. Uniquness Validator4 2. UNIQ constraint 3. DBґଘͷCustom Validation
• ྫ: ϨίʔυΛ࡞͔ͯ͠Β10Ҏ 4 v7.0.4ͰόάͬͯΔͷͰɺجຊతʹؾʹ͢Δඞཁ͕ͳ͍ͣɻ 20
rails/rails#48643 21