Class: Byebug::TracevarCommand
- Defined in:
- lib/byebug/commands/tracevar.rb
Overview
Show (and possibily stop) at every line that changes a global variable.
Instance Attribute Summary
Attributes inherited from Command
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Command
#arguments, columnize, #context, #frame, help, #initialize, match, to_s
Methods included from Helpers::StringHelper
#camelize, #deindent, #prettify
Constructor Details
This class inherits a constructor from Byebug::Command
Class Method Details
.description ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/byebug/commands/tracevar.rb', line 14 def self.description <<-EOD 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. EOD end |
.regexp ⇒ Object
8 9 10 11 12 |
# File 'lib/byebug/commands/tracevar.rb', line 8 def self.regexp /^\s* tr(?:acevar)? (?: \s+ (\S+))? # (variable-name)? (?: \s+ (stop|nostop))? \s*$/x end |
.short_description ⇒ Object
26 27 28 |
# File 'lib/byebug/commands/tracevar.rb', line 26 def self.short_description 'Enables tracing of a global variable' end |
Instance Method Details
#execute ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/byebug/commands/tracevar.rb', line 30 def execute var = @match[1] return errmsg(pr('trace.errors.needs_global_variable')) unless var unless global_variables.include?(:"#{var}") return errmsg(pr('trace.errors.var_is_not_global', name: var)) end 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 |