Actions
Bug #11113
closedTime ranges cannot be used in case statements in 1.9+ but they could in 1.8.7
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
1.9.2, 1.9.3, 2.0, 2.1, 2.2
Backport:
Description
Given this script:
range = (Time.now - 1000)...(Time.now + 1000)
case Time.now
when range then puts "in range"
else puts "not in range"
end
I'd expect it to print "in range". This worked on 1.8.7:
$ ruby -v time_range_problem.rb
ruby 1.8.7 (2013-12-22 patchlevel 375) [i686-darwin12.5.0]
in range
...but raises an exception in 1.9.2, 1.9.3, 2.0, 2.1 and 2.2:
time_range_problem.rb:4:in `each': can't iterate from Time (TypeError)
from time_range_problem.rb:4:in `include?'
from time_range_problem.rb:4:in `include?'
from time_range_problem.rb:4:in `==='
from time_range_problem.rb:4:in `<main>'
It looks like Range#===
is broken. Given that ===
is a standard ruby protocol, I would not expect a built-in type to raise an error like this. IMO, ===
should either return true or false but should not raise an error. We rely upon ===
in RSpec to do matching and this behavior means that if users pass us a time range, things blow up. See https://github.com/rspec/rspec-mocks/issues/938 for an example.
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0