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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
manabeai
October 30, 2025
Programming
34
0
Share
Kaminariのコードリーディングをしよう
manabeai
October 30, 2025
More Decks by manabeai
See All by manabeai
関数型プログラミングで 「脳がバグる」を乗り越える
manabeai
2
390
dry-monadsで安全に副作用を扱おう
manabeai
0
170
Other Decks in Programming
See All in Programming
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
5
2.5k
Rethinking API Platform Filters
vinceamstoutz
0
10k
The free-lunch guide to idea circularity
hollycummins
0
420
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.3k
Swift Concurrency Type System
inamiy
0
180
[PHPerKaigi 2026]PHPerKaigi2025の企画CodeGolfが最高すぎて社内で内製して半年運営して得た内製と運営の知見
ikezoemakoto
0
340
VueエンジニアがReactを触って感じた_設計の違い
koukimiura
0
160
瑠璃の宝石に学ぶ技術の声の聴き方 / 【劇場版】アニメから得た学びを発表会2026 #エンジニアニメ
mazrean
0
170
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
810
「効かない!」依存性注入(DI)を活用したAPI Platformのエラーハンドリング奮闘記
mkmk884
0
300
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
340
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
970
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
The browser strikes back
jonoalderson
0
900
Measuring & Analyzing Core Web Vitals
bluesmoon
9
800
Between Models and Reality
mayunak
3
260
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
260
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
510
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
670
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
270
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
430
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
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は言語の性質上コードジャンプができなくて定義を負いにくいこともある • まずはリファレンスをよく読み、それでも解決しなければソースコードをよく見てみよ う