Skip to content

Conversation

@jandudulski
Copy link
Contributor

Pattern matching is available in Ruby since 2.7, so the lowest supported version (it was experimental then but nothing changed in usage).

This would allow to enhance event handlers with pattern matching like:

def call(event)
  case event
  in Foo(event_id:, data: {abc: 1})
    handle_foo_for_abc_1(event_id, event)
  in Foo(data: {abc:})
    handle_foo_abc(abc)
  end # raise NoMatchingPatternError when nothing matches
end

Pattern matching is available in Ruby since 2.7, so the lowest supported
version (it was experimental then but nothing changed in usage).

This would allow to enhance event handlers with pattern matching like:

```ruby
def call(event)
  case event
  in Foo(event_id:, data: {abc: 1})
    handle_foo_for_abc_1(event_id, event)
  in Foo(data: {abc:})
    handle_foo_abc(abc)
  end # raise NoMatchingPatternError when nothing matches
end
```
@mostlyobvious
Copy link
Member

@mostlyobvious mostlyobvious merged commit 43dade8 into RailsEventStore:master Nov 9, 2025
54 checks passed
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.

2 participants