# requires Ruby 3.1 or newer
now = Time.new(2021, 6, 1)
# *** before: ***
if (Time.new(2021)..Time.new(2022)).cover?(now)
puts "within 2021"
end
# *** in version 3.1: ***
case now
in ^(Time.new(2021)..Time.new(2022)) # ^(...) pins any expression, not just a
#variable
puts "within 2021"
end