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
Rubyのメソッド解決チェーン
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
すぎうり
June 23, 2026
Programming
35
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rubyのメソッド解決チェーン
すぎうり
June 23, 2026
More Decks by すぎうり
See All by すぎうり
BareRuby ~組み込み向けRubyAOTコンパイラ~
uproad3
0
33
AIコードアポカリプス
uproad3
0
83
負債解消という仕事は儲かる
uproad3
8
5.1k
RaspberryPi Picoの表現力の拡張 ~アナログコンピュータとの出会い~
uproad3
0
55
お前はまだRubyの 型の強さを知らない
uproad3
0
45
動的型解析器 Ethotrace
uproad3
0
28
お前はまだRubyの 型システムを知らない
uproad3
1
110
UdonRubyの実現可能性について
uproad3
0
48
RubyKaja 2026
uproad3
0
42
Other Decks in Programming
See All in Programming
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
370
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
130
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
290
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
350
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
170
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2k
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
330
Distance field of Julia set
kinakomoti321
0
310
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
590
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
小さなアプリを作って公開するまで
onozaty
0
160
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
370
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Color Theory Basics | Prateek | Gurzu
gurzu
1
520
The Cult of Friendly URLs
andyhume
79
7.1k
Facilitating Awesome Meetings
lara
57
7.2k
Ruling the World: When Life Gets Gamed
codingconduct
0
440
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
430
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
Unsuck your backbone
ammeep
672
58k
Transcript
Rubyのメソッド解決チェーン すぎうり
メソッド解決チェーンとは Rubyがメソッドを呼ぶとき、どこを探しに行くか MyClass 呼ばれたクラス SuperClass 継承元クラス Object BasicObject ← 先に探す
後で探す → obj.greet # MyClass に greet があれば → 使う # なければ → SuperClass を探す → Object → BasicObject この探索順序がメソッド解決チェーン( Method Resolution Order)
include するとチェーンの後ろに入る module Greetable def greet; 'Hello!'; end end class
MyClass include Greetable end 解決チェーン MyClass Greetable Object MyClass の後ろ(継承元の手前)に差し込まれる MyClass.ancestors # => [MyClass, Greetable, Object, ...] MyClass.new.greet # => 'Hello!' クラス自身にメソッドがなければ、 includeしたモジュールに委ねる
prepend するとチェーンの先頭に入る module Greetable def greet puts 'called!' super end
end class MyClass prepend Greetable end MyClass.ancestors # => [Logger, MyClass, Object, ...] MyClass.new.greet # => 'called!' include の場合(参考) MyClass Greetable Object prepend の場合 Greetable MyClass Object MyClass より前(先頭)に割り込む どのメソッドを呼んでも、必ず prependのGreetableを通る
元のメソッドを変えずに、呼び出しを横取りできる 呼び出しの流れ 呼び出し元 prepend モジュール ← 先に通る 元のメソッド super で呼ばれる
戻り値 引数を記録する module Tracer def greet(name) # 引数を記録する $log << { method: :greet, args: [name], class: name.class } super # 元のメソッドを呼ぶ end end MyClass.prepend(Tracer)