DelegateClass$B$N%P%C%/%H%l!<%9(B

e$BLn8}$H?=$7$^$9!#e(B

DelegateClasse$B$G0Q>y$7$?%*%V%8%’%/%H$N%a%=%C%I$GH/@8$7$?e(B
e$BNc30$N2U=j$,%P%C%/%H%l!<%9$K8=$l$J$$$h$&$G$9!#e(B

% cat foo.rb
require ‘delegate’

class Foo
def foo
foo1
end

def foo1
raise
end
end

class Bar < DelegateClass( Foo )
def initialize
super(Foo.new)
end
end

Bar.new.foo

e$B0J>e$N$h$&$J%9%/%j%W%H$r<B9T$9$k$He(B

% ruby -v foo.rb
ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-freebsd6.1]
(eval):3:in __send__': unhandled exception from (eval):3:infoo’
from foo.rb:19

e$B$3$N$h$&$K$J$j$^$9$,e(B

ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-freebsd6.1]
foo.rb:9:in foo1': unhandled exception from foo.rb:5:infoo’
from foo.rb:19

e$B$H=P$k$N$,@5$7$$$N$G$O$J$$$G$7$g$&$+!#e(B

Index: delegate.rb

— delegate.rb (e$B%j%S%8%g%se(B 15743)
+++ delegate.rb (e$B:n6H%3%T!<e(B)
@@ -291,12 +291,12 @@
}
for method in methods
begin

  •  klass.module_eval <<-EOS
    
  •  klass.module_eval(<<-EOS, __FILE__)
       def #{method}(*args, &block)
        begin
          @_dc_obj.__send__(:#{method}, *args, &block)
        rescue
    
  •       $@[0,2] = nil