-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Allow ArgsNode
to iterate over its arguments
#154
Conversation
f01ff10
to
a0b0e45
Compare
Thank you for the great PR. I meant to do something like that for a while too. I'm definitely 👍 for the creation of One thing to keep in mind is As far as the interface goes, I'd prefer to keep |
@marcandre sounds good about |
Exactly. And I'm thinking |
43ed4fb
to
8e74a06
Compare
@marcandre updated to use I'm not really sure I understand what a
I didn't do this for this PR but I'll try to get this working next. |
8e74a06
to
71f123a
Compare
It is to distinguish
Perfect. It's a valid question as to why the format is like this though, I'll ask. |
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.
I like where this is going!
71f123a
to
54fff0b
Compare
@marcandre I wasn't sure if |
54fff0b
to
67fdc91
Compare
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.
Looks pretty much ready to merge.
One last small detail, could we return frozen arrays? We might want to cache this in the future, and there shouldn't be a need to modify this result.
67fdc91
to
d658902
Compare
…estarg`, `blockarg`, `forward_arg` and `shadowarg` types. - Add `ArgsNode#argument_list` to return all descendant argument type nodes. - Added Procarg0Node for modernized compatibility with ArgNode. - Expose `ArgsNode#argument_list` on `BlockNode`.
d658902
to
f674159
Compare
Great work, thanks! |
While working on rubocop/rubocop#9071, I needed a way to evaluate block arguments (and get their names) that are inside destructuring, but
BlockNode#arguments
returns themlhs
node instead of the actual arguments. This change addseach_arg
toArgsNode
so that only argument types can be iterated, and created a Node type (ArgNode
) for the 7 arg types, which exposesname
,default_value
, etc. I added some predicates that I think are useful too.I overrode
ArgsNode#to_a
so thatarguments.size
will return the actual number of arguments when they are not all at the same node depth.Finally, this adds
BlockNode#argument_names
which is convenient for me in rubocop/rubocop#9071. It gives a way to collect all the argument names even when there are numbered params (for whichBlockNode#arguments
just returns a bare array).