class DEBUGGER__::WatchIVarBreakpoint

公共类方法

new(ivar, object, current, cond: nil, command: nil, path: nil) 点击切换源代码
调用父类方法 DEBUGGER__::Breakpoint::new
# File debug-1.10.0/lib/debug/breakpoint.rb, line 382
def initialize ivar, object, current, cond: nil, command: nil, path: nil
  @ivar = ivar.to_sym
  @object = object
  @key = [:watch, object.object_id, @ivar].freeze

  @current = current

  super(cond, command, path)
end

公共实例方法

setup() 点击切换源代码
# File debug-1.10.0/lib/debug/breakpoint.rb, line 410
def setup
  @tp = TracePoint.new(:line, :return, :b_return){|tp|
    watch_eval(tp)
  }
end
to_s() 点击切换源代码
# File debug-1.10.0/lib/debug/breakpoint.rb, line 416
def to_s
  value_str =
    if defined?(@prev)
      "#{@prev} -> #{@current}"
    else
      "#{@current}"
    end
  "#{generate_label("Watch")} #{@object} #{@ivar} = #{value_str}"
end
watch_eval(tp) 点击切换源代码
# File debug-1.10.0/lib/debug/breakpoint.rb, line 392
def watch_eval(tp)
  result = @object.instance_variable_get(@ivar)
  if result != @current
    begin
      @prev = @current
      @current = result

      if (@cond.nil? || @object.instance_eval(@cond)) && !skip_path?(tp.path)
        suspend
      end
    ensure
      remove_instance_variable(:@prev)
    end
  end
rescue Exception
  false
end