Class: Byebug::ListCommand

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

Overview

List parts of the source code.

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ParseHelper

#get_int, #parse_steps, #syntax_valid?

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?

Methods inherited from Command

#arguments, columnize, #context, #frame, help, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



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

def self.description
  <<-EOD
    l[ist][[-=]][ nn-mm]

    #{short_description}

    Lists lines 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

.regexpObject



15
16
17
# File 'lib/byebug/commands/list.rb', line 15

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

.short_descriptionObject



33
34
35
# File 'lib/byebug/commands/list.rb', line 33

def self.short_description
  'Lists lines of source code'
end

Instance Method Details

#executeObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/byebug/commands/list.rb', line 37

def execute
  msg = "No sourcefile available for #{frame.file}"
  fail(msg) unless File.exist?(frame.file)

  max_lines = n_lines(frame.file)
  b, e = range(@match[2], max_lines)
  fail('Invalid line range') unless valid_range?(b, e, max_lines)

  display_lines(b, e)

  processor.prev_line = b
end