-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Make Array methods return Array instances instead of subclass instances #3690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Array methods return Array instances instead of subclass instances #3690
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in reviewing 😅
Can't this break existing code that depends on this behaviour? |
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.
8551d60
to
9d0d3f8
Compare
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
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. |
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.
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 changes the following methods to return Array instances instead
of subclass instances:
Fixes [Bug #6087]