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
Kaminariのコードリーディングをしよう
Search
manabeai
October 30, 2025
Programming
0
21
Kaminariのコードリーディングをしよう
manabeai
October 30, 2025
Tweet
Share
More Decks by manabeai
See All by manabeai
関数型プログラミングで 「脳がバグる」を乗り越える
manabeai
2
360
dry-monadsで安全に副作用を扱おう
manabeai
0
130
Other Decks in Programming
See All in Programming
ゲームの物理 剛体編
fadis
0
380
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
290
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
180
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
1.9k
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
480
ゆくKotlin くるRust
exoego
1
160
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
140
gunshi
kazupon
1
120
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
390
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
160
Go コードベースの構成と AI コンテキスト定義
andpad
0
140
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
410
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
67
Designing for Performance
lara
610
69k
Speed Design
sergeychernyshev
33
1.4k
How GitHub (no longer) Works
holman
316
140k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
6.7k
Designing Powerful Visuals for Engaging Learning
tmiket
0
190
Embracing the Ebb and Flow
colly
88
4.9k
The SEO Collaboration Effect
kristinabergwall1
0
310
Deep Space Network (abreviated)
tonyrice
0
22
Tell your own story through comics
letsgokoyo
0
770
Typedesign – Prime Four
hannesfritz
42
2.9k
Transcript
Kaminariのコードリーディング をしよう 発表者: manabeai
開発あるある • エラーがよくわからん! • ググりがち • AIに聞きがち • Ruby言語の特性上、 コードジャンプできないことも
ソースコードを読んでいますか?
コードリーディングの利点 • 意図を読み解く能力が上がる • その言語の文化、構文を知れる。 • 適切な抽象化の匙加減がつかめる。
ソースコードをちゃんと読もう 通勤中...
今回読むGem • ページネーションライブラリKaminari • ActiveRecordやActionViewの連携も可能
なぜkaminariなのか • Rubyらしい • Railsらしい
None
Kaminariのしくみ • クラスメソッド: pageはどこから? ◦ ちなみに pageはインスタンスメソッドとしても使える • インスタンスメソッド: perはどこから?
Kaminariのしくみ • インスタンスメソッド: current_pageはどこから?
コードジャンプができない! githubで検索
コードジャンプができない! Ruby 3.4 リファレンスマニュアル :https://docs.ruby-lang.org/ja/latest/method/Object/i/method.html Object#methodメソッドを使う
メソッド定義を探す https://github.com/kaminari/kaminari/blob/ca4a5dcfce40ede7990ebfe00a12f21e78e910d9/kaminari-activerecord/lib/kaminari/activerecord.rb ::ActiveRecord::BaseにKaminari::ActiveRecordExtensionを includesしている
https://github.com/kaminari/kaminari/blob/ca4a5dcfce40ede7990ebfe00a12f21e78e910d9/kaminari-activerecord/lib/kaminari/activerecord/active_record_extension.rb
メソッド定義を探す https://github.com/kaminari/kaminari/blob/ca4a5dcfce40ede7990ebfe00a12f21e78e910d9/kaminari-activerecord/lib/kaminari/activerecord/active_record_extension.rb
Ruby 3.4 リファレンスマニュアル :https://docs.ruby-lang.org/ja/latest/method/Class/i/inherited.html
メソッド定義を探す ここでinheritedが実行される! 継承
メソッド定義を探す https://github.com/kaminari/kaminari/blob/ca4a5dcfce40ede7990ebfe00a12f21e78e910d9/kaminari-activerecord/lib/kaminari/activerecord/active_record_extension.rb • ActiveRecord::Baseが継承されるタイミングで実行
None
メソッド定義を探す • Kaminari.config.page_method_nameは pageメソッド • 設定で任意のメソッドに変えられる • extendingについてはこちら https://railsdoc.com/page/extending
メソッド定義を探す • perメソッドはここに
まとめ • Rubyは言語の性質上コードジャンプができなくて定義を負いにくいこともある • まずはリファレンスをよく読み、それでも解決しなければソースコードをよく見てみよ う