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
Rubyのメソッド解決チェーン
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
すぎうり
June 23, 2026
Programming
1
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 すぎうり
RaspberryPi Picoの表現力の拡張 ~アナログコンピュータとの出会い~
uproad3
0
0
お前はまだRubyの 型の強さを知らない
uproad3
0
1
動的型解析器 Ethotrace
uproad3
0
1
お前はまだRubyの 型システムを知らない
uproad3
1
47
UdonRubyの実現可能性について
uproad3
0
18
RubyKaja 2026
uproad3
0
10
VRChatでスライドを 表示する技術
uproad3
0
30
Other Decks in Programming
See All in Programming
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
460
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.8k
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
510
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
初めてのKubernetes 本番運用でハマった話
oku053
0
130
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
270
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
780
フィードバックで育てるAI開発
kotaminato
1
120
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
390
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
430
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
えっ!!コードを読まずに開発を!?
hananouchi
0
220
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
590
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
360
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Ruling the World: When Life Gets Gamed
codingconduct
0
280
New Earth Scene 8
popppiees
3
2.4k
Making the Leap to Tech Lead
cromwellryan
135
10k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
First, design no harm
axbom
PRO
2
1.2k
RailsConf 2023
tenderlove
30
1.5k
Accessibility Awareness
sabderemane
1
160
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)