From: GO Noguchi Date: 2008-03-11T12:44:41+09:00 Subject: [ruby-dev:34019] DelegateClassのバックトレース 野口と申します。 DelegateClassで委譲したオブジェクトのメソッドで発生した 例外の箇所がバックトレースに現れないようです。 % 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 以上のようなスクリプトを実行すると % 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 このようになりますが 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 と出るのが正しいのではないでしょうか。 Index: delegate.rb =================================================================== --- delegate.rb (リビジョン 15743) +++ delegate.rb (作業コピー) @@ -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