collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

Adds support for ruby 3.0 pattern matching #200

Open bonflintstone opened 3 years ago

bonflintstone commented 3 years ago

This is simply done by implementing deconstruct_keys in the context, and will enable one to use interactors like this:

context = MyInteractor.()

case context
in success: true, result: { first:, second: }
  do_stuff(first, second)
in failure: true, error_message:
  log_error(message: error_message)
end

More about pattern matching: https://docs.ruby-lang.org/en/3.0.0/doc/syntax/pattern_matching_rdoc.html

Obligatory gif:

alexcameron89 commented 3 years ago

This seems like a cool use case for Ruby 3 and I love that it's proven backwards compatible in the testing. 👍