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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
すぎうり
June 23, 2026
Programming
29
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
29
AIコードアポカリプス
uproad3
0
60
負債解消という仕事は儲かる
uproad3
8
5k
RaspberryPi Picoの表現力の拡張 ~アナログコンピュータとの出会い~
uproad3
0
47
お前はまだRubyの 型の強さを知らない
uproad3
0
37
動的型解析器 Ethotrace
uproad3
0
21
お前はまだRubyの 型システムを知らない
uproad3
1
98
UdonRubyの実現可能性について
uproad3
0
44
RubyKaja 2026
uproad3
0
38
Other Decks in Programming
See All in Programming
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Railsバージョンを4倍にした話
optim
0
290
SREの越境 / SRE Collaboration
y0hgi
2
310
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
210
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.4k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
990
Exploring anti-patterns in Rails
aemeredith
4
540
4 Signs Your Business is Dying
shpigford
187
23k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
For a Future-Friendly Web
brad_frost
184
10k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
Faster Mobile Websites
deanohume
310
32k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
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)