Skip to content

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

@Earlopain

Description

@Earlopain

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions