From dcd4fe9fb06399b0a874ba8c26881ea95dc651b8 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 30 Dec 2025 17:43:59 +0900 Subject: [PATCH] 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 --- mrblib/range.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mrblib/range.rb b/mrblib/range.rb index 96e2ebf24..b9757affd 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -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