Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4417909e57f7
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b887ca9adba2
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Feb 20, 2015

  1. Copy the full SHA
    7e71609 View commit details
  2. Copy the full SHA
    8dd71a7 View commit details
  3. Merge pull request #3324 from ruipserra/fix_array_slice_with_length_a…

    …rgument
    
    Fix array slice with length argument
    jemc committed Feb 20, 2015
    Copy the full SHA
    b887ca9 View commit details
Showing with 14 additions and 1 deletion.
  1. +3 −1 kernel/common/array.rb
  2. +11 −0 spec/ruby/core/array/slice_spec.rb
4 changes: 3 additions & 1 deletion kernel/common/array.rb
Original file line number Diff line number Diff line change
@@ -601,6 +601,7 @@ def delete_range(index, del_length)
# Use a shift start optimization if we're only removing one
# element and the shift started isn't already huge.
if del_length == 1
@tuple.put @start, nil
@start += 1
else
@tuple.copy_from @tuple, reg_start + @start, reg_length, 0
@@ -1580,7 +1581,8 @@ def slice!(start, length=undefined)
end
else
start = Rubinius::Type.coerce_to_collection_index start
length = Rubinius::Type.coerce_to_collection_index length
length = Rubinius::Type.coerce_to_collection_length length
return nil if length < 0

out = self[start, length]

11 changes: 11 additions & 0 deletions spec/ruby/core/array/slice_spec.rb
Original file line number Diff line number Diff line change
@@ -37,6 +37,17 @@
a.should == []
a.slice!(0, 4).should == []
a.should == []

a = [1]
a.slice!(0, 1).should == [1]
a.should == []
a[-1].should == nil
end

it "returns nil if length is negative" do
a = [1, 2, 3]
a.slice!(2, -1).should == nil
a.should == [1, 2, 3]
end

it "properly handles recursive arrays" do