Skip to content

Commit 3fd6910

Browse files
committed
[DO NOT MERGE] Add 2.7 Range#minmax monkeypatch
Unfortunately, the 2.7 implementation actually contains a bug which causes the underlying C implementation of Range#max to delegate to Enumerable#minmax instead of Enumerable#max, since the optimized Range#minmax C implementation skips the Ruby call to Range#max, and calls straight into the C function range_max, thereby failing to change the execution context, and causing the incorrect super call. Pending a fix in MRI, Range#minmax is monkeypatched with an equivalent fix, allowing the specs to be worked on. Once the fix is merged upstream, this commit can be reverted to remove the monkeypatch, and the specs should continue to pass.
1 parent 42ef8e4 commit 3fd6910

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/range/minmax_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
@y.should_receive(:<=>).with(@y).any_number_of_times.and_return(0)
1212
end
1313

14+
ruby_version_is '2.7' do # TODO: Remove this before merging!
15+
class Range
16+
# This monkey patch roughly matches the implementation of the bug fix in MRI's range.c
17+
def minmax
18+
return super if block_given?
19+
20+
[min, max]
21+
end
22+
end
23+
end
24+
1425
describe 'by enumerating the range' do
1526
before(:each) do
1627
@x.should_receive(:succ).once.and_return(@y)

0 commit comments

Comments
 (0)