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

? repetition causes matched nodes to be returned as an array #322

Open
Earlopain opened this issue Oct 24, 2024 · 1 comment
Open

? repetition causes matched nodes to be returned as an array #322

Earlopain opened this issue Oct 24, 2024 · 1 comment

Comments

@Earlopain
Copy link
Contributor

https://nodepattern.herokuapp.com/?p=(%0A%20%20def%20%24_method_name%0A%20%20(args)%0A%20%20(or-asgn%20%24(ivasgn%20_%20...)%20...)%3F%0A)&ruby=def%20foo%0A%20%20%40bar%20%7C%7C%3D%20baz%0Aend

grafik

The pattern is reduced from what I'm trying to write. I'd like to use OR {} but because each branch will contain different amount of captures, I write multiple ? matchers after each other. * and + can return 0-n and 1-n matches so it totally makes sense to return an array for these. + on the other hand is ony 0-1 so I'd expect this to be either be the node or nil.

Can't change this now without a major version bump of course and the solution for me is to just call flatten somewhere in the code but I wanted to see what others think. Does my "complaint" make sense?

@marcandre
Copy link
Contributor

Does my "complaint" make sense?

It does.

Can't change this now without a major version bump of course

Well, there's a major version in the works... :-)

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

No branches or pull requests

2 participants