Skip to content

Instantly share code, notes, and snippets.

@blackawa
Created March 10, 2017 09:53
Show Gist options
  • Save blackawa/f7b6d470daaf18ba0ee44d9d05f3e078 to your computer and use it in GitHub Desktop.
Save blackawa/f7b6d470daaf18ba0ee44d9d05f3e078 to your computer and use it in GitHub Desktop.
呼ばれるのはHogeのmethod_missingだけ。
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