Class: Byebug::BreakCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::FileHelper, Helpers::ParseHelper
Defined in:
lib/byebug/commands/break.rb

Overview

Implements breakpoint functionality

Instance Method Summary collapse

Methods included from Helpers::ParseHelper

#get_int, #parse_steps, #syntax_valid?, #without_stderr

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize

Methods inherited from Command

#help, #initialize, #match, subcommands, to_name

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Instance Method Details

#descriptionObject



39
40
41
42
43
44
45
46
# File 'lib/byebug/commands/break.rb', line 39

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

    #{short_description}
  EOD
end

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/byebug/commands/break.rb', line 20

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

  b = line_breakpoint(@match[1]) || method_breakpoint(@match[1])

  if syntax_valid?(@match[2])
    return puts(pr('break.created', id: b.id, file: b.source, line: b.pos))
  end

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

#regexpObject



16
17
18
# File 'lib/byebug/commands/break.rb', line 16

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

#short_descriptionObject



35
36
37
# File 'lib/byebug/commands/break.rb', line 35

def short_description
  'Set breakpoint to some position, (optionally) if expr == true'
end