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
すぎうり
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
58
負債解消という仕事は儲かる
uproad3
8
4.8k
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
37
Other Decks in Programming
See All in Programming
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
160
APNsからLive Activityを開始する話
yumnumm
0
160
SREの越境 / SRE Collaboration
y0hgi
2
300
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.3k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
570
sbt 2.0: takeoff
eed3si9n
0
140
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
480
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
400
Featured
See All Featured
Abbi's Birthday
coloredviolet
4
10k
Product Roadmaps are Hard
iamctodd
55
13k
My Coaching Mixtape
mlcsv
0
350
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
Deep Space Network (abreviated)
tonyrice
0
360
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Being A Developer After 40
akosma
92
590k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
New Earth Scene 8
popppiees
4
2.7k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Raft: Consensus for Rubyists
vanstee
142
7.7k
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)