MΓ³dulo 26 Β· Enumerable, Enumerator & Pattern Matching β LecciΓ³n 5 de 6 Β· ~9 min
Pattern Matching with case/in
Not a switch statement β a structural matcher
case/in (Ruby 3.0+) is one of the biggest additions to modern Ruby, and it's nothing like case/when. case/when asks "does this value match?"; case/in asks *"does this data have this shape, and if so, bind these pieces to variables."* It destructures arrays and hashes, checks types, and extracts values β in one construct. It's tailor-made for parsing the webhook payloads from the last lesson.
In an interview, say: "
case/inis structural pattern matching β it matches the shape of data and destructures it in one step, binding parts to locals. It's how I'd parse a variable-shaped API payload instead of a pile of nestedif/digchecks."