In Ruby, whenever we are evaluating if an object lies inside a range, we can use
cover? to ask Ruby to figure it out logically using the lower and upper limit; rather than using
include? which would instantiate each element of the range and then perform the evaluation on each instance of the range.
Compares to performing all these evaluations:
Compares to performing this single evaluation:
cover? has performance advantages on large ranges or on more complex objects; like Date objects.
You can find more information about
include? on the ruby-doc website.