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
最近追加した型の紹介とその振り返り
Search
a_fujisaki
July 11, 2024
Programming
910
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
最近追加した型の紹介とその振り返り
a_fujisaki
July 11, 2024
More Decks by a_fujisaki
See All by a_fujisaki
自作マクロと型生成
aki19035vc
0
59
rails newと同時に型を書く
aki19035vc
6
1.3k
“Rails × 型”での2年間を振り返る
aki19035vc
2
1.2k
rbs-inlineを使ってみた
aki19035vc
0
1.1k
Emacs × LSP × Steep
aki19035vc
0
300
MiniMagickの型を生成したい
aki19035vc
0
170
Other Decks in Programming
See All in Programming
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
140
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
190
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2k
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
120
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
200
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
8
5.6k
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
450
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
240
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
310
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
150
Domain-Driven Transformation
hschwentner
2
2.3k
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
GraphQLとの向き合い方2022年版
quramy
50
15k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
KATA
mclloyd
PRO
35
16k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
320
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Speed Design
sergeychernyshev
33
2.1k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
480
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
Marketing to machines
jonoalderson
1
5.9k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Google's AI Overviews - The New Search
badams
0
1.6k
Transcript
最近追加した型の紹介とその振り返り Roppongi.rb#20 2024/07/11 @aki19035vc
自己紹介 ❏ 藤崎 亮人 ❏ @aki19035vc ❏ 所属: イタンジ株式会社 ❏
バックエンドエンジニア ❏ Ruby歴5年くらい。Railsも同じくらい ❏ 学生の頃からEmacs使ってます
話す事 ❏ ここ最近で追加したり修正したりした型の話 (※ 事例紹介的な感じ) ❏ その際に困った事とか今後やりたい事なども併せて紹介 ※型についての基本的な解説はしません。 「ruby rbs
入門」とかで調べるとたくさん出てきます
コントリビュートのきっかけ ❏ 業務で書いているRailsアプリケーションでは型をほぼ100% 書いている ❏ gemの型はない事が多いため、使用するメソッドの型などは 自前で書く事が多い ❏ 他のRailsアプリケーションでも使いたい事もある ❏
せっかくなのでコミュニティに還元していきたい
PR作る前に何をしたか ❏ CONTRIBUTING.md を読む ❏ 既存の型定義を読む ❏ 他の人の過去のPRを読む ❏ gemのドキュメント・実装を読む
❏ ここが一番大変 ❏ 業務ではその時使用する特定の状態のみを記述して、とりあえず型チェックを 通すようにしていた ❏ コントリビュートする際は取りうる状態をすべて考慮して型を追加しないといけな い
最近やったこと ❏ csv: CSV::Row#initialize の型の追加 ❏ https://github.com/ruby/rbs/pull/1903 (まだマージされてません) ❏ zlib:
GzipReader のシングルトンメソッドの型の追加 ❏ https://github.com/ruby/rbs/pull/1911 (まだマージされてません) ❏ ActiveModel: バリデーション周りの型を追加・修正 ❏ https://github.com/ruby/gem_rbs_collection/pull/614 ❏ https://github.com/ruby/gem_rbs_collection/pull/615 ❏ MiniMagick: 新しく型を追加 ❏ https://github.com/ruby/gem_rbs_collection/pull/616
ActiveModelのバリデーション周りの型を追加・修正
ActiveModelのバリデーション周りの型を追加・修正 ❏ Rails 6.1 から追加されたActiveModel::Errorの型がないので追加した person = Person.new person.valid? person.errors.each
do |error| error #=> ActiveModel::Error end require "active_model" class Person include ActiveModel::Validations attr_accessor :name validates :name, presence: true end
困ったこと ❏ 7.0のディレクトリ内にある型ファイルが 6.0のディレクトリ内の型ファイルへの シンボリックリンクになっている ❏ 7.0の方にだけ型を追加したり修正したりする場合、既存の型定義を activemodel-6.0.rbs に移す必要がある gem_rbs_collection/gems/activemodel
├── 6.0 │ ├── activemodel-generated.rbs │ ├── activemodel.rbs │ └── patch.rbs └── 7.0 ├── activemodel-7.0.rbs ├── activemodel-generated.rbs -> ../6.0/activemodel-generated.rbs ├── activemodel.rbs -> ../6.0/activemodel.rbs └── patch.rbs -> ../6.0/patch.rbs
困ったこと ❏ 7.0のディレクトリ内にある型ファイルが 6.0のディレクトリ内の型ファイルへの シンボリックリンクになっている ❏ 7.0の方にだけ型を追加する場合、既存の型定義を activemodel-6.0.rbsに移す 必要がある gem_rbs_collection/gems/activemodel
├── 6.0 │ ├── activemodel-generated.rbs │ ├── activemodel.rbs │ └── patch.rbs └── 7.0 ├── activemodel-7.0.rbs ├── activemodel-generated.rbs -> ../6.0/activemodel-generated.rbs ├── activemodel.rbs -> ../6.0/activemodel.rbs └── patch.rbs -> ../6.0/patch.rbs ❏ 今回は既存の型は変更せず、ActiveModel::Errorをactivemodel-7.0.rbsに追加する だけにした ❏ シンボリックリンクを使う方法はどうにかしたいとのことなので、今後改善されるかも?
MiniMagickの型を追加
MiniMagick ❏ ImageMagickという画像を扱うソフトウェアのRubyバインディング ❏ 画像をリサイズしたりフォーマットを変換したりできる $ magick mogrify -resize 100x100
-format png -write output.png input.jpg require "mini_magick" image = MiniMagick::Image.open("input.jpg") image.resize "100x100" image.format "png" image.write "output.png"
困った事 ❏ method_missing で黒魔術してる ❏ ImageMagickのコマンドを作るDSLが提供されているイメージ ❏ 使用可能なオプションが何百と存在するため、それら全てをメソッドとして定義する のは大変 module
MiniMagick class Tool def method_missing(name, *args) option = "-#{name.to_s.tr('_', '-')}" self << option self.merge!(args) self end end end image.resize "100x100" image.format "png" image.write "output.png" #=> これらのメソッドは定義されていない
どうしたか・どうしたいか ❏ 実際に定義されているメソッドの型はひとまず追加 ❏ 定義されていないが、READMEで使われている一般的なメソッドは追加 ❏ ImageMagickで使えるオプションを全て定義することはできていない ❏ http://www.imagemagick.org/script/mogrify.php ドキュメントをパースして型定
義を生成したい
最後に ❏ 既存のgemの型の修正は意外と簡単 ❏ 新規にgemの型を追加する際は考える事が多くて意外と大変 ❏ rbs_collectionはマージされたらすぐ使えるようになるため、コントリビュートの実 感は得やすい 自前で書いている型があれば積極的にコントリビュートしていきましょう!!