Class: YARP::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/yarp.rb,
ext/yarp/extension.c

Overview

This represents a source of Ruby code that has been parsed. It is used in conjunction with locations to allow them to resolve line numbers and source ranges.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, offsets) ⇒ Source

Returns a new instance of Source.



10
11
12
13
# File 'lib/yarp.rb', line 10

def initialize(source, offsets)
  @source = source
  @offsets = offsets
end

Instance Attribute Details

#offsetsObject (readonly)

Returns the value of attribute offsets.



8
9
10
# File 'lib/yarp.rb', line 8

def offsets
  @offsets
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/yarp.rb', line 8

def source
  @source
end

Instance Method Details

#column(value) ⇒ Object



23
24
25
# File 'lib/yarp.rb', line 23

def column(value)
  value - offsets[line(value) - 1]
end

#line(value) ⇒ Object



19
20
21
# File 'lib/yarp.rb', line 19

def line(value)
  offsets.bsearch_index { |offset| offset > value } || offsets.length
end

#slice(offset, length) ⇒ Object



15
16
17
# File 'lib/yarp.rb', line 15

def slice(offset, length)
  source.byteslice(offset, length)
end