0Pricing
Ruby Academy · Lesson

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'
end

case/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

All lessons in this course

  1. case/in Basics
  2. Array and Hash Patterns
  3. Find Patterns and Guards
  4. Practical Use Cases
← Back to Ruby Academy