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

Update hash-pattern to use HashNode and array-pattern to use ArrayNode. #210

Closed
wants to merge 1 commit into from

Conversation

dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Sep 23, 2021

hash-pattern and array-pattern are special case hashes and arrays so should be able to be used like normal.

…rrayNode`.

`hash-pattern` and `array-pattern` are special case hashes and arrays so should be able to be used like normal.
@dvandersluis
Copy link
Member Author

The previous CI failures are all green now!

@marcandre
Copy link
Contributor

hash-pattern and array-pattern are special case hashes and arrays

I am not convinced of that. Can you tell me more why you think so, and what use-cases you have in mind?

I'm not against extracting common methods, but we have to think carefully about this.

Although it looks similar, pattern match means something very different.

E.g.: {x: } means something as a pattern match, it also does not map really well to each_key / each_pair. Moreover, in Ruby 3.1, it will mean something completely different when not a pattern match.

@dvandersluis
Copy link
Member Author

Thanks for reviewing @marcandre!

I had opened this for rubocop/rubocop#10108, but ended up solving it another way. My rationale is that array-pattern and hash-pattern are hashes that just happen to contain match-vars instead of other nodes. Fair point about each_key and each_pair though, and I wasn't thinking about how it could match a hash key without capturing a value from it.

I don't actively need this anymore so if it doesn't make sense feel free to close it, or I'm happy to make changes to make this make more sense.

@marcandre
Copy link
Contributor

Let's close this until we actually need to add functionality to the pattern nodes

@marcandre marcandre closed this Sep 29, 2021
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