Skip to content
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

Simplify Enumerable#to_a #15432

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Feb 7, 2025

The implementation of #to_a is identical to its yielding variant #to_a(&). We can simply delegate to #to_a(&).
As a bonus, inheriting types which override #to_a(&) with an optimized implementation will implicitly use the same optimization for #to_a as well. This means we can drop Indexable#to_a.

Inheriting types Tuple and Hash already explicitly delegate #to_a to their override implementations of #to_a(&).
We probably want to keep these overrides of #to_a because they augment the documentation.
But we can replace the method bodies with super to make it clear that the behaviour is inherited and the def only provides documentation.

@straight-shoota straight-shoota added this to the 1.16.0 milestone Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants