Hi,

On 5/17/05, Imobach GonzáÍez Sosa <imobachgs / gmail.com> wrote:
> Hi all,
> 
> We're interested in doing some backtracing in our code, but not just
> the "filename:line in method" thing, we'd like to retrieve the status
> of each object referenced.
> 
> For example, we have three objects A, B and C. A calls a B's method
> and B calls an C's method. That's ok. But the C methods raises and
> exception. At A, we could get a backtrace containing files, lines and
> methods called. But, what about some extra info as, for example, B
> status?
> 
> We've implemented such a thing using begin-end-rescue in all those
> called methods, so in the rescue they do some extra work to register
> the status. Ok?
> 
> But write a lot of methods with begin-end-rescue could be painful, at
> least for me.

Until a  better solution comes up, you could simplify it by creating a module:
-----

module DebugWrappable
  def debug_wrap(*names)
    names.each{|name| eval <<-END }
      alias_method :___#{name}, :#{name}
      def #{name}(*args, &block)
        begin
          ___#{name}(*args, &block)
        rescue Exception => e
          unless e.respond_to? :environments
            class << e; e.attr_accessor :environments; end
          end
          e.environments ||= []
          e.environments << [binding, self]
          raise e
        end
      end
    END
  end
end

class A
  def foo
    # do stuff
  end
  def Bar
    # do more stuff
  end
  include DebugWrappable
  debug_wrap :foo, :bar
end

-----

Okay, I haven't actually tried this code, so there are probably bugs.
But the idea is sound.

cheers,
Mark