Object#in?(another_object) method is not part of the Ruby standard library. Thanks to Rails, it’s a convenience method added to the
Object class to check if an object is included in another object.
This method returns true if the calling object is found within the argument provided. The argument must be any object that responds to the
#include? method, which is a common method used to determine whether a collection or data structure contains a specific element.
Verifying objects like strings, numbers, and
hash works properly with
Object#in? but if we use
Object#in? to check if a date is present in an open date range, in Ruby 3.1, it never provides a result owing to the infinite loop, on the other hand, in Ruby 3.2, it raises a TypeError.
To check if a date is present in an open date range, we should use the
cover? method instead. The
cover? method will return true if the date is within the range, and
In the upcoming version of Rails, it is possible to check if a date is present in an open date range with
This Pull Request changes
Object#in? behavior to properly handle open date ranges i.e. beginless and endless ranges.
Under the hood
Range#cover? instead of
Range#include to properly handle beginless and
endless date range inclusion checks.