module Debug
  def debug(*args)
    $stderr.puts "#{self.class.name}@#{caller[0]}\n\t#{args.join(' ')}"
  end
  def debug_caller
    debug
    caller.each {|line| $stderr.puts(line)}
  end

  def inspect_variables(object)
    $stdout.puts "#{self.class.name}@#{caller[0]}"
    object.instance_variables.each { |v|$stdout.puts "#{v}=#{object.call(v[1..-1])}"}
  end

  def set_trace
    set_trace_func proc { |event, file, line, id, binding, classname|
    #unless event =~ 'c-' or file =~ 'ruby'
      if event == 'call' or event == 'return' and file =~ /^\.\//
    #if event == 'line'  and file =~ /^\.\//
      printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
      end
    }
  end

  def unset_trace
    set_trace_func nil
  end
  def set_trace_var(symbol)
    trace_var(symbol){ puts "#{symbol}  -> #{caller[0]}"}
  end
end
