summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-08-25 14:32:32 -0400
committergit <svn-admin@ruby-lang.org>2023-08-25 21:10:17 +0000
commit76512d78fcde99458db211c0f958bd39cb23dd98 (patch)
tree68869c0492cc97f36fc3149c0b815c4efed8b9a4 /lib
parent481388769407b533879e97510dc8160d094356e0 (diff)
[ruby/yarp] Rename Location#to to Location#join, include checks
https://github.com/ruby/yarp/commit/de8924e3ec
Diffstat (limited to 'lib')
-rw-r--r--lib/yarp.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/yarp.rb b/lib/yarp.rb
index 4c3cf268ce..d44f80b9a0 100644
--- a/lib/yarp.rb
+++ b/lib/yarp.rb
@@ -37,7 +37,7 @@ module YARP
class Location
# A Source object that is used to determine more information from the given
# offset and length.
- private attr_reader :source
+ protected attr_reader :source
# The byte offset from the beginning of the source where this location
# starts.
@@ -112,8 +112,13 @@ module YARP
other.end_offset == end_offset
end
- # Returns a new location that is the union of this location and the other.
- def to(other)
+ # Returns a new location that stretches from this location to the given
+ # other location. Raises an error if this location is not before the other
+ # location or if they don't share the same source.
+ def join(other)
+ raise "Incompatible sources" if source != other.source
+ raise "Incompatible locations" if start_offset > other.start_offset
+
Location.new(source, start_offset, other.end_offset - start_offset)
end