Ruby case equality operator malfunction ===

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 check if a date falls within a date series. I expect the date range pap1..pap2

to span dat

and dat2

. The equality operator case

must count dat

as a range 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 this is not the case. Did I miss something?

+3


source to share


1 answer


This is apparently a known bug in Ruby 2.3.0, fixed at some point in 2.3.1. Here is a bug report Bug report === with dates . Answer: update.



+4


source







All Articles