range.rb: fix Range#hash for endless/beginless ranges

Use self.begin/self.end instead of first/last to compute hash for
ranges. The first/last methods raise RangeError for endless/beginless
ranges, but the internal begin/end accessors return nil safely.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-30 17:43:59 +09:00
parent 8f259fb560
commit dcd4fe9fb0
+2 -1
View File
@@ -74,7 +74,8 @@ class Range
# redefine #hash 15.3.1.3.15
def hash
h = first.hash ^ last.hash
# Use self.begin/self.end instead of first/last to handle endless/beginless ranges
h = self.begin.hash ^ self.end.hash
h += 1 if self.exclude_end?
h
end