class Pry::Code::CodeRange
Represents a range of lines in a code listing.
@api private
Attributes
end_line[R]
start_line[R]
Public Class Methods
new(start_line, end_line = nil)
click to toggle source
@param [Integer] start_line
@param [Integer?] end_line
# 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
Public Instance Methods
indices_range(lines)
click to toggle source
@param [Array<LOC>] lines @return [Range]
# File lib/pry/code/code_range.rb, line 19 def indices_range(lines) Range.new(*indices(lines)) end
Private Instance Methods
find_end_index(lines)
click to toggle source
@return [Integer]
# 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)
click to toggle source
@return [Integer]
# 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()
click to toggle source
If `end_line` is equal to `nil`, then calculate it from the first parameter, `start_line`. Otherwise, leave it as it is. @return [void]
# 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)
click to toggle source
Finds indices of `start_line` and `end_line` in the given Array of lines
.
@param [Array<LOC>] lines @return [Array<Integer>]
# File lib/pry/code/code_range.rb, line 45 def indices(lines) [find_start_index(lines), find_end_index(lines)] end
set_end_line_from_range()
click to toggle source
For example, if the range is 4..10, then `start_line` would be equal to 4 and `end_line` to 10. @return [void]
# 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