case/in Basics
Structural matching.
Pattern Matching Arrives
Ruby's case/in expression performs structural pattern matching: it tests the shape and content of data, not just equality. It is a powerful upgrade over case/when.
case 42
in Integer
puts 'it is an integer'
endcase/in vs case/when
case/when compares with === (equality-style). case/in deconstructs values and can bind variables. Use in for matching structure.
case 'hello'
in String => s
puts "string of length #{s.length}"
end