1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Make Array methods return Array instances instead of subclass instances

This changes the following methods to return Array instances instead
of subclass instances:

* Array#drop
* Array#drop_while
* Array#flatten
* Array#slice!
* Array#slice/#[]
* Array#take
* Array#take_while
* Array#uniq
* Array#*

Fixes [Bug #6087]
This commit is contained in:
Jeremy Evans 2020-11-03 14:01:38 -08:00 committed by GitHub
parent 7d6c72dc06
commit 2a294d499b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-11-04 07:02:06 +09:00
Merged: https://github.com/ruby/ruby/pull/3690

Merged-By: jeremyevans <code@jeremyevans.net>
6 changed files with 171 additions and 95 deletions

View file

@ -128,8 +128,16 @@ describe "Array#uniq" do
[false, nil, 42].uniq { :bar }.should == [false]
end
it "returns subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(ArraySpecs::MyArray)
ruby_version_is ''...'3.0' do
it "returns subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(ArraySpecs::MyArray)
end
end
ruby_version_is '3.0' do
it "returns Array instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(Array)
end
end
it "properly handles an identical item even when its #eql? isn't reflexive" do