class Pry::Code::LOC

loc.line #=> “ def examplen :examplenend”
loc.indent(3)
#=> nil
end
:example
def example
puts loc.line
loc = LOC.new(“def examplen :examplenend”, 1)
@example
@api private
instance methods. ‘Pry::Code` heavily uses this class.
`LOC` object’s state (namely, the line parameter) can be changed via
A line of code is a tuple, which consists of a line and a line number. A
the entirety was eval’d as a single unit following the ‘edit` command).
Represents a line of code (which may, in fact, contain multiple lines if

def ==(other)

Returns:
  • (Boolean) -
def ==(other)
  other.tuple == tuple
end

def add_line_number(max_width = 0, color = false)

Returns:
  • (void) -

Parameters:
  • max_width (Integer) --
def add_line_number(max_width = 0, color = false)
  padded = lineno.to_s.rjust(max_width)
  colorized_lineno =
    if color
      Pry::Helpers::BaseHelpers.colorize_code(padded)
    else
      padded
    end
  properly_padded_line = handle_multiline_entries_from_edit_command(line, max_width)
  tuple[0] = "#{colorized_lineno}: #{properly_padded_line}"
end

def add_marker(marker_lineno)

Returns:
  • (void) -

Parameters:
  • marker_lineno (Integer) -- If it is equal to the `lineno`, then
def add_marker(marker_lineno)
  tuple[0] =
    if lineno == marker_lineno
      " => #{line}"
    else
      "    #{line}"
    end
end

def colorize(code_type)

Returns:
  • (void) -

Parameters:
  • code_type (Symbol) --
def colorize(code_type)
  tuple[0] = SyntaxHighlighter.highlight(line, code_type)
end

def dup

def dup
  self.class.new(line, lineno)
end

def handle_multiline_entries_from_edit_command(line, max_width)

def handle_multiline_entries_from_edit_command(line, max_width)
  line.split("\n").map.with_index do |inner_line, i|
    i.zero? ? inner_line : "#{' ' * (max_width + 2)}#{inner_line}"
  end.join("\n")
end

def indent(distance)

Returns:
  • (void) -

Parameters:
  • distance (Integer) --
def indent(distance)
  tuple[0] = "#{' ' * distance}#{line}"
end

def initialize(line, lineno)

Parameters:
  • lineno (Integer) -- The position of the +line+.
  • line (String) -- The line of code.
def initialize(line, lineno)
  @tuple = [line.chomp, lineno.to_i]
end

def line

Returns:
  • (String) -
def line
  tuple.first
end

def lineno

Returns:
  • (Integer) -
def lineno
  tuple.last
end