Class: TypeProf::CodePosition
- Inherits:
-
Object
- Object
- TypeProf::CodePosition
- Includes:
- Comparable
- Defined in:
- lib/typeprof/code_range.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(lineno, column) ⇒ CodePosition
constructor
A new instance of CodePosition.
- #left ⇒ Object
- #right ⇒ Object
- #to_lsp ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(lineno, column) ⇒ CodePosition
Returns a new instance of CodePosition.
3 4 5 6 |
# File 'lib/typeprof/code_range.rb', line 3 def initialize(lineno, column) @lineno = lineno @column = column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
16 17 18 |
# File 'lib/typeprof/code_range.rb', line 16 def column @column end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
16 17 18 |
# File 'lib/typeprof/code_range.rb', line 16 def lineno @lineno end |
Class Method Details
.from_lsp(pos) ⇒ Object
8 9 10 |
# File 'lib/typeprof/code_range.rb', line 8 def self.from_lsp(pos) new(pos[:line] + 1, pos[:character]) end |
Instance Method Details
#<=>(other) ⇒ Object
18 19 20 21 |
# File 'lib/typeprof/code_range.rb', line 18 def <=>(other) cmp = @lineno <=> other.lineno cmp == 0 ? @column <=> other.column : cmp end |
#==(other) ⇒ Object Also known as: eql?
25 26 27 |
# File 'lib/typeprof/code_range.rb', line 25 def ==(other) @lineno == other.lineno && @column == other.column end |
#hash ⇒ Object
31 32 33 |
# File 'lib/typeprof/code_range.rb', line 31 def hash [@lineno, @column].hash end |
#left ⇒ Object
41 42 43 44 |
# File 'lib/typeprof/code_range.rb', line 41 def left raise if @column == 0 CodePosition.new(@lineno, @column - 1) end |
#right ⇒ Object
46 47 48 |
# File 'lib/typeprof/code_range.rb', line 46 def right CodePosition.new(@lineno, @column + 1) end |
#to_lsp ⇒ Object
12 13 14 |
# File 'lib/typeprof/code_range.rb', line 12 def to_lsp { line: @lineno - 1, character: @column } end |
#to_s ⇒ Object Also known as: inspect
35 36 37 |
# File 'lib/typeprof/code_range.rb', line 35 def to_s "(%d,%d)" % [@lineno, @column] end |