Actions
Bug #19564
closedRange.cover? fails for Range wrapped in SimpleDelegator
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin22]
Description
test 'built-in cover? method is broken for SimpleDelegator' do
class TimeRangeDelegator < SimpleDelegator
end
t1 = Time.now
t2 = t1+1.day
t3 = t1+1.week
r_long = t1..t3
r_short = t1..t2
assert r_long.cover?(r_short) #passes correctly, assert == true
r_long_delegated = TimeRangeDelegator.new(r_long)
r_short_delegated = TimeRangeDelegator.new(r_short)
assert r_long_delegated.cover?(r_short_delegated) #fails incorrectly, assert == false
end
Updated by jeremyevans0 (Jeremy Evans) over 1 year ago
I'm not sure if this is a bug. There are many other cases where wrapping an object in a delegate changes behavior (e.g. if false
vs. if SimpleDelegator.new(false)
).
If we want to allow this to work, the most likely approach would be adding something like Range#to_range
, and having Range#cover?
try to use to_range
to convert arguments if the arguments respond to to_range
. I'm not sure the benefits of that are worth the costs.
Updated by matz (Yukihiro Matsumoto) over 1 year ago
I have a few ideas to address the issue, but all of them have significant side-effect. I don't think it's worth making cover?
to support Delegators, despite those side effect.
Matz.
Updated by jeremyevans0 (Jeremy Evans) over 1 year ago
- Status changed from Open to Rejected
Actions
Like0
Like0Like0Like0