require 'delegate'
# 正しい動作
a = Object.new
def a.test
p 1
end
c = SimpleDelegator.new( a )
c.test
# 間違った動作を起こす
class Uy_Object
def initialize
end
def respond_to_missing?(m, include_private)
# 呼ばれるべきではないメソッド
p :responde_to_missing
self.__getobj__.respond_to?(m, include_private)
end
def __getobj__
# 呼ばれるべきではないメソッド
p :exit
exit
end
def f
p :def_f
end
end
c.__setobj__ Uy_Object.new
c.f # => :def_f
c.test # exit
cmVxdWlyZSAnZGVsZWdhdGUnCgoKIyDmraPjgZfjgYTli5XkvZwKYSA9IE9iamVjdC5uZXcKZGVmIGEudGVzdAogIHAgMQplbmQKYyA9IFNpbXBsZURlbGVnYXRvci5uZXcoIGEgKQpjLnRlc3QKCgoKIyDplpPpgZXjgaPjgZ/li5XkvZzjgpLotbfjgZPjgZkKCmNsYXNzIFV5X09iamVjdAogIGRlZiBpbml0aWFsaXplCiAgZW5kCiAgZGVmIHJlc3BvbmRfdG9fbWlzc2luZz8obSwgaW5jbHVkZV9wcml2YXRlKQogICAgIyDlkbzjgbDjgozjgovjgbnjgY3jgafjga/jgarjgYTjg6Hjgr3jg4Pjg4kKICAgIHAgOnJlc3BvbmRlX3RvX21pc3NpbmcKICAgIHNlbGYuX19nZXRvYmpfXy5yZXNwb25kX3RvPyhtLCBpbmNsdWRlX3ByaXZhdGUpCiAgZW5kCiAgZGVmIF9fZ2V0b2JqX18KICAgICMg5ZG844Gw44KM44KL44G544GN44Gn44Gv44Gq44GE44Oh44K944OD44OJCiAgICBwIDpleGl0CiAgICBleGl0CiAgZW5kCiAgZGVmIGYKICAgIHAgOmRlZl9mCiAgZW5kCmVuZAoKYy5fX3NldG9ial9fICBVeV9PYmplY3QubmV3CiAKYy5mICMgPT4gOmRlZl9mCgpjLnRlc3QgIyBleGl0CgoK