Make Array methods return Array instances instead of subclass instances - #3690
Merged
Merged
Conversation
marcandre
reviewed
Nov 3, 2020
marcandre
left a comment
Member
There was a problem hiding this comment.
Sorry for the delay in reviewing 😅
Member
|
Can't this break existing code that depends on this behaviour? |
Contributor
Author
Yes, though the breakage is probably minimal as subclassing Array is not that common, and most Array methods do not return subclass instances. Note that this behavior change was already approved by matz in bug 6087. |
This changes the following methods to return Array instances instead of subclass instances: * Array#flatten * Array#slice! * Array#slice/#[] * Array#uniq * Array#* Fixes [Bug ruby#6087]
Add assert_equal_instance in array tests for DRYer code.
jeremyevans
force-pushed
the
array-methods-return-array
branch
from
November 3, 2020 20:48
8551d60 to
9d0d3f8
Compare
Contributor
Author
|
@marcandre I rebased this against current master and pushed another commit handling the issues you noted. Assuming it passes CI, I'll squash merge it. |
Contributor
Author
|
macOS failure is a timeout: This appears to be unrelated to this PR, so I'll merge this. If it turns out this commit causes issues, we can revert. |
mtasaka
added a commit
to mtasaka/coderay
that referenced
this pull request
Feb 21, 2021
With ruby 3.0, especially with ruby/ruby#3690 , for subclass of Array, `flatten` method now returns the instance of Array, not of the subclass. To keep the object instance of the subclass, use `flatten!` instead.
junaruga
pushed a commit
to junaruga/coderay
that referenced
this pull request
Mar 1, 2021
With ruby 3.0, especially with ruby/ruby#3690 , for subclass of Array, `flatten` method now returns the instance of Array, not of the subclass. To keep the object instance of the subclass, use `flatten!` instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes the following methods to return Array instances instead
of subclass instances:
Fixes [Bug #6087]