-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
NodePattern: Add Constants and keyword parameters #35
Conversation
03f81bc
to
eb90348
Compare
PS: Still missing doc for /cc @bbatsov |
adb8211
to
397b3bb
Compare
PR finished, defaults added to |
[source,ruby] | ||
---- | ||
def_node_matcher :interesting_call?, '(send _ %method ...)', | ||
method: Set[:transform_values, :transform_keys, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good idea to accept arrays here as well and just implicitly convert them to sets. Seems to me this will result in nicer end user API, if it's more flexible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't you aware of my machiavelic plan to convert the whole world to Sets? ;-)
I like that currently the API is simple, we use <your object> === <node element>
It would be easy to convert the values to Sets at the level of def_node_matcher
, but it would be a bad idea to do it at the matcher call level, so I'm afraid there would be confusion...
I should add a note in the doc that Array#===
will never work on a AST element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0f05dcb
to
805cf3d
Compare
Changelog entries added, PR ready as far as I'm concerned. |
83c3566
to
2d9ebee
Compare
Rebased. |
2d9ebee
to
09630a1
Compare
09630a1
to
1c7af10
Compare
This PR allows use of constants in a
NodePattern
, and allows keyword parameters (in addition to the existing sequential parameters).Example from the main gem
This would also be faster (doing a single hash lookup instead of 8 comparisons, see #29)
The keyword parameters is for cases where positional parameters wouldn't be as clear, but also because I would like to make it possible to specify some keyword parameters at the definition too (upcoming PR)
For example, if one doesn't care to define a constant, one could write:
This could be overridden when calling the matcher, e.g.