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)
-
#==(other)
(also: #eql?)
See additional method definition at line 91.
-
#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 75
def self.[](a, b, c, d) pos1 = CodePosition.new(a, b) pos2 = CodePosition.new(c, d) new(pos1, pos2) end
.from_node(node, file_context)
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 58
def self.from_node(node, file_context) node = node.location if node.respond_to?(:location) case node when Prism::Location start_col, end_col = file_context.column_offsets_for(node) pos1 = CodePosition.new(node.start_line, start_col) pos2 = CodePosition.new(node.end_line, end_col) when 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
Instance Attribute Details
#first (readonly)
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 85
attr_reader :first, :last
#last (readonly)
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 85
attr_reader :first, :last
Instance Method Details
#<=>(other)
[ GitHub ]#==(other) Also known as: #eql?
See additional method definition at line 91.
#eql?(other)
Alias for #==.
# File 'lib/typeprof/code_range.rb', line 95
alias eql? ==
#hash
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 97
def hash [@first, @last].hash end
#include?(pos) ⇒ Boolean
# File 'lib/typeprof/code_range.rb', line 87
def include?(pos) @first <= pos && pos < @last end
#inspect
Alias for #to_s.
# File 'lib/typeprof/code_range.rb', line 105
alias inspect to_s
#to_lsp
[ GitHub ]# File 'lib/typeprof/code_range.rb', line 81
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 101
def to_s "%p-%p" % [@first, @last] end