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

**URL:** <https://www.ruby-forum.com/t/delegateclass-b-n-p-c-h-l-9-b/131538>\
**Category:** Development\
**Created:** [March 11, 2008, 5:15am UTC](https://www.ruby-forum.com/t/delegateclass-b-n-p-c-h-l-9-b/131538 "2008-03-11T05:15:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GO\_Noguchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7cd45c/32.png) [@GO\_Noguchi](https://www.ruby-forum.com/u/GO_Noguchi)\
**Post date:** [March 11, 2008, 5:15am UTC](https://www.ruby-forum.com/t/delegateclass-b-n-p-c-h-l-9-b/131538/1 "2008-03-11T05:15:34Z")

</div>

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:in`foo’  
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:in`foo’  
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

```

- 

```
      $@.delete_if{ |line| line.index( __FILE__ ) == 0}
      raise
    end
  end
```
