Skip to content

Commit

Permalink
Array#new_range fills unassigned slots with nil. Fixes #3634.
Browse files Browse the repository at this point in the history
This method needs to be replaced with a Mirror method so it is not polluting
the Array namespace.
  • Loading branch information
brixen committed Apr 5, 2016
1 parent 42fb295 commit 40b599c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/ruby/core/array/new_range_spec.rb
@@ -0,0 +1,21 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "Array#new_range" do
it "returns an Array of length specified by the second parameter" do
[].new_range(0, 4).length.should == 4
end

it "returns an Array with a subsequence contained in the original Array" do
[1, 2, 3, 4].new_range(1, 3).should == [2, 3, 4]
end

it "returns an Arary with a partial subsequence when the range exceeds the Array size" do
ary = [1, 2, 3].new_range(1, 4)
ary[0].should == 2
ary[1].should == 3
end

it "initializes elements outside the original Array to nil" do
[1, 2, 3].new_range(1, 4).should == [2, 3, nil, nil]
end
end

0 comments on commit 40b599c

Please sign in to comment.