I have:
require 'date'
pap1 = Date.parse('1968-06-12')
pap2 = Date.parse('1968-12-31')
dat = Date.parse('1968-06-12')
dat2 = dat + 5 # => #<Date: 1968-06-17 ((2440025j,0s,0n),+0s,2299161j)>
In the example below, I want to test if a date falls in a range of dates. I expect the date range pap1..pap2
to cover dat
and dat2
. The case
equality operator should count dat
as within the range of pap1
and pap2
:
case dat
when (pap1..pap2)
puts 'in range'
else
puts 'not in range'
end
# >> not in range
(pap1..pap2).cover?(dat) # => true
(pap1..pap2).include?(dat) # => true
(pap1..pap2) === dat # => false
puts 'works' if (pap1..pap2) === dat # => nil
(pap1..pap2).cover?(dat2) # => true
(pap1..pap2).include?(dat2) # => true
(pap1..pap2) === dat2 # => false
puts 'works' if (pap1..pap2) === dat2 # => nil
But it doesn't. Am I missing something?