class Byebug::TracevarCommand - byebug-11.0.1 Documentation

# class Byebug::TracevarCommand

Show (and possibily stop) at every line that changes a global variable.

### Public Class Methods

description() click to toggle source

    # File lib/byebug/commands/tracevar.rb, line 16
        def self.description
          <<-DESCRIPTION
            tr[acevar] <variable> [[no]stop]

            #{short_description}

            If "stop" is specified, execution will stop every time the variable
            changes its value. If nothing or "nostop" is specified, execution won't
            stop, changes will just be logged in byebug's output.
          DESCRIPTION
        end

regexp() click to toggle source

    # File lib/byebug/commands/tracevar.rb, line 10
    def self.regexp
      /^\s* tr(?:acevar)? (?: \s+ (\S+))?  # (variable-name)?
                          (?: \s+ (stop|nostop))?
       \s*$/x
    end

short_description() click to toggle source

    # File lib/byebug/commands/tracevar.rb, line 28
    def self.short_description
      "Enables tracing of a global variable"
    end

### Public Instance Methods

execute() click to toggle source

    # File lib/byebug/commands/tracevar.rb, line 32
    def execute
      var = @match[1]
      return errmsg(pr("trace.errors.needs_global_variable")) unless var
      return errmsg(pr("trace.errors.var_is_not_global", name: var)) unless global_variables.include?(:"#{var}")

      stop = @match[2] && @match[2] !~ /nostop/

      instance_eval do
        trace_var(:"#{var}") { |val| on_change(var, val, stop) }
      end

      puts pr("trace.messages.success", var: var)
    end

### Private Instance Methods

on_change(name, value, stop) click to toggle source

    # File lib/byebug/commands/tracevar.rb, line 48
    def on_change(name, value, stop)
      puts pr("trace.messages.on_change", name: name, value: value)

      context.step_out(1, false) if stop
    end