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.
This commit is contained in:
Tanaka Akira 2023-10-13 00:00:58 +09:00
Родитель b2e1ddffa5
Коммит c23b25f75f
1 изменённых файлов: 13 добавлений и 0 удалений

13
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?.
*/