Class: Byebug::BreakCommand

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

Overview

Implements breakpoint functionality

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, #match

Methods included from StringFunctions

#camelize, #prettify

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Methods included from ParseFunctions

#get_int, #parse_steps, #syntax_valid?

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject


36
37
38
39
40
41
42
43
# File 'lib/byebug/commands/break.rb', line 36

def description
  prettify <<-EOD
    b[reak] [file:]line [if expr]
    b[reak] [module::...]class(.|#)method [if expr]

    Set breakpoint to some position, (optionally) if expr == true
  EOD
end

.namesObject


32
33
34
# File 'lib/byebug/commands/break.rb', line 32

def names
  %w(break)
end

Instance Method Details

#executeObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/byebug/commands/break.rb', line 15

def execute
  return puts(self.class.help) unless @match[1]

  brkpt = line_breakpoint(@match[1]) || method_breakpoint(@match[1])
  if syntax_valid?(@match[2])
    return puts(
      pr('break.created', id: brkpt.id, file: brkpt.source, line: brkpt.pos)
    )
  end

  errmsg(pr('break.errors.expression', expr: @match[2]))
  brkpt.enabled = false
rescue => e
  errmsg(e.message)
end

#regexpObject


11
12
13
# File 'lib/byebug/commands/break.rb', line 11

def regexp
  /^\s* b(?:reak)? (?:\s+ (\S+))? (?:\s+ if \s+(.+))? \s*$/x
end