Created
March 10, 2017 09:53
-
-
Save blackawa/f7b6d470daaf18ba0ee44d9d05f3e078 to your computer and use it in GitHub Desktop.
呼ばれるのはHogeのmethod_missingだけ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hoge | |
def self.included(klass) | |
klass.extend ClassMethods | |
end | |
module ClassMethods | |
def foo | |
p 'foo' | |
end | |
def respond_to_missing? | |
true | |
end | |
def method_missing(method) | |
p "#{method} is missing(from module Hoge)" | |
super | |
end | |
end | |
end | |
class FugaParent | |
def method_missing(method) | |
p "#{method} is missing(from class FugaParent)" | |
super | |
end | |
end | |
class Fuga < FugaParent | |
include Hoge | |
attr_accessor :a, :b, :c | |
def initialize(h) | |
@a = h[:a] | |
@b = h[:b] | |
@c = h[:c] | |
end | |
end | |
p Fuga.new(a: 1, b: 2, c: 3) | |
p Fuga.ancestors | |
Fuga.fugaaaaaaaaaa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment