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
0
30
Kaminariのコードリーディングをしよう
manabeai
October 30, 2025
Tweet
Share
More Decks by manabeai
See All by manabeai
関数型プログラミングで 「脳がバグる」を乗り越える
manabeai
2
380
dry-monadsで安全に副作用を扱おう
manabeai
0
160
Other Decks in Programming
See All in Programming
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
0
110
CSC307 Lecture 12
javiergs
PRO
0
450
RubyとGoでゼロから作る証券システム: 高信頼性が求められるシステムのコードの外側にある設計と運用のリアル
free_world21
0
180
浮動小数の比較について
kishikawakatsumi
0
370
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
440
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
200
日本だけで解禁されているアプリ起動の方法
ryunakayama
0
360
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
0
210
CopilotKit + AG-UIを学ぶ
nearme_tech
PRO
1
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
190
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
600
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
200
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
470
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Unsuck your backbone
ammeep
672
58k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
sira's awesome portfolio website redesign presentation
elsirapls
0
170
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
190
Tell your own story through comics
letsgokoyo
1
830
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
140
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
130
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は言語の性質上コードジャンプができなくて定義を負いにくいこともある • まずはリファレンスをよく読み、それでも解決しなければソースコードをよく見てみよ う