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

[Ruby 3.0] Add support for find pattern #4364

Merged
merged 2 commits into from Jul 28, 2021

Conversation

vinistock
Copy link
Collaborator

Changes from whitequark

This PR adds support for the find pattern, which is another variation of the pattern matching syntax.

The syntax works as follows: it allows finding specific matches inside structures and (optionally) assigning it to a variable. For example,

foo = [1, 2, 3, 4, 5]

case foo; in [*x, 3 => a, *y] then true; end # foo has the element 3 inside, therefore this will return true and set a = 3

case foo; in [*x, 7 => a, *y] then true; end # foo does not have the element 7, therefore this will raise NoMatchingPatternError

Motivation

Part of the effort to support Ruby 3.0.

Test plan

See included automated tests.

Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com>
@vinistock vinistock requested a review from a team as a code owner July 14, 2021 21:01
@vinistock vinistock requested review from jez and removed request for a team July 14, 2021 21:01
@jez
Copy link
Collaborator

jez commented Jul 28, 2021

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_JwEGm4dUTxuhPS
https://go/builds/bui_JwEGsy8spQriOj

Copy link
Collaborator

@jez jez left a comment

Choose a reason for hiding this comment

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

Thanks!

@jez jez merged commit bf94f80 into sorbet:master Jul 28, 2021
@vinistock vinistock deleted the ruby30-pattern-matching branch July 29, 2021 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants