class TypeProf::CodeRange
Attributes
Public Class Methods
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 73 def self.[](a, b, c, d) pos1 = CodePosition.new(a, b) pos2 = CodePosition.new(c, d) new(pos1, pos2) end
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 58 def self.from_node(node, encoding = Encoding::UTF_16LE) node = node.location if node.respond_to?(:location) 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.is_a?(RBS::Location) pos1 = CodePosition.new(*node.start_loc) pos2 = CodePosition.new(*node.end_loc) else p node.class.ancestors raise "unknown type: #{ node.class }" end new(pos1, pos2) end
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 52 def initialize(first, last) @first = first @last = last raise unless first end
Public Instance Methods
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 109 def <=>(other) cmp = @first <=> other.first cmp == 0 ? @last <=> other.last : cmp end
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 89 def ==(other) @first == other.first && @last == other.last end
Also aliased as: eql?
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 95 def hash [@first, @last].hash end
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 85 def include?(pos) @first <= pos && pos < @last end
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/code_range.rb, line 79 def to_lsp { start: @first.to_lsp, end: @last.to_lsp } end