README.md in operatic-0.5.0 vs README.md in operatic-0.6.0
- old
+ new
@@ -47,10 +47,21 @@
result.message # => nil
result[:message] # => nil
result.to_h # => {}
```
+An `Operatic::Result` also supports pattern matching in Ruby 2.7+ returning an array of `[success, data]`:
+
+```ruby
+case SayHello.call(name: 'Dave')
+in [true, { message: }]
+ # Result is a success, do something with the `message` variable.
+in [false, _]
+ # Result is a failure, do something else.
+end
+```
+
A Rails controller might use Operatic like this:
```ruby
class HellosController < ApplicationController
def create
@@ -61,9 +72,38 @@
else
render :new
end
end
end
+```
+
+Or a pattern matching alternative:
+
+```ruby
+class HellosController < ApplicationController
+ def create
+ case SayHello.call(name: params[:name])
+ in [true, { message: }]
+ render plain: message
+ in [false, _]
+ render :new
+ end
+ end
+end
+```
+
+## Development
+
+Run the tests with:
+
+```
+bundle exec rspec
+```
+
+Generate Yard documentation with:
+
+```
+bundle exec yardoc
```
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).