Class: Pry::Code::CodeRange 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 range of lines in a code listing.
Instance Attribute Summary collapse
- #end_line ⇒ Object readonly private private
- #start_line ⇒ Object readonly private private
Instance Method Summary collapse
- #find_end_index(lines) ⇒ Integer private private
- #find_start_index(lines) ⇒ Integer private private
-
#force_set_end_line
private
private
If
end_line
is equal tonil
, then calculate it from the first parameter,start_line
. -
#indices(lines) ⇒ Array<Integer>
private
private
Finds indices of
start_line
andend_line
in the given Array of +lines+. - #indices_range(lines) ⇒ Range private
-
#initialize(start_line, end_line = nil) ⇒ CodeRange
constructor
private
A new instance of CodeRange.
-
#set_end_line_from_range
private
private
For example, if the range is 4..10, then
start_line
would be equal to 4 andend_line
to 10.
Constructor Details
#initialize(start_line, end_line = nil) ⇒ CodeRange
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 CodeRange.
11 12 13 14 15 |
# File 'lib/pry/code/code_range.rb', line 11 def initialize(start_line, end_line = nil) @start_line = start_line @end_line = end_line force_set_end_line end |
Instance Attribute Details
#end_line ⇒ Object (readonly, private)
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.
27 28 29 |
# File 'lib/pry/code/code_range.rb', line 27 def end_line @end_line end |
#start_line ⇒ Object (readonly, private)
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.
25 26 27 |
# File 'lib/pry/code/code_range.rb', line 25 def start_line @start_line end |
Instance Method Details
#find_end_index(lines) ⇒ Integer (private)
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.
57 58 59 60 61 |
# File 'lib/pry/code/code_range.rb', line 57 def find_end_index(lines) return end_line if end_line < 0 (lines.index { |loc| loc.lineno > end_line } || 0) - 1 end |
#find_start_index(lines) ⇒ Integer (private)
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.
50 51 52 53 54 |
# File 'lib/pry/code/code_range.rb', line 50 def find_start_index(lines) return start_line if start_line < 0 lines.index { |loc| loc.lineno >= start_line } || lines.length end |
#force_set_end_line (private)
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.
If end_line
is equal to nil
, then calculate it from the first
parameter, start_line
. Otherwise, leave it as it is.
32 33 34 35 36 37 38 |
# File 'lib/pry/code/code_range.rb', line 32 def force_set_end_line if start_line.is_a?(Range) set_end_line_from_range else @end_line ||= start_line end end |
#indices(lines) ⇒ Array<Integer> (private)
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.
Finds indices of start_line
and end_line
in the given Array of
+lines+.
45 46 47 |
# File 'lib/pry/code/code_range.rb', line 45 def indices(lines) [find_start_index(lines), find_end_index(lines)] end |
#indices_range(lines) ⇒ Range
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.
19 20 21 |
# File 'lib/pry/code/code_range.rb', line 19 def indices_range(lines) Range.new(*indices(lines)) end |
#set_end_line_from_range (private)
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.
For example, if the range is 4..10, then start_line
would be equal to
4 and end_line
to 10.
66 67 68 69 70 |
# File 'lib/pry/code/code_range.rb', line 66 def set_end_line_from_range @end_line = start_line.last @end_line -= 1 if start_line.exclude_end? @start_line = start_line.first end |