Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Workaround for Range#relative_to

This is a workaround until https://bugs.ruby-lang.org/issues/6203
is addressed and we can apply the fix from there. Or this will be
a permanent work around in the unlikely case that the change is
rejected.
  • Loading branch information...
commit 4defae53ca731bf3c82b6ecfa694e93b47f09bcd 1 parent fc235b1
@ferrous26 ferrous26 authored
Showing with 5 additions and 3 deletions.
  1. +2 −0  range.c
  2. +3 −3 spec/macruby/core/range_spec.rb
View
2  range.c
@@ -969,6 +969,8 @@ range_relative_to(VALUE range, SEL sel, VALUE max)
{
long beg, len, m = NUM2LONG(max);
rb_range_beg_len(range, &beg, &len, m, 0);
+ if (beg + len - 1 > m)
+ len -= 1;
return rb_range_new(LONG2NUM(beg), LONG2NUM(beg + len - 1), 0);
}
View
6 spec/macruby/core/range_spec.rb
@@ -11,9 +11,8 @@
it "responds to #relative_to, which returns a new Range object without negative indicies" do
( 0 .. 10).relative_to(11).should == (0..10)
( 1 .. 9 ).relative_to(11).should == (1..9 )
- ##
- # TODO: This spec fails right now, though it is the intended behaviour.
- # ( 0 .. 15).relative_to(11).should == (0..10)
+ ( 0 .. 15).relative_to(11).should == (0..10)
+ ( 0 .. 11).relative_to(11).should == (0..10)
( 0 .. -1 ).relative_to(11).should == (0..10)
( 0 .. -2 ).relative_to(11).should == (0..9 )
@@ -24,6 +23,7 @@
(-10.. -5 ).relative_to(11).should == (1..6 )
( 4 ... 11).relative_to(11).should == (4..10)
+ ( 4 ... 15).relative_to(11).should == (4..10)
( 4 ... 10).relative_to(11).should == (4..9 )
( 4 ...-1 ).relative_to(11).should == (4..9 )
(-11...-1 ).relative_to(11).should == (0..9 )
Please sign in to comment.
Something went wrong with that request. Please try again.