class DEBUGGER__::WatchIVarBreakpoint
def initialize ivar, object, current, cond: nil, command: nil, path: nil
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
def setup
def setup @tp = TracePoint.new(:line, :return, :b_return){|tp| watch_eval(tp) } end
def to_s
def to_s value_str = if defined?(@prev) "#{@prev} -> #{@current}" else "#{@current}" end "#{generate_label("Watch")} #{@object} #{@ivar} = #{value_str}" end
def watch_eval(tp)
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