Class: DebuggerCode::LOC Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-debugger/code/loc.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a line of code. A line of code is a tuple, which consists of a line and a line number. A ‘LOC` object’s state (namely, the line parameter) can be changed via instance methods. ‘Pry::Code` heavily uses this class.

Examples:

loc = LOC.new("def example\n  :example\nend", 1)
puts loc.line
def example
  :example
end
#=> nil

loc.indent(3)
loc.line #=> "   def example\n  :example\nend"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, lineno) ⇒ LOC

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LOC.

Parameters:

  • line (String)

    The line of code.

  • lineno (Integer)

    The position of the line.



26
27
28
# File 'lib/puppet-debugger/code/loc.rb', line 26

def initialize(line, lineno)
  @tuple = [line.chomp, lineno.to_i]
end

Instance Attribute Details

#tupleArray<String, Integer> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



22
23
24
# File 'lib/puppet-debugger/code/loc.rb', line 22

def tuple
  @tuple
end

Instance Method Details

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


31
32
33
# File 'lib/puppet-debugger/code/loc.rb', line 31

def ==(other)
  other.tuple == tuple
end

#add_line_number(max_width = 0) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Prepends the line number ‘lineno` to the `line`.

Parameters:

  • max_width (Integer) (defaults to: 0)


52
53
54
55
# File 'lib/puppet-debugger/code/loc.rb', line 52

def add_line_number(max_width = 0)
  padded = lineno.to_s.rjust(max_width)
  tuple[0] = "#{padded}: #{line}"
end

#add_marker(marker_lineno) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Prepends a marker “=>” or an empty marker to the line.

Parameters:

  • marker_lineno (Integer)

    If it is equal to the ‘lineno`, then prepend a hashrocket. Otherwise, an empty marker.



62
63
64
65
66
67
68
69
# File 'lib/puppet-debugger/code/loc.rb', line 62

def add_marker(marker_lineno)
  tuple[0] =
    if lineno == marker_lineno
      " => #{line}".cyan
    else
      "    #{line}"
    end
end

#dupObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/puppet-debugger/code/loc.rb', line 35

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

#indent(distance) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Indents the ‘line` with distance spaces.

Parameters:

  • distance (Integer)


75
76
77
# File 'lib/puppet-debugger/code/loc.rb', line 75

def indent(distance)
  tuple[0] = "#{' ' * distance}#{line}"
end

#lineString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



40
41
42
# File 'lib/puppet-debugger/code/loc.rb', line 40

def line
  tuple.first
end

#linenoInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)


45
46
47
# File 'lib/puppet-debugger/code/loc.rb', line 45

def lineno
  tuple.last
end