Class: Pry::Code::LOC Private
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.
Instance Attribute Summary collapse
- #tuple ⇒ Array<String, Integer> readonly private
Instance Method Summary collapse
- #==(other) ⇒ Boolean private
-
#add_line_number(max_width = 0, color = false) ⇒ void
private
Prepends the line number ‘lineno` to the `line`.
-
#add_marker(marker_lineno) ⇒ void
private
Prepends a marker “=>” or an empty marker to the
line
. -
#colorize(code_type) ⇒ void
private
Paints the ‘line` of code.
- #dup ⇒ Object private
-
#indent(distance) ⇒ void
private
Indents the ‘line` with
distance
spaces. -
#initialize(line, lineno) ⇒ LOC
constructor
private
A new instance of LOC.
- #line ⇒ String private
- #lineno ⇒ Integer private
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.
27 28 29 |
# File 'lib/pry/code/loc.rb', line 27 def initialize(line, lineno) @tuple = [line.chomp, lineno.to_i] end |
Instance Attribute Details
#tuple ⇒ Array<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.
23 24 25 |
# File 'lib/pry/code/loc.rb', line 23 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.
32 33 34 |
# File 'lib/pry/code/loc.rb', line 32 def ==(other) other.tuple == tuple end |
#add_line_number(max_width = 0, color = false) ⇒ 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`.
62 63 64 65 66 |
# File 'lib/pry/code/loc.rb', line 62 def add_line_number(max_width = 0, color = false) padded = lineno.to_s.rjust(max_width) colorized_lineno = color ? Pry::Helpers::BaseHelpers.colorize_code(padded) : padded tuple[0] = "#{ colorized_lineno }: #{ 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
.
73 74 75 76 77 78 79 80 |
# File 'lib/pry/code/loc.rb', line 73 def add_marker(marker_lineno) tuple[0] = if lineno == marker_lineno " => #{ line }" else " #{ line }" end end |
#colorize(code_type) ⇒ 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.
Paints the ‘line` of code.
54 55 56 |
# File 'lib/pry/code/loc.rb', line 54 def colorize(code_type) tuple[0] = CodeRay.scan(line, code_type).term end |
#dup ⇒ Object
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.
36 37 38 |
# File 'lib/pry/code/loc.rb', line 36 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.
86 87 88 |
# File 'lib/pry/code/loc.rb', line 86 def indent(distance) tuple[0] = "#{ ' ' * distance }#{ line }" end |
#line ⇒ String
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.
41 42 43 |
# File 'lib/pry/code/loc.rb', line 41 def line tuple.first end |
#lineno ⇒ Integer
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.
46 47 48 |
# File 'lib/pry/code/loc.rb', line 46 def lineno tuple.last end |