123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::CodeRange

Relationships & Source Files
Inherits: Object
Defined in: lib/typeprof/code-range.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(first, last) ⇒ CodeRange

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 52

def initialize(first, last)
  @first, @last = first, last
end

Class Method Details

.from_lsp(lsp_range)

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 63

def self.from_lsp(lsp_range)
  CodeRange.new(CodeLocation.from_lsp(lsp[:start]), CodeLocation.from_lsp(lsp[:end]))
end

.from_rbs(rbs_loc)

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 67

def self.from_rbs(rbs_loc)
  CodeRange.new(
    CodeLocation.new(rbs_loc.start_line, rbs_loc.start_column),
    CodeLocation.new(rbs_loc.end_line, rbs_loc.end_column),
  )
end

Instance Attribute Details

#first (readonly)

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 60

attr_reader :first

#last (readonly)

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 61

attr_reader :last

Instance Method Details

#contain?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 82

def contain?(other)
  @first <= other.first && other.last <= @last
end

#contain_loc?(loc) ⇒ Boolean

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 78

def contain_loc?(loc)
  @first <= loc && loc < @last
end

#inspect

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 56

def inspect
  "%p-%p" % [@first, @last]
end

#overlap?(other) ⇒ Boolean

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 86

def overlap?(other)
  if @first <= other.first
    return @last > other.first
  else
    return @first < other.last
  end
end

#to_lsp

[ GitHub ]

  
# File 'lib/typeprof/code-range.rb', line 74

def to_lsp
  { start: @first.to_lsp, end: @last.to_lsp }
end