Add MatchData#deconstruct/deconstruct_keys
The #deconstruct_keys behaviour is inferred from the Struct#deconstruct_keys, in particular:
- Both Symbols and Strings could be passed as the required keys, the type is preserved.
- If the number of the passed keys is greater than the number of the named groups, an empty Hash is returned.
- Collecting the keys stops as soon as an unknown key is encountered; the returned Hash contains all the keys collected so far.
IMO, 1) and 2) are questionable. But since we already do that for Structs, it makes sense to preserve the current behaviors and not introduce a new one. Alternatively, we can re-visit the Struct API (which I proposed once, but it was rejected).
/cc @baweaver
@palkan Sorry for late review. Could you update NEWS.md if possible? Then, I'll merge this.
- Both Symbols and Strings could be passed as the required keys, the type is preserved.
- If the number of the passed keys is greater than the number of the named groups, an empty Hash is returned.
These are not required. In case of Struct, I implemented them this way for performance.
@k-tsj Thanks for the review! Updated.
@palkan Thanks for updating NEWS! I added some review comments, could you check it?