fork download
  1. require 'delegate'
  2.  
  3.  
  4. # 正しい動作
  5. a = Object.new
  6. def a.test
  7. p 1
  8. end
  9. c = SimpleDelegator.new( a )
  10. c.test
  11.  
  12.  
  13.  
  14. # 間違った動作を起こす
  15.  
  16. class Uy_Object
  17. def initialize
  18. end
  19. def respond_to_missing?(m, include_private)
  20. # 呼ばれるべきではないメソッド
  21. p :responde_to_missing
  22. self.__getobj__.respond_to?(m, include_private)
  23. end
  24. def __getobj__
  25. # 呼ばれるべきではないメソッド
  26. p :exit
  27. exit
  28. end
  29. def f
  30. p :def_f
  31. end
  32. end
  33.  
  34. c.__setobj__ Uy_Object.new
  35.  
  36. c.f # => :def_f
  37.  
  38. c.test # exit
  39.  
  40.  
  41.  
Success #stdin #stdout 0.01s 5408KB
stdin
Standard input is empty
stdout
1
:def_f
:responde_to_missing
:exit