Class: TypeProf::CodeRange
- Inherits:
-
Object
- Object
- TypeProf::CodeRange
- Defined in:
- lib/typeprof/code_range.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql? ⇒ Object
- #hash ⇒ Object
- #include?(pos) ⇒ Boolean
-
#initialize(first, last) ⇒ CodeRange
constructor
A new instance of CodeRange.
- #to_lsp ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(first, last) ⇒ CodeRange
Returns a new instance of CodeRange.
52 53 54 55 56 |
# File 'lib/typeprof/code_range.rb', line 52 def initialize(first, last) @first = first @last = last raise unless first end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
85 86 87 |
# File 'lib/typeprof/code_range.rb', line 85 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
85 86 87 |
# File 'lib/typeprof/code_range.rb', line 85 def last @last end |
Class Method Details
.[](a, b, c, d) ⇒ Object
75 76 77 78 79 |
# 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) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 Method Details
#<=>(other) ⇒ Object
111 112 113 114 |
# File 'lib/typeprof/code_range.rb', line 111 def <=>(other) cmp = @first <=> other.first cmp == 0 ? @last <=> other.last : cmp end |
#==(other) ⇒ Object
91 92 93 |
# File 'lib/typeprof/code_range.rb', line 91 def ==(other) @first == other.first && @last == other.last end |
#eql? ⇒ Object
95 96 97 |
# File 'lib/typeprof/code_range.rb', line 95 def ==(other) @first == other.first && @last == other.last end |
#hash ⇒ Object
97 98 99 |
# File 'lib/typeprof/code_range.rb', line 97 def hash [@first, @last].hash end |
#include?(pos) ⇒ Boolean
87 88 89 |
# File 'lib/typeprof/code_range.rb', line 87 def include?(pos) @first <= pos && pos < @last end |
#to_lsp ⇒ Object
81 82 83 |
# File 'lib/typeprof/code_range.rb', line 81 def to_lsp { start: @first.to_lsp, end: @last.to_lsp } end |
#to_s ⇒ Object Also known as: inspect
101 102 103 |
# File 'lib/typeprof/code_range.rb', line 101 def to_s "%p-%p" % [@first, @last] end |