From c23b25f75f6180b7428f9650e063b1e50fc161e2 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 13 Oct 2023 00:00:58 +0900 Subject: [PATCH] describe the assumption for Range#overlap?. Range#overlap? assumes that there is no minimum value. This assumption makes +(...-Float::INFINITY).overlap?((...-Float::INFINITY))+ returns true while +(...-Float::INFINITY)+ is empty. --- range.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/range.c b/range.c index 867c96336a..7e72984dc7 100644 --- a/range.c +++ b/range.c @@ -2386,6 +2386,19 @@ empty_region_p(VALUE beg, VALUE end, int excl) * (1..2).overlap?(3..4) # => false * (1...3).overlap?(3..4) # => false * + * This method assumes that there is no minimum value because + * Ruby lacks a standard method for determining minimum values. + * This assumption is invalid. + * For example, there is no value smaller than +-Float::INFINITY+, + * making +(...-Float::INFINITY)+ an empty set. + * Consequently, +(...-Float::INFINITY)+ has no elements in common with itself, + * yet +(...-Float::INFINITY).overlap?((...-Float::INFINITY))+ returns + * true due to this assumption. + * In general, if +r = (...minimum); r.overlap?(r)+ returns +true+, + * where +minimum+ is a value that no value is smaller than. + * Such values include +-Float::INFINITY+, +[]+, +""+, and + * classes without subclasses. + * * Related: Range#cover?. */