123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::CodePosition

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Comparable
Inherits: Object
Defined in: lib/typeprof/code_range.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(lineno, column) ⇒ CodePosition

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 3

def initialize(lineno, column)
  @lineno = lineno
  @column = column
end

Class Method Details

.from_lsp(pos)

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 8

def self.from_lsp(pos)
  new(pos[:line] + 1, pos[:character])
end

Instance Attribute Details

#column (readonly)

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 16

attr_reader :lineno, :column

#lineno (readonly)

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 16

attr_reader :lineno, :column

Instance Method Details

#<=>(other)

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 18

def <=>(other)
  cmp = @lineno <=> other.lineno
  cmp == 0 ? @column <=> other.column : cmp
end

#==(other) Also known as: #eql?

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 25

def ==(other)
  @lineno == other.lineno && @column == other.column
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 29

alias eql? ==

#hash

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 31

def hash
  [@lineno, @column].hash
end

#inspect

Alias for #to_s.

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 39

alias inspect to_s

#left

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 41

def left
  raise if @column == 0
  CodePosition.new(@lineno, @column - 1)
end

#right

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 46

def right
  CodePosition.new(@lineno, @column + 1)
end

#to_lsp

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 12

def to_lsp
  { line: @lineno - 1, character: @column }
end

#to_s Also known as: #inspect

[ GitHub ]

  
# File 'lib/typeprof/code_range.rb', line 35

def to_s
  "(%d,%d)" % [@lineno, @column]
end