mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+2
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user