Currently, the min and max range values are checked with range.first and range.max, that will fail with cannot get the first element of beginless range (RangeError) and cannot get the maximum of endless range (RangeError) respectively for beginless/endless ranges.
Proposed solution
We can rely on range.begin and range.end (by correctly checking if end should be considered by looking at exclude_end?) instead, that will both return nil instead of raising for beginless/endless ranges.
Also added the required early returns on minimum/maximum value checks when the begin/end of range is absent and updated the specs with two scenarios for beginless/endless ranges.
Problem
Currently, the min and max range values are checked with
range.first
andrange.max
, that will fail withcannot get the first element of beginless range (RangeError)
andcannot get the maximum of endless range (RangeError)
respectively for beginless/endless ranges.Proposed solution
We can rely on
range.begin
andrange.end
(by correctly checking ifend
should be considered by looking atexclude_end?
) instead, that will both returnnil
instead of raising for beginless/endless ranges.Also added the required early returns on minimum/maximum value checks when the begin/end of range is absent and updated the specs with two scenarios for beginless/endless ranges.
Fixes #1614.