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, #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


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

def description
  prettify <<-EOD
    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.
  EOD
end

.namesObject


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

def names
  %w(list)
end

Instance Method Details

#executeObject


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

def execute
  exist = File.exist?(@state.file)
  return errmsg "No sourcefile available for #{@state.file}\n" unless exist

  @match ||= match('list')
  max_lines = n_lines(@state.file)
  b, e = range(@match[2], max_lines)
  return errmsg('Invalid line range') unless valid_range?(b, e, max_lines)

  display_lines(b, e)

  @state.prev_line = b
end

#regexpObject


8
9
10
# File 'lib/byebug/commands/list.rb', line 8

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