Class: Byebug::ListCommand

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

Overview

List parts of the source code.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



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

def description
  %(l[ist][[-=]][ nn-mm]

    Lists lines of code forward from current line or from the place where
    code was last listed. If "list-" is specified, lists backwards
    instead. If "list=" is specified, lists from current line regardless
    of where code was last listed. A line range can also be specified to
    list specific sections of code.)
end

.namesObject



25
26
27
# File 'lib/byebug/commands/list.rb', line 25

def names
  %w(list)
end

Instance Method Details

#executeObject



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

def execute
  Byebug.source_reload if Setting[:autoreload]

  lines = get_lines(@state.file)
  return errmsg "No sourcefile available for #{@state.file}\n" unless lines

  @match ||= match('list')
  b, e = range(@match[2], lines.size)
  return errmsg('Invalid line range') unless valid_range?(b, e, lines.size)
  display_lines(b, e, lines)

  @state.prev_line = b
end

#regexpObject



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

def regexp
  /^\s* l(?:ist)? (?:\s*([-=])|\s+(\S+))? \s*$/x
end