Skip to content

Commit de8924e

Browse files
committed
Rename Location#to to Location#join, include checks
1 parent 40fbf61 commit de8924e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/yarp.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def compute_offsets(code)
3737
class Location
3838
# A Source object that is used to determine more information from the given
3939
# offset and length.
40-
private attr_reader :source
40+
protected attr_reader :source
4141

4242
# The byte offset from the beginning of the source where this location
4343
# starts.
@@ -112,8 +112,13 @@ def ==(other)
112112
other.end_offset == end_offset
113113
end
114114

115-
# Returns a new location that is the union of this location and the other.
116-
def to(other)
115+
# Returns a new location that stretches from this location to the given
116+
# other location. Raises an error if this location is not before the other
117+
# location or if they don't share the same source.
118+
def join(other)
119+
raise "Incompatible sources" if source != other.source
120+
raise "Incompatible locations" if start_offset > other.start_offset
121+
117122
Location.new(source, start_offset, other.end_offset - start_offset)
118123
end
119124

0 commit comments

Comments
 (0)