Array and Hash Patterns
Destructure data.
Array Patterns
An array pattern matches by position and length. Each element pattern is checked against the corresponding element.
case [1, 2, 3]
in [1, 2, 3]
puts 'exact match'
endBinding Array Elements
Use identifiers to capture each position into a variable.
case [10, 20]
in [x, y]
puts(x + y)
endAll lessons in this course
- case/in Basics
- Array and Hash Patterns
- Find Patterns and Guards
- Practical Use Cases