Class: YARP::Source
- Inherits:
-
Object
- Object
- YARP::Source
- 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
-
#offsets ⇒ Object
readonly
Returns the value of attribute offsets.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #column(value) ⇒ Object
-
#initialize(source, offsets) ⇒ Source
constructor
A new instance of Source.
- #line(value) ⇒ Object
- #slice(offset, length) ⇒ Object
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
#offsets ⇒ Object (readonly)
Returns the value of attribute offsets.
8 9 10 |
# File 'lib/yarp.rb', line 8 def offsets @offsets end |
#source ⇒ Object (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 |