From 76512d78fcde99458db211c0f958bd39cb23dd98 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 25 Aug 2023 14:32:32 -0400 Subject: [ruby/yarp] Rename Location#to to Location#join, include checks https://github.com/ruby/yarp/commit/de8924e3ec --- lib/yarp.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3