Class: Byebug::ConditionCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/condition.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

command_exists?, commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match, register_setting_get, register_setting_set, register_setting_var, settings, settings_map, terminal_width

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



30
31
32
33
34
35
36
37
# File 'lib/byebug/commands/condition.rb', line 30

def description
  %{cond[ition] nnn[ expr]

    Specify breakpoint number nnn to break only if expr is true. nnn is an
    integer and expr is an expression to be evaluated whenever breakpoint
    nnn is reached. If no expression is specified, the condition is
    removed.}
end

.namesObject



26
27
28
# File 'lib/byebug/commands/condition.rb', line 26

def names
  %w(condition)
end

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/byebug/commands/condition.rb', line 10

def execute
  return print ConditionCommand.help(nil) unless @match[1]

  breakpoints = Byebug.breakpoints.sort_by{|b| b.id }
  largest = breakpoints.inject(0) do |tally, b|
    tally = b.id if b.id > tally
  end

  return print "No breakpoints have been set.\n" if 0 == largest
  return unless pos = get_int(@match[1], "Condition", 1, largest)

  breakpoint = breakpoints.select{ |b| b.id == pos }.first
  breakpoint.expr = @match[2] if breakpoint
end

#regexpObject



6
7
8
# File 'lib/byebug/commands/condition.rb', line 6

def regexp
  /^\s* cond(?:ition)? (?:\s+(\d+)(?:\s+(.*))?)? \s*$/x
end