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



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

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



27
28
29
# File 'lib/byebug/commands/list.rb', line 27

def names
  %w(list)
end

Instance Method Details

#executeObject



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

def execute
  Byebug.source_reload if Setting[:autoreload]

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

  b, e = set_line_range(Setting[:listsize], lines.size)
  return @state.previous_line if b < 0

  puts "\n[#{b}, #{e}] in #{@state.file}"
  @state.previous_line = display_list(b, e, lines, @state.line)
end

#regexpObject



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

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