Skip to content

Methods for Pattern Matching#259

Draft
hasumikin wants to merge 2 commits intomrubyc:masterfrom
hasumikin:methods-for-pattern-matching
Draft

Methods for Pattern Matching#259
hasumikin wants to merge 2 commits intomrubyc:masterfrom
hasumikin:methods-for-pattern-matching

Conversation

@hasumikin
Copy link
Member

This pull request adds support for Ruby's pattern matching methods and enhances Array#[] to handle ranges, including beginless and endless ranges, as well as negative indices. It also introduces comprehensive tests for these features, ensuring robust error handling and correct behavior.

Enhancements to Array:

  • Added support for Array#[] with Range, including inclusive/exclusive ranges, beginless/endless ranges, negative indices, and proper handling of edge cases and errors. [1] [2] [3]
  • Implemented the deconstruct method for Array, allowing pattern matching and returning the array itself; raises ArgumentError if called with arguments. [1] [2] [3] [4] [5]

Enhancements to Hash:

  • Implemented the deconstruct_keys method for Hash, always returning the hash itself for pattern matching and raising ArgumentError if called with incorrect argument count. [1] [2] [3] [4] [5]

Testing improvements:

  • Added extensive tests for Array#[] with various range types, Array#deconstruct, and Hash#deconstruct_keys, including error cases and edge conditions. [1] [2]

@hasumikin hasumikin changed the title Methods for pattern matching Methods for Pattern Matching Feb 18, 2026
- Pattern Matching internally uses this feature
- For Pattern Matching support
- They just return `self` with only checking argument count
@hasumikin hasumikin force-pushed the methods-for-pattern-matching branch from 3e27161 to b8eb4e1 Compare February 19, 2026 02:22
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.

1 participant