Ruby: Use cover? instead of include? for ranges
include?
compares every object of an array, while cover?
checks if an item fits between the end points.
This difference makes it much faster to use cover?
for ranges.
Example:
one_hundert_years_ago = Date.today - 100.years
today = Date.today
t = Time.now
(one_hundert_years_ago..today).include?(Date.tomorrow)
puts Time.now - t
# => 0.029056
t = Time.now
(one_hundert_years_ago..today).cover?(Date.tomorrow)
puts Time.now - t
# => 3.4e-05 (= 0.000034)