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

ActiveRecord select block returns BasicObject #2147

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

jakebrady5
Copy link
Contributor

Motivation

This change matches the block return value to that of the sig on Array#select.

In practice, updating our large Rails app surfaced many violations of this sig that would cause (in my opinion) undesirable code changes in order to satisfy the T::Boolean return type. It does seem quite historically idiomatic for Ruby code to rely on the implicit truthiness/falsiness check, rather than coerce it explicitly.

Implementation

Continuing the original implementation, this is just a change to the return type of the block sig.

Tests

Existing tests are updated to reflect this change and seem to have sufficient coverage.

@jakebrady5 jakebrady5 requested a review from a team as a code owner January 8, 2025 22:35
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this makes a lot of sense.

I would have gone for returning T.untyped instead, but I agree that matching the Array#select sig is a better choice.

@jakebrady5
Copy link
Contributor Author

I was late on the search, but just commenting that another contributor had a similar though differing idea here.

Copy link
Contributor

@dirceu dirceu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@dirceu dirceu merged commit 997a9cf into Shopify:main Jan 9, 2025
18 of 20 checks passed
@jakebrady5 jakebrady5 deleted the select-block-sig branch January 9, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants