class TypeProf::CodeRange
Attributes
first[R]
last[R]
Public Class Methods
[](a, b, c, d)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 76 def self.[](a, b, c, d) pos1 = CodePosition.new(a, b) pos2 = CodePosition.new(c, d) new(pos1, pos2) end
from_node(node, encoding = Encoding::UTF_16LE)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 58 def self.from_node(node, encoding = Encoding::UTF_16LE) node = node.location if node.is_a?(Prism::Node) if node.is_a?(Prism::Location) pos1 = CodePosition.new(node.start_line, node.start_code_units_column(encoding)) pos2 = CodePosition.new(node.end_line, node.end_code_units_column(encoding)) elsif node.respond_to?(:location) loc = node.location row, col = loc.start_loc pos1 = CodePosition.new(row, col) # TODO: use SPLAT row, col = loc.end_loc pos2 = CodePosition.new(row, col) else p node.class.ancestors raise "unknown type: #{ node.class }" end new(pos1, pos2) end
new(first, last)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 52 def initialize(first, last) @first = first @last = last raise unless first end
Public Instance Methods
==(other)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 92 def ==(other) @first == other.first && @last == other.last end
Also aliased as: eql?
hash()
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 98 def hash [@first, @last].hash end
include?(pos)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 88 def include?(pos) @first <= pos && pos < @last end
to_lsp()
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 82 def to_lsp { start: @first.to_lsp, end: @last.to_lsp } end
to_s()
click to toggle source
# File typeprof-0.30.1/lib/typeprof/code_range.rb, line 102 def to_s "%p-%p" % [@first, @last] end
Also aliased as: inspect