Class: TypeProf::CodeRange
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/typeprof/code_range.rb |
Class Method Summary
Instance Attribute Summary
Instance Method Summary
-
#==(other)
(also: #eql?)
See additional method definition at line 92.
-
#eql?(other)
Alias for #==.
- #hash
- #include?(pos) ⇒ Boolean
-
#inspect
Alias for #to_s.
- #to_lsp
- #to_s (also: #inspect)
Constructor Details
.new(first, last) ⇒ CodeRange
Class Method Details
.[](a, b, c, d)
[ GitHub ]# File '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)
[ GitHub ]# File '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
Instance Attribute Details
#first (readonly)
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 86
attr_reader :first, :last
#last (readonly)
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 86
attr_reader :first, :last
Instance Method Details
#==(other) Also known as: #eql?
See additional method definition at line 92.
#eql?(other)
Alias for #==.
# File 'lib/typeprof/code_range.rb', line 96
alias eql? ==
#hash
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 98
def hash [@first, @last].hash end
#include?(pos) ⇒ Boolean
# File 'lib/typeprof/code_range.rb', line 88
def include?(pos) @first <= pos && pos < @last end
#inspect
Alias for #to_s.
# File 'lib/typeprof/code_range.rb', line 106
alias inspect to_s
#to_lsp
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 82
def to_lsp { start: @first.to_lsp, end: @last.to_lsp } end
#to_s Also known as: #inspect
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 102
def to_s "%p-%p" % [@first, @last] end